Macro Generator Language
(MGL) Syntax
MGL language is used to create templates for NewGen generator. MGL template is a binary
file compiled from the set of macros. One macro has dedicated name
"main" and is used as a start point of generation.
Macro decomposition.
Actually you can define your template in single macro, but in
most cases it will be huge text block too difficult to navigate
througout containing lot of duplicated text blocks. So it make sence to
apply procedural decomposition and split your big macro definition onto
several small ones. Consider the following example:
<macro>main<begin><for>c classes<begin>class
%.name% {
<for>a
attributes<begin> attribute %.name%:
%decode<%.type%:String:char*:Integer:int:Float:float:%.type%>;
<endfor><endfor>
<for>r.t associations.type<begin>
role %r.name%: %t.name% {
<for>a
attributes<begin> attribute %.name%:
%decode<%.type%:String:char*:Integer:int:Float:float:%.type%>;
<endfor><endfor>
} // end role
} // end class<endfor><endmacro>
will generate something like
class Bank {
attribute Name: char*;
attribute Location: char*;
} // end class
class User {
attribute FirstName: char*;
attribute LastName: char*;
attrubute Age: int;
role myBank: Bank {
attribute Name: char*;
attribute Location: char*;
} // end role
} // end class
The text block shown in bold is repeated twice, so we can move it into
sub macro -
<macro>main<begin><for>c classes<begin>class
%.name% {
%call<attr_list>
<for>r.t
associations.type<begin>
role %r.name%: %t.name% {
%call<attr_list>
} // end role
} // end class<endfor><endmacro>
<macro>attr_list<begin><for>a
attributes<begin> attribute %.name%:
%decode<%.type%:String:char*:Integer:int:Float:float:%.type%>;
<endfor><endfor><endmacro>
Such decomposition can be extended further, i.e sub macro can use
anothe sub macros, etc.
File decomposition
In real situation your macro file can hold definitions of tens macros,
that complicates the navigation and maintenance. To simplify situation
you can split one big file onto several files. But to compile the
template you have explicitly denote all required files by INCLUDE
command. The previouse example can be modified as
[file Main.mac]
%include<attrlist.mac>
<macro>main<begin><for>c classes<begin>class
%.name% {
%call<attr_list>
<for>r.t
associations.type<begin>
role %r.name%: %t.name% {
%call<attr_list>
} // end role
} // end class<endfor><endmacro>
[end file]
[file attrlist.mac]
<macro>attr_list<begin><for>a
attributes<begin> attribute %.name%:
%decode<%.type%:String:char*:Integer:int:Float:float:%.type%>;
<endfor><endfor><endmacro>
[end file]
As result we have two hierarchical structures: one is hierarchy of
macro calls built by <call> and <macro> commands and
another one is hierarhy of files buit by <include> commands. It
is desired but not required that file hierarchy repeats hierarchy of
macro calls (macro file contains <include> commands for each
macro used within it). The alternative approach could be including of
all files into the root macro file.
The next rules apply:
- The order of macro definitions and include commands is not
important.
- The same macro file can be included several time in differeent
places - template compilator will load it's definition only once.
- The location of the "main" macro is not important.
- The comp.exe utility must be provided with the name of the macro
file wich is the root of the file hierarchy.
MGL macro
MGL macro is a block of text containing string literals, generator
variables, generator constants and generator commands.
- Generator commands are "active"
elements of MGL. They are used to contol the
process of generation.
- String literals are inserted into the generated
output as is.
- In place of variables generator
puts their values. Variables represents
properties of class model elements.
- In place of constants generator
puts their values. Constants, unlike variables,
represents special character codes and some information about generator
and generation time.
Syntax convention
Syntax format convention used in this document
- Normal font is used for regular text
- Bold font is used for MGL
keywords, example - <for>
- Bold and
italic font is used for MGL constants and variables, example - %ver%
- Italic font is used to
show other elements of commands syntax, example - param1