Class Token

java.lang.Object
nz.org.riskscape.dsl.Token

public class Token extends Object

A substring, location in the source text, plus type, that constitutes a Token emitted from the Lexer

  • Field Details

    • UNKNOWN_LOCATION

      public static final Token UNKNOWN_LOCATION
    • type

      public final TokenType type
    • source

      public final String source
    • begin

      public final int begin
    • end

      public final int end
    • value

      public final String value
    • lineno

      public int lineno
  • Constructor Details

  • Method Details

    • eof

      public static Token eof(Lexer.Tokens<?> tokens, String source)
    • token

      public static Token token(TokenType tokenType, String value)

      Handy constructor for testing situations

    • getStartOfLine

      public Token getStartOfLine()
    • getIndents

      public List<Token> getIndents()
      Returns:
      a List of Token objects that are the whitespace tokens that preceede any non-whitespace tokens.
    • countIndents

      public int countIndents()
      Returns:
      The number of whitespace tokens that preceede any non-whitespace tokens.
    • isWhitespace

      public boolean isWhitespace()
      Returns:
      true if this token is of a whitespace token type
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLocation

      public Token.Location getLocation()
    • getPosition

      public String getPosition()
    • rawValue

      public String rawValue()
    • moreIndented

      public boolean moreIndented(Token compareTo)
      Returns:
      true if this token has more indent tokens than the previous one
    • isSourceSingleLine

      public boolean isSourceSingleLine()
      Returns:
      true if the source code's non-whitespace tokens occur on a single line
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getValue

      public String getValue()