Interface TokenMatcher
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface that replaces using Pattern
for sometimes easier, more understandable and more
flexible pattern matching during lexing
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic TokenMatcher
forChar
(char character) Creates a token matcher for a single characterstatic TokenMatcher
forIString
(String string) Creates a token matcher for a single characterstatic TokenMatcher
forLineComment
(String startsWith) static TokenMatcher
forPattern
(String regex) static TokenMatcher
forPattern
(Pattern pattern) Creates a token matcher for aPattern
static TokenMatcher
Creates a token matcher for a quoted string.static TokenMatcher
forQuotedString
(char quoteChar) Creates a token matcher for a quoted string.static TokenMatcher
forQuotedString
(Set<Character> quoteWith) Creates a token matcher for a string quoted with any of the characters in the given set.static TokenMatcher
Creates a token matcher for a single character
-
Field Details
-
DEFAULT_QUOTES
-
LINE_ENDINGS
-
-
Method Details
-
forChar
Creates a token matcher for a single character
-
forString
Creates a token matcher for a single character
-
forIString
Creates a token matcher for a single character
-
forPattern
-
forPattern
Creates a token matcher for a
Pattern
-
forQuotedString
Creates a token matcher for a quoted string. Strings can be quoted with either single or double quotes and escaping is done by adding a backslash in front of the used quote (aka the mode) character
-
forQuotedString
Creates a token matcher for a quoted string. Strings can be quoted with either single or double quotes and escaping is done by adding a backslash in front of the used quote (aka the mode) character
-
forQuotedString
Creates a token matcher for a string quoted with any of the characters in the given set. The quote characters operate in a 'mode' - that is if one of these characters is seen in the source, that triggers that 'mode' and the quoting is terminated by seeing that character again.
Escaping is always done with a backslash
-
match
- Parameters:
source
- string to match a token fromposition
- place in string where to start matching from- Returns:
- a
Token
that is built fromposition
insource
, ornull
if it doesn't match
-
forLineComment
-
getKeyword
-