Macro
@Js
const class Macro : Obj
Macro provides a way to replace macro expressions within a pattern using a pluggable implementation for the macro resolution. See apply for macro syntax.
Create a macro for the given pattern
The unresolved macro pattern
The pattern text is scanned for keys delimited by {{ and }}
Get a list of all the macro keys in the order they appear in the macro pattern
Str apply(|Str->Str| resolve)
The pattern text is scanned for keys delimited by {{ and }}. The text between the delimiters is the key. The supplied callback is invoked to resolve the key and the macro is replaced with that value in the text. Returns the resulting Str after the macro has been applied. Throws ParseErr if the pattern contains invalid macros.
Macro("{{hello}} {{world}}!").apply { it.upper } => HELLO WORLD!
Macro("{{notTerminated").apply { it.upper } => ParseErr
No lexical restriction is placed on the macro keys. The callback is entirely reponsible for validating keys. For example, all the following are perfectly acceptable keys as far as parsing the macro goes:
{{}}- empty key{{ }}- all white space{{ foo }}- leading and trailing white space
Str[] keys()
Get a list of all the macro keys in the order they appear in the macro pattern. Duplicates are not removed.
Macro("{{hello}} {{world}}! Good-bye {{world}}").keys
=> ["hello", "world", "world"]
new make(Str pattern)
Create a macro for the given pattern.
const Str : pattern
The unresolved macro pattern