Class CommonTreeAdaptor
java.lang.Object
org.antlr.runtime.tree.BaseTreeAdaptor
org.antlr.runtime.tree.CommonTreeAdaptor
- All Implemented Interfaces:
TreeAdaptor
- Direct Known Subclasses:
ANTLRParser.grammar_Adaptor, TreeWizard.TreePatternTreeAdaptor
A TreeAdaptor that works with any Tree implementation. It provides
really just factory methods; all the work is done by BaseTreeAdaptor.
If you would like to have different tokens created than ClassicToken
objects, you need to override this and then set the parser tree adaptor to
use your subclass.
To get your parser to build nodes of a different type, override
create(Token), errorNode(), and to be safe, YourTreeClass.dupNode().
dupNode is called to duplicate nodes during rewrite operations.
-
Field Summary
Fields inherited from class BaseTreeAdaptor
treeToUniqueIDMap, uniqueNodeID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a tree node from Token object; for CommonTree type trees, then the token just becomes the payload.createToken(int tokenType, String text) Tell me how to create a token for use with imaginary token nodes.createToken(Token fromToken) Tell me how to create a token for use with imaginary token nodes.Duplicate a node.Get a child 0..n-1 nodeintHow many children? If 0, then this is a leaf nodeintWhat index is this node in the child list? Range: 0..n-1 If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.Who is the parent node of this node; if null, implies node is root.What is the Token associated with this node? If you are not using CommonTree, then you must override this in your own adaptor.intGet the token start index for this subtree; return -1 if no such indexintGet the token stop index for this subtree; return -1 if no such indexintFor tree parsing, I need to know the token type of a nodevoidreplaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) Replace from start to stop child index of parent with t, which might be a list.voidsetChildIndex(Object t, int index) voidvoidsetTokenBoundaries(Object t, Token startToken, Token stopToken) Track start/stop token for subtree root created for a rule.Methods inherited from class BaseTreeAdaptor
addChild, becomeRoot, becomeRoot, create, create, create, deleteChild, dupTree, dupTree, errorNode, getUniqueID, isNil, nil, rulePostProcessing, setChild, setText, setType
-
Constructor Details
-
CommonTreeAdaptor
public CommonTreeAdaptor()
-
-
Method Details
-
dupNode
-
create
Description copied from interface:TreeAdaptorCreate a tree node from Token object; for CommonTree type trees, then the token just becomes the payload. This is the most common create call. Override if you want another kind of node to be built. -
createToken
Tell me how to create a token for use with imaginary token nodes. For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID). If you care what the token payload objects' type is, you should override this method and any other createToken variant.- Specified by:
createTokenin classBaseTreeAdaptor
-
createToken
Tell me how to create a token for use with imaginary token nodes. For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID). This is a variant of createToken where the new token is derived from an actual real input token. Typically this is for converting '{' tokens to BLOCK etc... You'll see r : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ; If you care what the token payload objects' type is, you should override this method and any other createToken variant.- Specified by:
createTokenin classBaseTreeAdaptor
-
setTokenBoundaries
Track start/stop token for subtree root created for a rule. Only works with Tree nodes. For rules that match nothing, seems like this will yield start=i and stop=i-1 in a nil node. Might be useful info so I'll not force to be i..i. -
getTokenStartIndex
Description copied from interface:TreeAdaptorGet the token start index for this subtree; return -1 if no such index -
getTokenStopIndex
Description copied from interface:TreeAdaptorGet the token stop index for this subtree; return -1 if no such index -
getText
- Specified by:
getTextin interfaceTreeAdaptor- Overrides:
getTextin classBaseTreeAdaptor
-
getType
Description copied from interface:TreeAdaptorFor tree parsing, I need to know the token type of a node- Specified by:
getTypein interfaceTreeAdaptor- Overrides:
getTypein classBaseTreeAdaptor
-
getToken
-
getChild
Description copied from interface:TreeAdaptorGet a child 0..n-1 node- Specified by:
getChildin interfaceTreeAdaptor- Overrides:
getChildin classBaseTreeAdaptor
-
getChildCount
Description copied from interface:TreeAdaptorHow many children? If 0, then this is a leaf node- Specified by:
getChildCountin interfaceTreeAdaptor- Overrides:
getChildCountin classBaseTreeAdaptor
-
getParent
Description copied from interface:TreeAdaptorWho is the parent node of this node; if null, implies node is root. If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality. -
setParent
-
getChildIndex
Description copied from interface:TreeAdaptorWhat index is this node in the child list? Range: 0..n-1 If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality. -
setChildIndex
-
replaceChildren
Description copied from interface:TreeAdaptorReplace from start to stop child index of parent with t, which might be a list. Number of children may be different after this call. If parent is null, don't do anything; must be at root of overall tree. Can't replace whatever points to the parent externally. Do nothing.
-