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.

@FunctionalInterface public interface TokenMatcher

Functional interface that replaces using Pattern for sometimes easier, more understandable and more flexible pattern matching during lexing

  • Field Details

    • LINE_ENDINGS

      static final String[] LINE_ENDINGS
  • Method Details

    • forChar

      static TokenMatcher forChar(char character)

      Creates a token matcher for a single character

    • forString

      static TokenMatcher forString(String string)

      Creates a token matcher for a single character

    • forIString

      static TokenMatcher forIString(String string)

      Creates a token matcher for a single character

    • forPattern

      static TokenMatcher forPattern(String regex)
    • forPattern

      static TokenMatcher forPattern(Pattern pattern)

      Creates a token matcher for a Pattern

    • match

      Token match(TokenType type, Source source, int position)
      Parameters:
      source - string to match a token from
      position - place in string where to start matching from
      Returns:
      a Token that is built from position in source, or null if it doesn't match
    • forLineComment

      static TokenMatcher forLineComment(String startsWith)
    • getKeyword

      default Optional<String> getKeyword()