Package org.codehaus.groovy.syntax
Class Token
- java.lang.Object
-
- org.codehaus.groovy.syntax.CSTNode
-
- org.codehaus.groovy.syntax.Token
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Reduction
asReduction()
Creates aReduction
from this token.Reduction
asReduction(CSTNode second)
Creates aReduction
from this token, adding the supplied node as the second element.Reduction
asReduction(CSTNode second, CSTNode third)
Creates aReduction
from this token, adding the supplied nodes as the second and third element, respectively.Reduction
asReduction(CSTNode second, CSTNode third, CSTNode fourth)
Creates aReduction
from this token, adding the supplied nodes as the second, third, and fourth element, respectively.Token
dup()
Returns a copy of this Token.CSTNode
get(int index)
Returns the specified element, or null.int
getMeaning()
Returns the meaning of this node.Token
getRoot()
Returns the root of the node.String
getRootText()
Returns the text of the root node.int
getStartColumn()
Returns the starting column of the node.int
getStartLine()
Returns the starting line of the node.String
getText()
Returns the text of the token.int
getType()
Returns the actual type of the node.static Token
newDecimal(String text, int startLine, int startColumn)
Creates a token that represents a decimal number.static Token
newIdentifier(String text, int startLine, int startColumn)
Creates a token that represents an identifier.static Token
newInteger(String text, int startLine, int startColumn)
Creates a token that represents an integer.static Token
newKeyword(String text, int startLine, int startColumn)
Creates a token that represents a keyword.static Token
newPlaceholder(int type)
Creates a token with the specified meaning.static Token
newString(String text, int startLine, int startColumn)
Creates a token that represents a double-quoted string.static Token
newSymbol(int type, int startLine, int startColumn)
Creates a token that represents a symbol, using a library for the text.static Token
newSymbol(String type, int startLine, int startColumn)
Creates a token that represents a symbol, using a library for the type.CSTNode
setMeaning(int meaning)
Sets the meaning for this node (and its root Token).void
setText(String text)
Not advisable, but if you need to adjust the token's text, this will do it.int
size()
Returns the number of elements in the node (including root).-
Methods inherited from class org.codehaus.groovy.syntax.CSTNode
add, addChildrenOf, canMean, children, get, getDescription, getMeaningAs, getRoot, hasChildren, isA, isAllOf, isAnExpression, isEmpty, isOneOf, markAsExpression, set, toString, write, write
-
-
-
-
Constructor Detail
-
Token
public Token(int type, String text, int startLine, int startColumn)
Initializes the Token with the specified information.
-
-
Method Detail
-
dup
public Token dup()
Returns a copy of this Token.
-
getMeaning
public int getMeaning()
Returns the meaning of this node. If the node isEmpty(), returns the type of Token.NULL.- Overrides:
getMeaning
in classCSTNode
-
setMeaning
public CSTNode setMeaning(int meaning)
Sets the meaning for this node (and its root Token). Not valid if the node isEmpty(). Returns this token, for convenience.- Overrides:
setMeaning
in classCSTNode
-
getType
public int getType()
Returns the actual type of the node. If the node isEmpty(), returns the type of Token.NULL.
-
size
public int size()
Returns the number of elements in the node (including root).
-
get
public CSTNode get(int index)
Returns the specified element, or null.
-
getRoot
public Token getRoot()
Returns the root of the node. By convention, all nodes have a Token as the first element (or root), which indicates the type of the node. May return null if the nodeisEmpty()
.
-
getRootText
public String getRootText()
Returns the text of the root node. UsesgetRoot(true)
to get the root, so you will only receive null in return if the root token returns it.- Overrides:
getRootText
in classCSTNode
-
getText
public String getText()
Returns the text of the token. Equivalent togetRootText()
when called directly.
-
setText
public void setText(String text)
Not advisable, but if you need to adjust the token's text, this will do it.
-
getStartLine
public int getStartLine()
Returns the starting line of the node. Returns -1 if not known.- Overrides:
getStartLine
in classCSTNode
-
getStartColumn
public int getStartColumn()
Returns the starting column of the node. Returns -1 if not known.- Overrides:
getStartColumn
in classCSTNode
-
asReduction
public Reduction asReduction()
Creates aReduction
from this token. Returns self if the node is already aReduction
.- Specified by:
asReduction
in classCSTNode
-
asReduction
public Reduction asReduction(CSTNode second)
Creates aReduction
from this token, adding the supplied node as the second element.
-
asReduction
public Reduction asReduction(CSTNode second, CSTNode third)
Creates aReduction
from this token, adding the supplied nodes as the second and third element, respectively.
-
asReduction
public Reduction asReduction(CSTNode second, CSTNode third, CSTNode fourth)
Creates aReduction
from this token, adding the supplied nodes as the second, third, and fourth element, respectively.
-
newKeyword
public static Token newKeyword(String text, int startLine, int startColumn)
Creates a token that represents a keyword. Returns null if the specified text isn't a keyword.
-
newString
public static Token newString(String text, int startLine, int startColumn)
Creates a token that represents a double-quoted string.
-
newIdentifier
public static Token newIdentifier(String text, int startLine, int startColumn)
Creates a token that represents an identifier.
-
newInteger
public static Token newInteger(String text, int startLine, int startColumn)
Creates a token that represents an integer.
-
newDecimal
public static Token newDecimal(String text, int startLine, int startColumn)
Creates a token that represents a decimal number.
-
newSymbol
public static Token newSymbol(int type, int startLine, int startColumn)
Creates a token that represents a symbol, using a library for the text.
-
newSymbol
public static Token newSymbol(String type, int startLine, int startColumn)
Creates a token that represents a symbol, using a library for the type.
-
newPlaceholder
public static Token newPlaceholder(int type)
Creates a token with the specified meaning.
-
-