Interface LexingMatcher


public 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 Details

    • DEFAULT_QUOTES

      static final char[] DEFAULT_QUOTES
    • LINE_ENDINGS

      static final String[] LINE_ENDINGS
  • Method Details

    • wrap

      static LexingMatcher wrap(TokenMatcher oldMatcher)
      Returns:
      a LexingMatcher that wraps a TokenMatcher for compatibility
    • forChar

      static LexingMatcher forChar(char character)

      Creates a LexingMatcher that matches a single character

    • forWhitespace

      static LexingMatcher forWhitespace(String whitespaceChars)

      Creates a LexingMatcher that consumes consecutive whitespace characters. Created tokens are empty, e.g. they have no value.

    • forString

      static LexingMatcher forString(String string)

      Creates a LexingMatcher for the given fixed string

    • forPattern

      static LexingMatcher forPattern(String regex)
    • forPattern

      static LexingMatcher forPattern(Pattern pattern)

      Creates a token matcher for a Pattern

    • forQuotedString

      static LexingMatcher 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

      static LexingMatcher forQuotedString(char quoteChar)

      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

      static LexingMatcher forQuotedString(char[] quoteWith)

      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

      static LexingMatcher forLineComment(String startsWith)
    • 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

      static LexingMatcher forKeyword(String keywordMixedCase)
      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

      Token match(TokenType type, LexingStream stream)

      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

      default Optional<String> getKeyword()
      Returns:
      a human readable name for the type of thing this matcher matches