TLX Syntax
The following sections provide a brief review of the TLX syntax.
This section contains the following topics
Literals
Literal text is enclosed in double quotation marks. This includes literals intended for the final expanded output and literals used as parameters to macros. For example,
"This is a text literal", Property("Name").
The valid characters for a literal include the printing characters (those higher than 32 decimal). Escape sequences are used for some characters. The escape sequences that are currently supported are as follows:
\n
Carriage return
\t
Horizontal tab character
\\
Back slash
\"
Double quote
One advantage to explicitly-delimited literals is that the formatting of the source and the output can vary. Source text can be formatted exactly as needed because the output text is formatted based upon tabs, spaces, and carriage returns embedded in literals.
Macros
Any text not enclosed in double quote marks, and that does not start with an at sign, is a macro name. For example,
MyMacro
If parameters are being passed to a macro, they will follow the macro name enclosed in parentheses. If more than one parameter is supplied, they are separated by commas. All parameters are string values.
MyMacro("Parameter1", "Parameter2")
There are two general classes of macros: substitution and iteration macros.
Substitution Macros
Substitution macros evaluate to a string value. A substitution macro takes the form described in the previous section: a macro name and possibly a parameter list. For example,
Property("Name").
The resulting string may be an empty value if the actual operations performed by the macro are the purpose of the macro. For example, a macro that writes data out to a file might evaluate to an empty string.
Iteration Macros
Iteration macros (usually) loop through objects in the model. Iteration macros do not evaluate to string values themselves.
An iteration macro may or may not have parameters, just like a substitution macro, but they are followed by curly braces denoting an iteration block.
ForEachOwnee("Attribute") { Property("Name") }
The source text inside the iteration block is evaluated once for each time that the iterator increments.
Some iterator macros do not actually traverse objects. For example, they might traverse values on the object. Generally, this type of iterator macro will have special accessor macros that allow these values to be retrieved.
The form of this type of iterator macro is identical. For example:
ForEachProperty { ForEachProperty.Value }
Macro Return Codes
When a macro is evaluated, it returns a success code to the TLX template processor. If the macro succeeds, it returns 'true'; if it fails, it returns 'false'.
For a substitution macro, the return code and the string value it evaluates into are not the same thing the macro may evaluate to an empty string and return 'true' to indicate a successful evaluation.
Iterator macros are invoked once before the iteration begins, and then once on each iteration. If the initial invocation fails, no iterations are performed. The looping continues until the macro returns 'false' from a request to increment.
Keywords
Unquoted text that starts with an at sign indicates a keyword. Currently, TLX supports four keywords for conditional control: @if, @ifnot, @elseif and @else. These are not case-sensitive.
These conditional keywords are followed by a block enclosed with curly braces, much like an iteration macro. The code within the block is evaluated only if the condition is true.
@if ( Equal( Property("Name"), "Delaware" ) ) { "The first state." } @elseif( Equal( Property("Name"), "Hawaii" ) ) { "The last state." } @else { "A state somewhere in the middle." }
Conditional Blocks
The @if/@elseif keywords provide conditional evaluation. An alternate mechanism for conditional behavior is the conditional block. Source text enclosed in square brackets is in a conditional block. A conditional block is emitted only if all macros within it succeed. The block stops evaluating when it encounters a failure.
The choice of whether to use conditional blocks or @if/@elseif statements is up to the user conditional blocks can provide a format that is easier to read than an embedded @if block in some situations. For example:
"CREATE TABLE " [Property("DB Owner" "."] Property("Physical Name")
Conditional blocks have no effect on enclosing blocks.
Propagating Blocks
Source text enclosed in angle brackets is in a propagating block. Propagating blocks essentially have a return code just like a macro does. They succeed if the text within them after evaluation is not empty; they fail otherwise.
In the following example, if we can find a first name or last name on the object, text will emit. If we can find neither, nothing will emit because the propagating block will cause a failure in the outer conditional block. If the propagating block was not used, the literal "My name is" would be emitted even if no name was present.
[ "My name is" < [ " " Property("Name")] [ " " Property("Last Name") ] > ]
Comments
Text that is enclosed in C-style comments is ignored by the TLX parser and does not become part of the final output.
/* This is a comment */
Copyright © 2025 Quest Software, Inc. |