Macros
Macros offer a way of reducing repeated code and cleaning up specifications.
Defining Macros
There are three types of macros: matcher, replacer, and rule macros. They are all specified in the same way:
macro matcher m1 = .;
macro replacer m2 = ();
macro rule = . -> ();Macros are only partially checked on creation, but are fully checked on insertion as if you had written the code in the macro instead.
Using Macros
To insert a macro, add a $ to its name:
rule macros1 = {
$m1 -> $m2;
then
$m3;
}Macros can only be inserted according to their type, matcher and replacer macros in matchers and replacers respectively and rule macros in place of rules, either on their own or within compound rules as shown above.
Limitations
Macros need to be complete elements by themselves. Things like operators, bindings, or annotations cannot be made into macros by themselves because they need to be attached to something to form a complete element.