Macro Generator Language (MGL) Syntax

MGL language is used to create templates (macros) for NewGen generator
MGL template is a text file containing string literals, generator variables, generator constants and generator commands.
Syntax format convention used in this document

Generator commands

Command
Description
Syntax
CALL
"CALL" command is widely used to avoid duplications in template. It actually inserts referencing template at point of execution. Call can be parametrized.
Syntax1
%call<macro>
Syntax2
<call>macro[<,>param1<,>param2<,>...]<endcall>
where
macro - name of macro file
param1 - will replace variable <1> in called template, etc.

Example
Main template
Class T%.name%
<for>y attributes<begin><call>attr.mac<,>  F<,>: <,>;<cr><end>
Generated result
Class TBankAccount
FNumber: string;
FUser: string;
FBalance: float;
DECODE
"DECODE" command generates output code based on comparison of 1st parameter with set of alternative values. Generator compares 1st parameter to each value one by one. If expr is equal to a value, generator returns the corresponding result. If no match is found, generator returns default, or, if default is omitted, returns nothing.
Command syntax has two forms
Syntax1
%decode<value:variant1:result1:variant2:result2:...:variantN:resultN:default result>
Syntax2
<decode>value<,>variant1<=>result1<,>variant2<=>result2<,>...<,>variantN<=>resultN<,>default result<enddecode>

Example
To generate correct string conversion function use the following code (note - generator constant <\> is used for template formating purpose only)
<decode>%.type%<,><\>
string<=>%.name%<,><\>
integer<=>IntToStr(%.name%)<,><\>
float<=>FltToStr(%.name%)<,><\>
/*ERROR - unsupported type  %.type%*/<\>
<enddecode>

GET
"GET" command returns single text tocken from input text delimited by specified separator.
Syntax
<get>text<,>index<,>separator<endget>
returns index token of the text string delimited by separator
Example
?
FOR
"FOR" is the most useful generator command. It is widely used to browse hierarchical structure of class model.
Syntax
<for>variable iterator[@objname]^{boolean_expression}^divider^wrap<begin>body<endfor>
for each element in iterator collection of objname object matching filter expression generates code based on body expression
  • variable - name (or names connected by ".") of variable(s) used to denote current element
  • iterator - name (or names connected by ".") of collection, depends on {objname} object type can be the following
    • packages
    • classes
    • attributes
    • methods
    • parameters
    • associations
    • associations1
    • association.types = associations + type
    • type
    • refattribute
    • parent
  • objname - optional, name of object - owner of collection, by default it is current object
  • boolean expression
  • divider - expression inserted between generated codes of different elements
  • wrap - expression iserted in the middle of the generated code if length of the line exeeds 100 characters
  • body - expression generated for each elemant of collection matching the filter
Example of usage.
To show list of classes in a UML package use the following code
<for>x classes<begin>Class %.name%
<endfor>
IF
Command of conditional generation "IF". Command syntax -
  • <if>boolean_expression<begin>body<endif>
boolean_expression = element<and>|<or>|<not>element ...
element = boolean_element|simple filter
boolean_element = p1 operation p2
p1, p2 - parameters
operation - compare operation, can be "=", "~", "<", ">" (ignore double quote)
simple_filter - can contain the next elements, always starts with "+" or "-"
  • +  ("plus sign") - positive (including) filter
  • -  ("minus" sign) - negative (excluding) filter, "NOT" operator
  • ! - distinct modificator
  • <N, <T, <P - sort by name/type/parent
  • #  - all attributes/methods/associations/parameters, overrides all other filters
  • D - derived attributes
  • S - simple type attributes
  • R - ref key attributes
  • C - attributes of class type
  • K - key
  • E - enumeration attribute
  • M0, M1 - mapped attributes
  • b - boolean
  • 1 - "one" or "zero-one" role cardinality
  • * - "zero-many" or "one-many" or "many" role cardinality
  • a - role aggregates
  • .1 - "one" or "zero-one" opposite role cardinality
  • .* - "zero-many" or "one-many" or "many" opposite role cardinality
  • .a - opposite role aggregates
  • P - include parent attributes/methods/associations
  • V - void parameters
  • X - collection classes
  • I - item roles
  • A - class of aggregated stereotype
  • X - class of collection stereotype (obsolete)
NVAL
"NVAL" command allowes you to use named values. MapTool uses named values to store mapping information.
Syntax
<nval>...<endnval>
name formats used by MapTool (0 means Oracle mapping, 1 means ODBC mapping)
  • m0name and m1name - name of mapped column for name attribute
  • t0name and t1name - type of mapped column for name attribute
  • v0name and v1name - mapping values for name attribute


Generator variables

There are two variable formats - %.xxx% and %y.xxx%. The 1st one returns "xxx" value of current object and the second one returns "xxx" value of the object identified by variable "y".
Variable name
Applicability
%.name%

%.name1% associations
%.uname%
packages and classes
%.version%
packages and classes
%.phase%
packages and classes
%.parent%
classes
%.stereotype%
classes
%.attrCount% classes
%.allAttrCount% classes
%.type% attributes and associations
%.type1% associations
%.iskey% attributes
%.ref%
attributes
%.reftarget%
attributes
%.map0% classes, attributes
%.mapval0% attributes
%.maptype0%
attributes
%.load0%, %.add0%, %.del0%
roles
%.map1%
classes, attributes
%.typecode% attributes and roles
%.return% methods
%.const%
parameters
%.dir%
parameters
%.amap0% associations (not supported yet)
%.index%
can be used only inside of <FOR> body

Generator constants


%ver%
version of generator
%time% time of generation
%\% "Line continuation". At the end of the line removes following "caridge return"; in any other place is ignored.
%cr%
caridge return
%p% % character
%g%
> character
%l% < character
%ct% ^ character
%col% : character