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

    • DEFAULT_QUOTES

      static final Set<Character> DEFAULT_QUOTES
    • 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

    • forQuotedString

      static TokenMatcher 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 TokenMatcher 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 TokenMatcher forQuotedString(Set<Character> 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 source, that triggers that 'mode' and the quoting is terminated by seeing that character again.

      Escaping is always done with a backslash

    • match

      Token match(TokenType type, String 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()