Interface LexingMatcher
Used by TokenTypes 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 LexingMatcherforChar(char character) Creates aLexingMatcherthat matches a single characterstatic LexingMatcherforKeyword(String keywordMixedCase) static LexingMatcherforLineComment(String startsWith) static LexingMatcherforPattern(String regex) static LexingMatcherforPattern(Pattern pattern) Creates a token matcher for aPatternstatic LexingMatcherCreates a token matcher for a quoted string.static LexingMatcherforQuotedString(char quoteChar) Creates a token matcher for a quoted string.static LexingMatcherforQuotedString(char[] quoteWith) Creates a token matcher for a string quoted with any of the characters in the given set.static LexingMatcherCreates aLexingMatcherfor the given fixed stringstatic LexingMatcherforWhitespace(String whitespaceChars) Creates aLexingMatcherthat consumes consecutive whitespace characters.static booleanisIdentifierCharacter(char ch, boolean includeNumbers) match(TokenType type, LexingStream stream) Match a token from the stream, returning null if it doesn't match.static LexingMatcherwrap(TokenMatcher oldMatcher)
-
Field Details
-
DEFAULT_QUOTES
static final char[] DEFAULT_QUOTES -
LINE_ENDINGS
-
-
Method Details
-
wrap
- Returns:
- a
LexingMatcherthat wraps aTokenMatcherfor compatibility
-
forChar
Creates a
LexingMatcherthat matches a single character -
forWhitespace
Creates a
LexingMatcherthat consumes consecutive whitespace characters. Created tokens are empty, e.g. they have no value. -
forString
Creates a
LexingMatcherfor 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
LexingMatcherthat 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
-