class Lexer extends java.lang.Object
A lexical scanner for processing variable syntax in strings.
Modifiers | Name | Description |
---|---|---|
class |
Lexer.InvalidVariableException |
|
class |
Lexer.Literal |
Token representing a literal substring within the source string. |
class |
Lexer.Token |
Base class from which literal and variable tokens are derived. |
class |
Lexer.Variable |
Token representing a variable within the source string. |
Type | Name and description |
---|---|
java.lang.Object |
VAR_DEFAULT |
java.lang.Object |
VAR_END |
java.lang.Object |
VAR_NAME |
java.lang.Object |
VAR_START |
Type Params | Return Type | Name and description |
---|---|---|
|
java.util.List |
tokenize(java.lang.String source) Lexes the given string for valid syntax and returns a List of Literal and Variable tokens. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Lexes the given string for valid syntax and returns a List of Literal and Variable tokens.
def tokens = (new Lexer()).tokenize("a ${foo|with default} string.")
assert tokens.length() == 3
assert tokens[0] instanceof Lexer.Literal
assert tokens[0].value == "a "
assert tokens[1] instanceof Lexer.Variable
assert tokens[1].name == "foo"
assert tokens[1].hasDefault
assert tokens[1].defaultValue == "with default"
assert tokens[2] instanceof Lexer.Literal
assert tokens[2].value == " string."