类 CommonTreeAdaptor
- java.lang.Object
-
- org.antlr.runtime.tree.BaseTreeAdaptor
-
- org.antlr.runtime.tree.CommonTreeAdaptor
-
- 所有已实现的接口:
TreeAdaptor
public class CommonTreeAdaptor extends BaseTreeAdaptor
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.
-
-
字段概要
-
从类继承的字段 org.antlr.runtime.tree.BaseTreeAdaptor
treeToUniqueIDMap, uniqueNodeID
-
-
构造器概要
构造器 构造器 说明 CommonTreeAdaptor()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 java.lang.Object
create(Token payload)
Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload.Token
createToken(int tokenType, java.lang.String text)
Tell me how to create a token for use with imaginary token nodes.Token
createToken(Token fromToken)
Tell me how to create a token for use with imaginary token nodes.java.lang.Object
dupNode(java.lang.Object t)
Duplicate a node.java.lang.Object
getChild(java.lang.Object t, int i)
Get a child 0..n-1 nodeint
getChildCount(java.lang.Object t)
How many children? If 0, then this is a leaf nodeint
getChildIndex(java.lang.Object t)
What 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.java.lang.Object
getParent(java.lang.Object t)
Who is the parent node of this node; if null, implies node is root.java.lang.String
getText(java.lang.Object t)
Token
getToken(java.lang.Object t)
What is the Token associated with this node? If you are not using CommonTree, then you must override this in your own adaptor.int
getTokenStartIndex(java.lang.Object t)
Get the token start index for this subtree; return -1 if no such indexint
getTokenStopIndex(java.lang.Object t)
Get the token stop index for this subtree; return -1 if no such indexint
getType(java.lang.Object t)
For tree parsing, I need to know the token type of a nodevoid
replaceChildren(java.lang.Object parent, int startChildIndex, int stopChildIndex, java.lang.Object t)
Replace from start to stop child index of parent with t, which might be a list.void
setChildIndex(java.lang.Object t, int index)
void
setParent(java.lang.Object t, java.lang.Object parent)
void
setTokenBoundaries(java.lang.Object t, Token startToken, Token stopToken)
Track start/stop token for subtree root created for a rule.-
从类继承的方法 org.antlr.runtime.tree.BaseTreeAdaptor
addChild, becomeRoot, becomeRoot, create, create, create, deleteChild, dupTree, dupTree, errorNode, getUniqueID, isNil, nil, rulePostProcessing, setChild, setText, setType
-
-
-
-
方法详细资料
-
dupNode
public java.lang.Object dupNode(java.lang.Object t)
Duplicate a node. This is part of the factory; override if you want another kind of node to be built. I could use reflection to prevent having to override this but reflection is slow.
-
create
public java.lang.Object create(Token payload)
从接口复制的说明:TreeAdaptor
Create 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
public Token createToken(int tokenType, java.lang.String text)
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.- 指定者:
createToken
在类中BaseTreeAdaptor
-
createToken
public Token createToken(Token fromToken)
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.- 指定者:
createToken
在类中BaseTreeAdaptor
-
setTokenBoundaries
public void setTokenBoundaries(java.lang.Object t, Token startToken, Token stopToken)
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
public int getTokenStartIndex(java.lang.Object t)
从接口复制的说明:TreeAdaptor
Get the token start index for this subtree; return -1 if no such index
-
getTokenStopIndex
public int getTokenStopIndex(java.lang.Object t)
从接口复制的说明:TreeAdaptor
Get the token stop index for this subtree; return -1 if no such index
-
getText
public java.lang.String getText(java.lang.Object t)
- 指定者:
getText
在接口中TreeAdaptor
- 覆盖:
getText
在类中BaseTreeAdaptor
-
getType
public int getType(java.lang.Object t)
从接口复制的说明:TreeAdaptor
For tree parsing, I need to know the token type of a node- 指定者:
getType
在接口中TreeAdaptor
- 覆盖:
getType
在类中BaseTreeAdaptor
-
getToken
public Token getToken(java.lang.Object t)
What is the Token associated with this node? If you are not using CommonTree, then you must override this in your own adaptor.
-
getChild
public java.lang.Object getChild(java.lang.Object t, int i)
从接口复制的说明:TreeAdaptor
Get a child 0..n-1 node- 指定者:
getChild
在接口中TreeAdaptor
- 覆盖:
getChild
在类中BaseTreeAdaptor
-
getChildCount
public int getChildCount(java.lang.Object t)
从接口复制的说明:TreeAdaptor
How many children? If 0, then this is a leaf node- 指定者:
getChildCount
在接口中TreeAdaptor
- 覆盖:
getChildCount
在类中BaseTreeAdaptor
-
getParent
public java.lang.Object getParent(java.lang.Object t)
从接口复制的说明:TreeAdaptor
Who 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
public void setParent(java.lang.Object t, java.lang.Object parent)
-
getChildIndex
public int getChildIndex(java.lang.Object t)
从接口复制的说明:TreeAdaptor
What 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
public void setChildIndex(java.lang.Object t, int index)
-
replaceChildren
public void replaceChildren(java.lang.Object parent, int startChildIndex, int stopChildIndex, java.lang.Object t)
从接口复制的说明:TreeAdaptor
Replace 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.
-
-