4. Macros

A macro usage is like a tag but with a set of parameters passed inside parenthesis. Macros support all filters but attributes can’t be used. It is important to note that macros are expanded at the point of their calls. This implementation maximizes speed but uses more memory as the definition is not shared. If the code is large it may be better to use an @@INCLUDE@@ as the code is not expanded.

Syntax:

@_[[FILTER[(parameter)]:]MACRO_NAME([PARAM1][,N=>PARAMN])_@

A macro call can have positional parameters (like PARAM1 above) or named (where the name is a number corresponding to the actual parameter position) parameters (like PARAMN above).

With the following definition:

@@MACRO(SOMETEXT)@@
Some text, first parameter is @_$1_@ and the second is @_$2_@.
@@END_MACRO@@
@@--
@_SOMETEXT(12,@_VAR_@)_@
@_UPPER:SOMETEXT(Ada,GNAT)_@

Using the program:

with Ada.Text_IO;
with Templates_Parser;

procedure Macro is

   use type Templates_Parser.Vector_Tag;

   Translations : Templates_Parser.Translate_Set;

begin
   Templates_Parser.Insert
     (Translations,
      Templates_Parser.Assoc ("VAR", "Templates_Parser"));
   Ada.Text_IO.Put_Line
     (Templates_Parser.Parse ("macro.tmplt", Translations));
end Macro;

We get the following result:

Some text, first parameter is 12 and the second is Templates_Parser.
SOME TEXT, FIRST PARAMETER IS ADA AND THE SECOND IS GNAT.