|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TreeAdaptor
How to create and navigate trees. Rather than have a separate factory and adaptor, I've merged them. Makes sense to encapsulate. This takes the place of the tree construction code generated in the generated code in 2.x and the ASTFactory. I do not need to know the type of a tree at all so they are all generic Objects. This may increase the amount of typecasting needed. :(
Method Summary | |
---|---|
void |
addChild(java.lang.Object t,
java.lang.Object child)
Add a child to the tree t. |
java.lang.Object |
becomeRoot(java.lang.Object newRoot,
java.lang.Object oldRoot)
If oldRoot is a nil root, just copy or move the children to newRoot. |
java.lang.Object |
becomeRoot(Token newRoot,
java.lang.Object oldRoot)
Create a node for newRoot make it the root of oldRoot. |
java.lang.Object |
create(int tokenType,
java.lang.String text)
Create a new node derived from a token, with a new token type. |
java.lang.Object |
create(int tokenType,
Token fromToken)
Create a new node derived from a token, with a new token type. |
java.lang.Object |
create(int tokenType,
Token fromToken,
java.lang.String text)
Same as create(tokenType,fromToken) except set the text too. |
java.lang.Object |
create(Token payload)
Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload. |
java.lang.Object |
deleteChild(java.lang.Object t,
int i)
Remove ith child and shift children down from right. |
java.lang.Object |
dupNode(java.lang.Object treeNode)
Duplicate a single tree node. |
java.lang.Object |
dupTree(java.lang.Object tree)
Duplicate tree recursively, using dupNode() for each node |
java.lang.Object |
errorNode(TokenStream input,
Token start,
Token stop,
RecognitionException e)
Return a tree node representing an error. |
java.lang.Object |
getChild(java.lang.Object t,
int i)
Get a child 0..n-1 node |
int |
getChildCount(java.lang.Object t)
How many children? If 0, then this is a leaf node |
int |
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)
Return the token object from which this node was created. |
int |
getTokenStartIndex(java.lang.Object t)
Get the token start index for this subtree; return -1 if no such index |
int |
getTokenStopIndex(java.lang.Object t)
Get the token stop index for this subtree; return -1 if no such index |
int |
getType(java.lang.Object t)
For tree parsing, I need to know the token type of a node |
int |
getUniqueID(java.lang.Object node)
For identifying trees. |
boolean |
isNil(java.lang.Object tree)
Is tree considered a nil node used to make lists of child nodes? |
java.lang.Object |
nil()
Return a nil node (an empty but non-null node) that can hold a list of element as the children. |
void |
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. |
java.lang.Object |
rulePostProcessing(java.lang.Object root)
Given the root of the subtree created for this rule, post process it to do any simplifications or whatever you want. |
void |
setChild(java.lang.Object t,
int i,
java.lang.Object child)
Set ith child (0..n-1) to t; t must be non-null and non-nil node |
void |
setChildIndex(java.lang.Object t,
int index)
|
void |
setParent(java.lang.Object t,
java.lang.Object parent)
|
void |
setText(java.lang.Object t,
java.lang.String text)
Node constructors can set the text of a node |
void |
setTokenBoundaries(java.lang.Object t,
Token startToken,
Token stopToken)
Where are the bounds in the input token stream for this node and all children? Each rule that creates AST nodes will call this method right before returning. |
void |
setType(java.lang.Object t,
int type)
Node constructors can set the type of a node |
Method Detail |
---|
java.lang.Object create(Token payload)
java.lang.Object dupNode(java.lang.Object treeNode)
java.lang.Object dupTree(java.lang.Object tree)
java.lang.Object nil()
java.lang.Object errorNode(TokenStream input, Token start, Token stop, RecognitionException e)
boolean isNil(java.lang.Object tree)
void addChild(java.lang.Object t, java.lang.Object child)
java.lang.Object becomeRoot(java.lang.Object newRoot, java.lang.Object oldRoot)
java.lang.Object rulePostProcessing(java.lang.Object root)
int getUniqueID(java.lang.Object node)
java.lang.Object becomeRoot(Token newRoot, java.lang.Object oldRoot)
java.lang.Object create(int tokenType, Token fromToken)
java.lang.Object create(int tokenType, Token fromToken, java.lang.String text)
java.lang.Object create(int tokenType, java.lang.String text)
int getType(java.lang.Object t)
void setType(java.lang.Object t, int type)
java.lang.String getText(java.lang.Object t)
void setText(java.lang.Object t, java.lang.String text)
Token getToken(java.lang.Object t)
void setTokenBoundaries(java.lang.Object t, Token startToken, Token stopToken)
int getTokenStartIndex(java.lang.Object t)
int getTokenStopIndex(java.lang.Object t)
java.lang.Object getChild(java.lang.Object t, int i)
void setChild(java.lang.Object t, int i, java.lang.Object child)
java.lang.Object deleteChild(java.lang.Object t, int i)
int getChildCount(java.lang.Object t)
java.lang.Object getParent(java.lang.Object t)
void setParent(java.lang.Object t, java.lang.Object parent)
int getChildIndex(java.lang.Object t)
void setChildIndex(java.lang.Object t, int index)
void replaceChildren(java.lang.Object parent, int startChildIndex, int stopChildIndex, java.lang.Object t)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |