Interface LexingMatcher
Used by TokenType
s to build tokens from a LexingStream
. This interface is to replace
TokenMatcher
as it accepts the more useful LexingStream
object instead of a string and a position.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic LexingMatcher
forChar
(char character) Creates aLexingMatcher
that matches a single characterstatic LexingMatcher
forKeyword
(String keywordMixedCase) static LexingMatcher
forLineComment
(String startsWith) static LexingMatcher
forPattern
(String regex) static LexingMatcher
forPattern
(Pattern pattern) Creates a token matcher for aPattern
static LexingMatcher
Creates a token matcher for a quoted string.static LexingMatcher
forQuotedString
(char quoteChar) Creates a token matcher for a quoted string.static LexingMatcher
forQuotedString
(char[] quoteWith) Creates a token matcher for a string quoted with any of the characters in the given set.static LexingMatcher
Creates aLexingMatcher
for the given fixed stringstatic LexingMatcher
forWhitespace
(String whitespaceChars) Creates aLexingMatcher
that consumes consecutive whitespace characters.static boolean
isIdentifierCharacter
(char ch, boolean includeNumbers) match
(TokenType type, LexingStream stream) Match a token from the stream, returning null if it doesn't match.static LexingMatcher
wrap
(TokenMatcher oldMatcher)
-
Field Details
-
DEFAULT_QUOTES
static final char[] DEFAULT_QUOTES -
LINE_ENDINGS
-
-
Method Details
-
wrap
- Returns:
- a
LexingMatcher
that wraps aTokenMatcher
for compatibility
-
forChar
Creates a
LexingMatcher
that matches a single character -
forWhitespace
Creates a
LexingMatcher
that consumes consecutive whitespace characters. Created tokens are empty, e.g. they have no value. -
forString
Creates a
LexingMatcher
for the given fixed string -
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 stream, that triggers that 'mode' and the quoting is terminated by seeing that character again.
Escaping is always done with a backslash
-
forLineComment
-
isIdentifierCharacter
static boolean isIdentifierCharacter(char ch, boolean includeNumbers) - Parameters:
includeNumbers
- whether to consider 0-9 an identifier character.- Returns:
- true if the given character is something you'd find in an identifier.
-
forKeyword
- Returns:
- a
LexingMatcher
that matches the given keyword (in any case). More complex than matching a string, as it checks that the keyword isn't followed by any further alphabetic characters
-
match
Match a token from the stream, returning null if it doesn't match. Implementations are free to advance the stream and do not need to worry about resetting it.
-
getKeyword
- Returns:
- a human readable name for the type of thing this matcher matches
-