net.percederberg.grammatica.parser
Class Token

java.lang.Object
  |
  +--net.percederberg.grammatica.parser.Node
        |
        +--net.percederberg.grammatica.parser.Token

public class Token
extends Node

A token node. This class represents a token (i.e. a set of adjacent characters) in a parse tree. The tokens are created by a tokenizer, that groups characters together into tokens according to a set of token patterns.


Constructor Summary
Token(TokenPattern pattern, java.lang.String image, int line, int col)
          Creates a new token.
 
Method Summary
 int getEndColumn()
          The column number of the last character in the token image.
 int getEndLine()
          The line number of the last character in the token image.
 int getId()
          Returns the token (pattern) id.
 java.lang.String getImage()
          Returns the token image (i.e. the characters).
 int getStartColumn()
          The column number of the first character in the token image.
 int getStartLine()
          The line number of the first character in the token image.
 java.lang.String toShortString()
          Returns a short string representation of this token.
 java.lang.String toString()
          Returns a detailed string representation of this token.
 
Methods inherited from class net.percederberg.grammatica.parser.Node
addValue, addValues, getAllValues, getChildAt, getChildCount, getParent, getValue, getValueCount, printTo, printTo, removeAllValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Token

public Token(TokenPattern pattern,
             java.lang.String image,
             int line,
             int col)
Creates a new token.

Parameters:
pattern - the token pattern
image - the token image (i.e. characters)
line - the line number of the first character
col - the column number of the first character
Method Detail

getId

public int getId()
Returns the token (pattern) id. This value is set as a unique identifier when creating the token pattern to simplify later identification.

Specified by:
getId in class Node
Returns:
the token id

getImage

public java.lang.String getImage()
Returns the token image (i.e. the characters).

Returns:
the token characters

getStartLine

public int getStartLine()
The line number of the first character in the token image.

Overrides:
getStartLine in class Node
Returns:
the line number of the first token character

getStartColumn

public int getStartColumn()
The column number of the first character in the token image.

Overrides:
getStartColumn in class Node
Returns:
the column number of the first token character

getEndLine

public int getEndLine()
The line number of the last character in the token image.

Overrides:
getEndLine in class Node
Returns:
the line number of the last token character

getEndColumn

public int getEndColumn()
The column number of the last character in the token image.

Overrides:
getEndColumn in class Node
Returns:
the column number of the last token character

toString

public java.lang.String toString()
Returns a detailed string representation of this token.

Overrides:
toString in class java.lang.Object
Returns:
a detailed string representation of this token
See Also:
Object.toString()

toShortString

public java.lang.String toShortString()
Returns a short string representation of this token. The string will only contain the token image and possibly the token pattern name.

Returns:
a short string representation of this token