type
Macro
Macro provides a way to replace macro expressions within a pattern using a pluggable implementation for the macro resolution. See apply
for macro syntax.
constructors
make |
Create a macro for the given pattern. |
---|
fields
pattern |
The unresolved macro pattern |
---|
methods
apply |
The |
---|---|
keys |
Get a list of all the macro keys in the order they appear in the macro |
Slot Details
apply
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
keys
make
new make(Str pattern)
Create a macro for the given pattern.
pattern
const Str pattern
The unresolved macro pattern