Build and navigate trees with this object. Must know about the names
of tokens so you have to pass in a map or array of token names (from
which this class can build the map). I.e., Token DECL means nothing
unless the class can translate it to a token type.
In order to create nodes and navigate, this class needs a
TreeAdaptor.
This class can build a token type -> node index for repeated use or
for iterating over the various nodes with a particular type.
This class works in conjunction with the TreeAdaptor rather than
moving all this functionality into the adaptor. An adaptor helps build
and navigate trees using methods. This class helps you do it with string
patterns like "(A B C)". You can create a tree from that
pattern or match subtrees against it.
|
__init__(self,
adaptor=None,
tokenNames=None,
typeMap=None)
x.__init__(...) initializes x; see help(type(x)) for signature |
|
|
|
getTokenType(self,
tokenName)
Using the map of token names to token types, return the type. |
|
|
|
create(self,
pattern)
Create a tree or node from the indicated tree pattern that closely
follows ANTLR tree grammar tree element syntax: |
|
|
|
index(self,
tree)
Walk the entire tree and make a node name to nodes mapping. |
|
|
|
_index(self,
t,
m)
Do the work for index |
|
|
|
find(self,
tree,
what)
Return a list of matching token. |
|
|
|
_findTokenType(self,
t,
ttype)
Return a List of tree nodes with token type ttype |
|
|
|
_findPattern(self,
t,
pattern)
Return a List of subtrees matching pattern. |
|
|
|
visit(self,
tree,
what,
visitor)
Visit every node in tree matching what, invoking the visitor. |
|
|
|
_visitType(self,
t,
parent,
childIndex,
ttype,
visitor)
Do the recursive work for visit |
|
|
|
_visitPattern(self,
tree,
pattern,
visitor)
For all subtrees that match the pattern, execute the visit action. |
|
|
|
parse(self,
t,
pattern,
labels=None)
Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on
the various nodes and '.' (dot) as the node/subtree wildcard, return
true if the pattern matches and fill the labels Map with the labels
pointing at the appropriate nodes. |
|
|
|
_parse(self,
t1,
tpattern,
labels)
Do the work for parse. |
|
|
|
equals(self,
t1,
t2,
adaptor=None)
Compare t1 and t2; return true if token types/text, structure match
exactly. |
|
|
|
_equals(self,
t1,
t2,
adaptor) |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|