Interface TokenStream.Token

All Known Implementing Classes:
TokenStream.CaseInsensitiveToken, TokenStream.CaseSensitiveToken
Enclosing class:
TokenStream

@Immutable public static interface TokenStream.Token
The interface defining a token, which references the characters in the actual input character stream.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get the index in the raw stream past the last character in the token.
    int
    Get the length of the token, which is equivalent to endIndex() - startIndex().
    boolean
    matches(char expected)
    Determine if the token matches the supplied character.
    boolean
    matches(int expectedType)
    Determine if the token matches the supplied type.
    default boolean
    matches(int expectedType, String expected)
    Determine if the token matches the supplied string and is of a requested type.
    boolean
    matches(String expected)
    Determine if the token matches the supplied string.
    Get the position of this token, which includes the line number and column number of the first character in the token.
    int
    Get the index in the raw stream for the first character in the token.
    int
    Get the type of the token.
    Get the value of the token, in actual case.
    withType(int typeMask)
    Bitmask ORed with existing type value.
  • Method Details

    • value

      String value()
      Get the value of the token, in actual case.
      Returns:
      the value
    • matches

      boolean matches(String expected)
      Determine if the token matches the supplied string.
      Parameters:
      expected - the expected value
      Returns:
      true if the token's value matches the supplied value, or false otherwise
    • matches

      default boolean matches(int expectedType, String expected)
      Determine if the token matches the supplied string and is of a requested type.
      Parameters:
      expectedType - the expected token type
      expected - the expected value
      Returns:
      true if the token's type and value matches the supplied type and value, or false otherwise
    • matches

      boolean matches(char expected)
      Determine if the token matches the supplied character.
      Parameters:
      expected - the expected character value
      Returns:
      true if the token's value matches the supplied character value, or false otherwise
    • matches

      boolean matches(int expectedType)
      Determine if the token matches the supplied type.
      Parameters:
      expectedType - the expected integer type
      Returns:
      true if the token's value matches the supplied integer type, or false otherwise
    • type

      int type()
      Get the type of the token.
      Returns:
      the token's type
    • startIndex

      int startIndex()
      Get the index in the raw stream for the first character in the token.
      Returns:
      the starting index of the token
    • endIndex

      int endIndex()
      Get the index in the raw stream past the last character in the token.
      Returns:
      the ending index of the token, which is past the last character
    • length

      int length()
      Get the length of the token, which is equivalent to endIndex() - startIndex().
      Returns:
      the length
    • position

      Position position()
      Get the position of this token, which includes the line number and column number of the first character in the token.
      Returns:
      the position; never null
    • withType

      TokenStream.Token withType(int typeMask)
      Bitmask ORed with existing type value.
      Parameters:
      typeMask - the mask of types
      Returns:
      copy of Token with new type