Macros

Macros offer a way of reducing repeated code and cleaning up specifications.

Defining Macros

There are three types of macros: matcher, replacer, env and rule macros. They are all specified in the same way:

macro matcher m1 = .;
macro replacer m2 = ();
macro env m3 = # _ or _ #;
macro rule m4 = . -> ();

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 in $m3 or _ . #;
  then
  $m4;
}

Macros can only be inserted according to their type, matcher and replacer macros in matchers and replacers respectively, environment macros in place of environments and rule macros in place of rules.

Environment macros can contain multiple environments and be combined with other environments when used, but inverted (except) environment macros are not available. To invert an environment macro, it must be placed into an except block when used.

Rule macros can be used either on their own or within compound rules as shown above. Currently, rule macros can not be combined with additional environments.

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.