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
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.javacc.parser.JavaCCConstants
JavaCCConstants.LexicalState, JavaCCConstants.TokenTypeNested classes/interfaces inherited from interface com.javacc.parser.Node
Node.VisitorNested classes/interfaces inherited from interface freemarker.template.TemplateModel
freemarker.template.TemplateModel.InvalidExpressionModel, freemarker.template.TemplateModel.JavaNull -
Field Summary
Fields inherited from interface com.javacc.parser.JavaCCConstants
BUF_SIZEFields inherited from interface freemarker.template.TemplateModel
INVALID_EXPRESSION, JAVA_NULL, NOTHINGFields inherited from interface freemarker.template.TemplateScalarModel
EMPTY_STRING -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedToken()Token(JavaCCConstants.TokenType type, JavaCCLexer tokenSource, int beginOffset, int endOffset) Token(JavaCCConstants.TokenType type, String image, JavaCCLexer tokenSource) -
Method Summary
Modifier and TypeMethodDescriptionvoidinserts a child Node at a specific index, displacing the nodes after the index by 1.voidappends a child node to this Nodechildren()voidRemove 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 Nodeintfinal NodegetChild(int i) final intfreemarker.template.TemplateSequenceModelintgetImage()final TokengetNext()freemarker.template.TemplateNodeModelfinal TokengetType()Return the TokenType of this Token objectfinal intbooleanbooleanbooleanbooleanstatic TokennewToken(JavaCCConstants.TokenType type, JavaCCLexer tokenSource, int beginOffset, int endOffset) static TokennewToken(JavaCCConstants.TokenType type, String image, JavaCCLexer tokenSource) voidremoveChild(int i) Remove the node at index i.voidsetBeginOffset(int beginOffset) It would be extremely rare that an application programmer would use this method.voidReplace the node at index ivoidsetEndOffset(int endOffset) It would be extremely rare that an application programmer would use this method.voidsetGrammar(Grammar grammar) voidvoidvoidsetTokenSource(JavaCCLexer tokenSource) It should be exceedingly rare that an application programmer needs to use this method.protected voidvoidsetUnparsed(boolean unparsed) Mark whether this Node is unparsed, i.e.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 Details
-
Token
- 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 Details
-
getGrammar
- Specified by:
getGrammarin interfaceNode
-
setGrammar
- Specified by:
setGrammarin interfaceNode
-
getNodeName
- Specified by:
getNodeNamein interfacefreemarker.template.TemplateNodeModel
-
getLeadingComments
-
getNormalizedText
-
setImage
-
isInserted
public boolean isInserted() -
preInsert
-
newToken
-
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
- Specified by:
getTokenSourcein interfaceNode- Returns:
- the JavaCCLexer object that handles location info for the tokens.
-
setTokenSource
It should be exceedingly rare that an application programmer needs to use this method.- Specified by:
setTokenSourcein interfaceNode
-
getType
Return the TokenType of this Token object -
setType
-
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
- Returns:
- the string image of the token.
-
getNext
- Returns:
- the next _cached_ regular (i.e. parsed) token or null
-
getPrevious
- Returns:
- the previous regular (i.e. parsed) token or null
-
nextCachedToken
- Returns:
- the next token of any sort (parsed or unparsed or invalid)
-
previousCachedToken
-
replaceType
-
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
-
toString
-
precedingTokens
- Returns:
- An iterator of the tokens preceding this one.
-
precedingUnparsedTokens
- Returns:
- a list of the unparsed tokens preceding this one in the order they appear in the input
-
followingTokens
- Returns:
- An iterator of the (cached) tokens that follow this one.
-
copyLocationInfo
Copy the location info from a Node- Specified by:
copyLocationInfoin interfaceNode- Parameters:
from- the Node to copy the info from
-
copyLocationInfo
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
- 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
Description copied from interface:NodeReplace the node at index i -
addChild
Description copied from interface:Nodeappends a child node to this Node -
addChild
Description copied from interface:Nodeinserts a child Node at a specific index, displacing the nodes after the index by 1. -
removeChild
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
-
getParent
-
setParent
-
getChildCount
public final int getChildCount()- Specified by:
getChildCountin interfaceNode- Returns:
- the number of child nodes
-
getChild
-
children
-
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
- Specified by:
getNodeTypein interfacefreemarker.template.TemplateNodeModel
-
getNodeNamespace
- Specified by:
getNodeNamespacein interfacefreemarker.template.TemplateNodeModel
-
getAsString
- Specified by:
getAsStringin interfacefreemarker.template.TemplateScalarModel
-