@brief Abstract baseclass for tree adaptors.
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.
:(
|
createWithPayload(self,
payload)
Create a tree node from Token object; for CommonTree type trees, then
the token just becomes the payload. |
|
|
|
dupNode(self,
treeNode)
Duplicate a single tree node. |
|
|
|
dupTree(self,
tree)
Duplicate tree recursively, using dupNode() for each node |
|
|
|
nil(self)
Return a nil node (an empty but non-null node) that can hold a list
of element as the children. |
|
|
|
errorNode(self,
input,
start,
stop,
exc)
Return a tree node representing an error. |
|
|
|
isNil(self,
tree)
Is tree considered a nil node used to make lists of child nodes? |
|
|
|
addChild(self,
t,
child)
Add a child to the tree t. |
|
|
|
becomeRoot(self,
newRoot,
oldRoot)
If oldRoot is a nil root, just copy or move the children to newRoot. |
|
|
|
rulePostProcessing(self,
root)
Given the root of the subtree created for this rule, post process it
to do any simplifications or whatever you want. |
|
|
|
|
|
createFromToken(self,
tokenType,
fromToken,
text=None)
Create a new node derived from a token, with a new token type and
(optionally) new text. |
|
|
|
createFromType(self,
tokenType,
text)
Create a new node derived from a token, with a new token type. |
|
|
|
getType(self,
t)
For tree parsing, I need to know the token type of a node |
|
|
|
setType(self,
t,
type)
Node constructors can set the type of a node |
|
|
|
|
|
setText(self,
t,
text)
Node constructors can set the text of a node |
|
|
|
getToken(self,
t)
Return the token object from which this node was created. |
|
|
|
setTokenBoundaries(self,
t,
startToken,
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. |
|
|
|
getTokenStartIndex(self,
t)
Get the token start index for this subtree; return -1 if no such
index |
|
|
|
getTokenStopIndex(self,
t)
Get the token stop index for this subtree; return -1 if no such index |
|
|
|
getChild(self,
t,
i)
Get a child 0..n-1 node |
|
|
|
setChild(self,
t,
i,
child)
Set ith child (0..n-1) to t; t must be non-null and non-nil node |
|
|
|
deleteChild(self,
t,
i)
Remove ith child and shift children down from right. |
|
|
|
getChildCount(self,
t)
How many children? If 0, then this is a leaf node |
|
|
|
getParent(self,
t)
Who is the parent node of this node; if null, implies node is root. |
|
|
|
setParent(self,
t,
parent)
Who is the parent node of this node; if null, implies node is root. |
|
|
|
getChildIndex(self,
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. |
|
|
|
setChildIndex(self,
t,
index)
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. |
|
|
|
replaceChildren(self,
parent,
startChildIndex,
stopChildIndex,
t)
Replace from start to stop child index of parent with t, which might
be a list. |
|
|
|
create(self,
*args)
Deprecated, use createWithPayload, createFromToken or createFromType. |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__init__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|