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:

MGL macro

MGL macro is a block of text containing string literals, generator variables, generator constants and generator commands.

Syntax convention

Syntax format convention used in this document