Chapter 9 Generation Reference Guide (GTL)
The .foreach_part macro iterates on the part of the input template specified as the first argument to the macro. The template specified inside the block is translated for each part of the input.
A part is delimited with a separator pattern. There are two kinds of separator:
.foreach_part '(' <input> [',' <separator-pattern> [',' <head> [, <tail>]]] ')' <simple-template> .next['(' <separator> ')']
This macro creates a new scope wherein the local variable CurrentPart is defined to be the i-th part of the input template at iteration i. The Separator local variable contains the following separator.
This macro is particularly useful when you work with naming conventions.
For more information about naming conventions, see " Defining naming conventions" in the "Managing Models" chapter in the General Features Guide.
The <separator-pattern> is defined in a double quote string " " and behaves as follows:
For example, the following pattern " -_,[A-Z]" specifies that each part can be separated by a space, a dash, an underscore, a comma or a character between A and Z (in capital letter).
By default, the <separator-pattern> is initialized with the pattern (" -_,\t"). If the specified pattern is empty, the pattern is initialized using the default value.
A separator <separator> can be concatenated between each part. <head> and <tail> expressions can be added respectively at the bottom or at the end of the generated expression.
Parameter | Type | Description |
---|---|---|
<input> | Simple template | Input text over which iteration is performed |
<separator-pattern> | Text | Char and word separators |
<head> (optional) | Text | Generated before output, if there is one |
<tail> (optional) | Text | Appended to the output, if there is one |
<separator> (optional) | Text | Generated between non empty evaluations of <complex-template> |
The output is the concatenated evaluations of <simple-template> for each part of the translated template <input>.
Examples:
Convert a name into a class code (Java naming convention). In the following example, the variable %Name% is equal to 'Employee shareholder', and it is converted to 'EmployeeShareholder':
.foreach_part (%Name%, " _-'") %.FU:CurrentPart% .next
Convert a name into a class attribute code (Java naming convention). In the following example, the variable %Name% is equal to 'Employee shareholder', and it is converted to 'employeeShareholder':
.set_value(_First, true, new) .foreach_part(%Name%,"' _-'") .if (%_First%) %.L:CurrentPart% .set_value(_First, false, update) .else %.FU:CurrentPart% .endif .next
Copyright (C) 2005. Sybase Inc. All rights reserved. |