Package com.javacc.parser
Class Token
- java.lang.Object
-
- com.javacc.parser.Token
-
- All Implemented Interfaces:
JavaCCConstants,Node,freemarker.template.TemplateModel,freemarker.template.TemplateNodeModel,freemarker.template.TemplateScalarModel,Comparable<Node>
- Direct Known Subclasses:
ANY_CHAR,Backslash,Comment,Delimiter,HASH,Identifier,InvalidToken,JavaCCKeyWord,KeyWord,Literal,MULTI_LINE_COMMENT_START,Operator,RightArrow,SINGLE_LINE_COMMENT_START,UP_TO_HERE,Whitespace
public class Token extends Object implements JavaCCConstants, Node
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.javacc.parser.JavaCCConstants
JavaCCConstants.LexicalState, JavaCCConstants.TokenType
-
Nested classes/interfaces inherited from interface com.javacc.parser.Node
Node.Visitor
-
-
Field Summary
-
Fields inherited from interface com.javacc.parser.JavaCCConstants
BUF_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedToken()Token(JavaCCConstants.TokenType type, JavaCCLexer tokenSource, int beginOffset, int endOffset)Token(JavaCCConstants.TokenType type, String image, JavaCCLexer tokenSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(int i, Node n)inserts a child Node at a specific index, displacing the nodes after the index by 1.voidaddChild(Node n)appends a child node to this NodeList<Node>children()voidclearChildren()Remove all the child nodesvoidcopyLocationInfo(Node from)Copy the location info from a NodevoidcopyLocationInfo(Node start, Node end)Copy the location info given a start and end NodeIterator<Token>followingTokens()StringgetAsString()intgetBeginOffset()NodegetChild(int i)intgetChildCount()freemarker.template.TemplateSequenceModelgetChildNodes()intgetEndOffset()GrammargetGrammar()StringgetImage()StringgetLeadingComments()StringgetLocation()TokengetNext()StringgetNodeName()StringgetNodeNamespace()StringgetNodeType()StringgetNormalizedText()NodegetParent()freemarker.template.TemplateNodeModelgetParentNode()TokengetPrevious()StringgetSource()JavaCCLexergetTokenSource()JavaCCConstants.TokenTypegetType()Return the TokenType of this Token objectintindexOf(Node n)booleanisInserted()booleanisSkipped()booleanisUnparsed()booleanisVirtual()static TokennewToken(JavaCCConstants.TokenType type, JavaCCLexer tokenSource, int beginOffset, int endOffset)static TokennewToken(JavaCCConstants.TokenType type, String image, JavaCCLexer tokenSource)TokennextCachedToken()Iterator<Token>precedingTokens()List<Token>precedingUnparsedTokens()voidpreInsert(Token prependedToken)TokenpreviousCachedToken()NoderemoveChild(int i)Remove the node at index i.TokenreplaceType(JavaCCConstants.TokenType type)voidsetBeginOffset(int beginOffset)It would be extremely rare that an application programmer would use this method.voidsetChild(int i, Node n)Replace the node at index ivoidsetEndOffset(int endOffset)It would be extremely rare that an application programmer would use this method.voidsetGrammar(Grammar grammar)voidsetImage(String image)voidsetParent(Node parent)voidsetTokenSource(JavaCCLexer tokenSource)It should be exceedingly rare that an application programmer needs to use this method.protected voidsetType(JavaCCConstants.TokenType type)voidsetUnparsed(boolean unparsed)Mark whether this Node is unparsed, i.e.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.javacc.parser.Node
appendChild, children, childrenOfType, close, compareTo, descendants, descendants, descendants, descendants, descendantsOfType, dump, dump, firstAncestorOfType, firstChildOfType, firstChildOfType, firstChildOfType, firstDescendantOfType, firstDescendantOfType, getAllTokens, getBeginColumn, getBeginLine, getEndColumn, getEndLine, getFirstChild, getFirstToken, getInputSource, getLastChild, getLastToken, getRealTokens, getRoot, getTokenType, hasChildNodes, iterator, nextSibling, open, prependChild, previousSibling, removeChild, replace, replaceChild
-
-
-
-
Constructor Detail
-
Token
public Token(JavaCCConstants.TokenType type, String image, JavaCCLexer tokenSource)
- Parameters:
type- the #TokenType of the token being constructedimage- the String content of the tokentokenSource- the object that vended this token.
-
Token
protected Token()
-
Token
public Token(JavaCCConstants.TokenType type, JavaCCLexer tokenSource, int beginOffset, int endOffset)
-
-
Method Detail
-
getGrammar
public Grammar getGrammar()
- Specified by:
getGrammarin interfaceNode
-
setGrammar
public void setGrammar(Grammar grammar)
- Specified by:
setGrammarin interfaceNode
-
getNodeName
public String getNodeName()
- Specified by:
getNodeNamein interfacefreemarker.template.TemplateNodeModel
-
getLeadingComments
public String getLeadingComments()
-
getNormalizedText
public String getNormalizedText()
-
setImage
public void setImage(String image)
-
isInserted
public boolean isInserted()
-
preInsert
public void preInsert(Token prependedToken)
-
newToken
public static Token newToken(JavaCCConstants.TokenType type, String image, JavaCCLexer tokenSource)
-
setBeginOffset
public void setBeginOffset(int beginOffset)
It would be extremely rare that an application programmer would use this method. It needs to be public because it is part of the com.javacc.parser.Node interface.- Specified by:
setBeginOffsetin interfaceNode
-
setEndOffset
public void setEndOffset(int endOffset)
It would be extremely rare that an application programmer would use this method. It needs to be public because it is part of the com.javacc.parser.Node interface.- Specified by:
setEndOffsetin interfaceNode
-
getTokenSource
public JavaCCLexer getTokenSource()
- Specified by:
getTokenSourcein interfaceNode- Returns:
- the JavaCCLexer object that handles location info for the tokens.
-
setTokenSource
public void setTokenSource(JavaCCLexer tokenSource)
It should be exceedingly rare that an application programmer needs to use this method.- Specified by:
setTokenSourcein interfaceNode
-
getType
public JavaCCConstants.TokenType getType()
Return the TokenType of this Token object
-
setType
protected void setType(JavaCCConstants.TokenType type)
-
isVirtual
public boolean isVirtual()
- Returns:
- whether this Token represent actual input or was it inserted somehow?
-
isSkipped
public boolean isSkipped()
- Returns:
- Did we skip this token in parsing?
-
getBeginOffset
public int getBeginOffset()
- Specified by:
getBeginOffsetin interfaceNode- Returns:
- the offset in the input source where the token begins, expressed in code units.
-
getEndOffset
public int getEndOffset()
- Specified by:
getEndOffsetin interfaceNode- Returns:
- the offset in the input source where the token ends, expressed in code units. This is actually the offset where the very next token would begin.
-
getImage
public String getImage()
- Returns:
- the string image of the token.
-
getNext
public final Token getNext()
- Returns:
- the next _cached_ regular (i.e. parsed) token or null
-
getPrevious
public final Token getPrevious()
- Returns:
- the previous regular (i.e. parsed) token or null
-
nextCachedToken
public Token nextCachedToken()
- Returns:
- the next token of any sort (parsed or unparsed or invalid)
-
previousCachedToken
public Token previousCachedToken()
-
replaceType
public Token replaceType(JavaCCConstants.TokenType type)
-
getSource
public String getSource()
- Specified by:
getSourcein interfaceNode- Returns:
- the original source content this Node came from a reference to the #JavaCCLexer that stores the source code and the start/end location info stored in the Node object itself. This method could throw a NullPointerException if #getTokenSource returns null. Also, the return value could be spurious if the content of the source file was changed meanwhile. But this is just the default implementation of an API and it does not address this problem!
-
isUnparsed
public boolean isUnparsed()
- Specified by:
isUnparsedin interfaceNode- Returns:
- whether this Node was created by regular operations of the parsing machinery.
-
setUnparsed
public void setUnparsed(boolean unparsed)
Description copied from interface:NodeMark whether this Node is unparsed, i.e. not the result of normal parsing- Specified by:
setUnparsedin interfaceNode- Parameters:
unparsed- whether to set the Node as unparsed or parsed.
-
clearChildren
public void clearChildren()
Description copied from interface:NodeRemove all the child nodes- Specified by:
clearChildrenin interfaceNode
-
precedingTokens
public Iterator<Token> precedingTokens()
- Returns:
- An iterator of the tokens preceding this one.
-
precedingUnparsedTokens
public List<Token> precedingUnparsedTokens()
- Returns:
- a list of the unparsed tokens preceding this one in the order they appear in the input
-
followingTokens
public Iterator<Token> followingTokens()
- Returns:
- An iterator of the (cached) tokens that follow this one.
-
copyLocationInfo
public void copyLocationInfo(Node from)
Copy the location info from a Node- Specified by:
copyLocationInfoin interfaceNode- Parameters:
from- the Node to copy the info from
-
copyLocationInfo
public void copyLocationInfo(Node start, Node end)
Description copied from interface:NodeCopy the location info given a start and end Node- Specified by:
copyLocationInfoin interfaceNode- Parameters:
start- the start nodeend- the end node
-
newToken
public static Token newToken(JavaCCConstants.TokenType type, JavaCCLexer tokenSource, int beginOffset, int endOffset)
-
getLocation
public String getLocation()
- Specified by:
getLocationin interfaceNode- Returns:
- a String that gives the starting location of this Node. This is a default implementation that could be overridden
-
setChild
public void setChild(int i, Node n)Description copied from interface:NodeReplace the node at index i
-
addChild
public void addChild(Node n)
Description copied from interface:Nodeappends a child node to this Node
-
addChild
public void addChild(int i, Node n)Description copied from interface:Nodeinserts a child Node at a specific index, displacing the nodes after the index by 1.
-
removeChild
public Node removeChild(int i)
Description copied from interface:NodeRemove the node at index i. Any Nodes after i are shifted to the left.- Specified by:
removeChildin interfaceNode- Parameters:
i- the index at which to remove- Returns:
- the removed Node
-
indexOf
public final int indexOf(Node n)
-
getParent
public Node getParent()
-
setParent
public void setParent(Node parent)
-
getChildCount
public final int getChildCount()
- Specified by:
getChildCountin interfaceNode- Returns:
- the number of child nodes
-
getChild
public final Node getChild(int i)
-
getParentNode
public freemarker.template.TemplateNodeModel getParentNode()
- Specified by:
getParentNodein interfacefreemarker.template.TemplateNodeModel
-
getChildNodes
public freemarker.template.TemplateSequenceModel getChildNodes()
- Specified by:
getChildNodesin interfacefreemarker.template.TemplateNodeModel
-
getNodeType
public String getNodeType()
- Specified by:
getNodeTypein interfacefreemarker.template.TemplateNodeModel
-
getNodeNamespace
public String getNodeNamespace()
- Specified by:
getNodeNamespacein interfacefreemarker.template.TemplateNodeModel
-
getAsString
public String getAsString()
- Specified by:
getAsStringin interfacefreemarker.template.TemplateScalarModel
-
-