Class DefaultToken

java.lang.Object
com.maroontress.clione.impl.DefaultToken
All Implemented Interfaces:
Token

public final class DefaultToken extends Object implements Token
The implementation of a preprocessing token.
  • Constructor Details

    • DefaultToken

      public DefaultToken(Collection<SourceChar> chars, TokenType type)
      Creates a new instance.
      Parameters:
      chars - The collection of SourceChar objects that compose this token. It must not contain any character representing EOF.
      type - The token type of this token.
  • Method Details

    • getValue

      public String getValue()
      Returns a new string representing this token.

      The string that this method returns does not have the clue of the token type and does not include the content of the child tokens.

      Specified by:
      getValue in interface Token
      Returns:
      The new string representing this token.
    • getSpan

      public SourceSpan getSpan()
      Returns a new span representing the range of this token in the source file.
      Specified by:
      getSpan in interface Token
      Returns:
      A new span representing the range of this token.
    • getChars

      public List<SourceChar> getChars()
      Returns the characters that compose this token.
      Specified by:
      getChars in interface Token
      Returns:
      The unmodifiable list containing the characters that compose this token.
    • getType

      public TokenType getType()
      Returns the type of this token.
      Specified by:
      getType in interface Token
      Returns:
      The type of this token.
    • getChildren

      public List<Token> getChildren()
      Returns the child tokens.

      This method returns an empty list if this token has no child tokens.

      Specified by:
      getChildren in interface Token
      Returns:
      The unmodifiable list containing the child tokens.
    • withType

      public Token withType(TokenType newType)
      Returns a new token that has the same content of this token but has the specified token type.
      Specified by:
      withType in interface Token
      Parameters:
      newType - The token type of the new token.
      Returns:
      The new token.
    • withChildren

      public Token withChildren(Collection<Token> newChildren)
      Returns a new token that has the same content of this token but has the specified child tokens.
      Specified by:
      withChildren in interface Token
      Parameters:
      newChildren - The child tokens of the new token.
      Returns:
      The new token.
    • toString

      public String toString()
      Returns a new string representation of this token that is easy for a person to read.

      This method returns a string equal to the value of:

              "[value=" + getValue() + ", span=" + getSpan() + ", "
                  + "chars=" + getChars() + ", type=" + getType() + ", "
                  + "children=" + getChildren() + "]";
              
      Specified by:
      toString in interface Token
      Overrides:
      toString in class Object
      Returns:
      The new string representation of this token.