Pre-processor

Below you can find the general command line (CLI) use of the program and the overall syntax. A powershell version will be available shortly, please contact us to get informed as soon as it is available.

The basic idea behind a pre-processor is to get an input containing pre-processor commands and to create an output without them. The commands are evaluated during the creation of the output file. By changing the variables you pass to the pre-processor you can change the created output file.

CLI 

Below you will find the description command line use of the pre-processor

To process a single file:

UniversalPreprocessor input.al output.al VARIABLE1=Value1 VAR2=Value2

To process all files ending with .al in a directory and all sub-directories:

UniversalPreprocessor inputFolder\ outputfolder\ VARIABLE1=Value1 VAR2=Value2

Variables

A variable has to start with a character and might contain numbers and underscores. You can choose any name you want to. There is one variable name that is used by our other tools (TARGETVERSION), but is has no special meaning to the pre-processor.

Data Types

A variable can contain values of the following types:

  • String
    • “Text value” 
  • Number
    • 15.0, 12
  • Boolean
    • true, false

Syntax

All preprocessor commands have to be inside a /* ... */ comment block.

Each command will start with the characters ### and end with the characters ###.

The following command are available:

In the following section we will describe each command in detail. 

IF

The IF command allows you to output a specific block of code only when the provided condition is true.

The basic syntax is:

### IF expression ###
// AL code
### ENDIF ###

You can use the following operators in the expressions:

  • ==
    • Is a equal b: A == B 
  • !=
    • Is a not equal b: A != B
    • Is a greater b: A > B
  • >=
    • Is a greater or equal b: A >= B
  • <
    • Is a smaller b: A < B
  • <=
    • Is a smaller equal b: A <= B
  • &&
    • Is condition a and condition b true: A && B
  • ||
    • Is condition a or condition b true: A || B

The variable has a data type. Some operators will only work with numbers, some with boolean expressions. You can use multiple operators and parentheses to build your expression.

You can use an ELSE clause to specify what should happen, if the condition is not true.

You have to specify ENDIF at the end.

All pre-processor commands have to be contained inside a multiline comment. But you do not have to close the comment right away. By leaving the comment open for a whole block, you can decide which code is visible to the AL compiler in Visual Studio Code, when working directly on the source code.

Example

IFDEF

Check whether a variable is defined.

Example

/* ### IFDEF DEBUG ### */
// Add debug code
/* ### ENDIF ###*/

IFNDEF

Check whether a variable is not defined. You can use this to set, for example, default values.

Example

/* ### IFNDEF TARGETVERSION ###
   ### DEFINE TARGETVERSION=13.0
   ### ENDIF ### */

DEFINE

Defines a variable from inside code. You can use this, for example, to define fallback values.

Example

/* ### IFNDEF TARGETVERSION ###
   ### DEFINE TARGETVERSION=13.0
   ### ENDIF ### */