Dodo doc > Macros and Templates > Advanced Macro
An advanced macro uses the same syntax as a simple macro. The following patterns have special meaning:
Pattern | Matches | Meaning |
---|---|---|
$variable | a dodo expression | declares a variable which gives the value of the matched expression when used |
$Type | a dodo type expression | declares a type which has the value of the matched expression when used |
\.&reference | a variable reference starting with "." | declares a reference to the matched variable |
_identifier | a variable name | declares an enum named after the identifier which value is the matched variable name |
~pattern | a dodo pattern | declares a pattern variable which can be used for pattern matching |
\k'variable' | the specified variable converted to a string and used as pattern | allows back references |
(?'variable' ... ) | pattern inside the brackets | declares a variable capturing the content of the brackets |
(?'block_var' ... ) | a dodo block enclosed in "{" and "}" or ":" and "." | declares "block_var" capturing the content of the block |
(?'list_var' ... ) | a comma-separated list | declares "list_var" capturing the elements of the list |
_ | a dodo expression | the expression is captured when part of a capture group |
(?{}) | dodo instructions | the instructions are captured when part of a capture group |
(?#comment) | no matching | inserts a comment |
; | semicolon or new line | a separator is expected at this location |
Declarations originating from the pattern are valid inside the macro block. If they are part of a named capture group they become attributes of this capture group variable.
Whitespace in the pattern matches any whitespace, for example a newline and a tab can match a blank.
A named capture group with a quantifier such as "*" or "?" gives a list variable. A repeated variable name gives a list variable.
A named capture group containing wilcards "_" or "(?{})" is automatically converted to the captured expression or instruction list when used.
Examples:
wrap /if \( $condition \) $true_choice else $false_choice/ { condition -> true_choice | false_choice } wrap /match \( $expr \) (?'block_match' (~pattern => (?'list_captures' $name) ; (?'caseBody' (?{})) )* )/: # use block_match.pattern[i] and block_match.caseBody[i] .