Class Token

java.lang.Object
org.tweetyproject.preferences.io.Token
All Implemented Interfaces:
Serializable

public class Token extends Object implements Serializable
Describes the input token stream.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The column number of the first character of this token.
    int
    The line number of the first character of this token.
    int
    The column number of the last character of this token.
    int
    The line number of the last character of this token.
    The string image of the token.
    int
    An integer that describes the kind of this token.
    A reference to the next regular (non-special) token in the input stream.
    A reference to special tokens that occur before this token but after the immediately preceding regular (non-special) token.
  • Constructor Summary

    Constructors
    Constructor
    Description
    No-argument constructor for Token.
    Token(int kind)
    Constructs a new token for the specified kind.
    Token(int kind, String image)
    Constructs a new token for the specified kind and image.
  • Method Summary

    Modifier and Type
    Method
    Description
    An optional attribute value of the Token.
    static Token
    newToken(int ofKind)
    Returns a new Token object with the specified kind.
    static Token
    newToken(int ofKind, String image)
    Returns a new Token object.
    Returns the string image of the token.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • kind

      public int kind
      An integer that describes the kind of this token. This is typically set by the parser.
    • beginLine

      public int beginLine
      The line number of the first character of this token.
    • beginColumn

      public int beginColumn
      The column number of the first character of this token.
    • endLine

      public int endLine
      The line number of the last character of this token.
    • endColumn

      public int endColumn
      The column number of the last character of this token.
    • image

      public String image
      The string image of the token.
    • next

      public Token next
      A reference to the next regular (non-special) token in the input stream. This field is set to null if this is the last token or if the token manager has not read tokens beyond this one.
    • specialToken

      public Token specialToken
      A reference to special tokens that occur before this token but after the immediately preceding regular (non-special) token. Special tokens are used for syntactic sugar and are not part of the main token stream.
  • Constructor Details

    • Token

      public Token()
      No-argument constructor for Token.
    • Token

      public Token(int kind)
      Constructs a new token for the specified kind.
      Parameters:
      kind - the kind of the token.
    • Token

      public Token(int kind, String image)
      Constructs a new token for the specified kind and image.
      Parameters:
      kind - the kind of the token.
      image - the image of the token.
  • Method Details

    • getValue

      public Object getValue()
      An optional attribute value of the Token. Tokens that are not used as syntactic sugar will often contain meaningful values that will be used later on by the compiler or interpreter. This attribute value is often different from the image.
      Returns:
      the attribute value of the token, or null if not applicable.
    • toString

      public String toString()
      Returns the string image of the token.
      Overrides:
      toString in class Object
      Returns:
      the image of the token.
    • newToken

      public static Token newToken(int ofKind, String image)
      Returns a new Token object. This method can be overridden to create instances of subclasses based on the value of ofKind.

      By default, this method returns a Token instance. Subclasses can be created by adding cases to the switch statement for specific token kinds.

      Parameters:
      ofKind - the kind of token to create.
      image - the image of the token.
      Returns:
      a new Token instance.
    • newToken

      public static Token newToken(int ofKind)
      Returns a new Token object with the specified kind.
      Parameters:
      ofKind - the kind of token to create.
      Returns:
      a new Token instance.