|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.runtime.tree.TreeWizard
public class TreeWizard
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.
Nested Class Summary | |
---|---|
static interface |
TreeWizard.ContextVisitor
|
static class |
TreeWizard.TreePattern
When using %label:TOKENNAME in a tree for parse(), we must track the label. |
static class |
TreeWizard.TreePatternTreeAdaptor
This adaptor creates TreePattern objects for use during scan() |
static class |
TreeWizard.Visitor
|
static class |
TreeWizard.WildcardTreePattern
|
Field Summary | |
---|---|
protected TreeAdaptor |
adaptor
|
protected java.util.Map |
tokenNameToTypeMap
|
Constructor Summary | |
---|---|
TreeWizard(java.lang.String[] tokenNames)
|
|
TreeWizard(TreeAdaptor adaptor)
During fillBuffer(), we can make a reverse index from a set of token types of interest to the list of indexes into the node stream. |
|
TreeWizard(TreeAdaptor adaptor,
java.util.Map tokenNameToTypeMap)
|
|
TreeWizard(TreeAdaptor adaptor,
java.lang.String[] tokenNames)
|
Method Summary | |
---|---|
protected static boolean |
_equals(java.lang.Object t1,
java.lang.Object t2,
TreeAdaptor adaptor)
|
protected void |
_index(java.lang.Object t,
java.util.Map m)
Do the work for index |
protected boolean |
_parse(java.lang.Object t1,
TreeWizard.TreePattern tpattern,
java.util.Map labels)
Do the work for parse. |
protected void |
_visit(java.lang.Object t,
java.lang.Object parent,
int childIndex,
int ttype,
TreeWizard.ContextVisitor visitor)
Do the recursive work for visit |
java.util.Map |
computeTokenTypes(java.lang.String[] tokenNames)
Compute a Map |
java.lang.Object |
create(java.lang.String pattern)
Create a tree or node from the indicated tree pattern that closely follows ANTLR tree grammar tree element syntax: (root child1 ... |
boolean |
equals(java.lang.Object t1,
java.lang.Object t2)
Compare type, structure, and text of two trees, assuming adaptor in this instance of a TreeWizard. |
static boolean |
equals(java.lang.Object t1,
java.lang.Object t2,
TreeAdaptor adaptor)
Compare t1 and t2; return true if token types/text, structure match exactly. |
java.util.List |
find(java.lang.Object t,
int ttype)
Return a List of tree nodes with token type ttype |
java.util.List |
find(java.lang.Object t,
java.lang.String pattern)
Return a List of subtrees matching pattern. |
java.lang.Object |
findFirst(java.lang.Object t,
int ttype)
|
java.lang.Object |
findFirst(java.lang.Object t,
java.lang.String pattern)
|
int |
getTokenType(java.lang.String tokenName)
Using the map of token names to token types, return the type. |
java.util.Map |
index(java.lang.Object t)
Walk the entire tree and make a node name to nodes mapping. |
boolean |
parse(java.lang.Object t,
java.lang.String pattern)
|
boolean |
parse(java.lang.Object t,
java.lang.String pattern,
java.util.Map labels)
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. |
void |
visit(java.lang.Object t,
int ttype,
TreeWizard.ContextVisitor visitor)
Visit every ttype node in t, invoking the visitor. |
void |
visit(java.lang.Object t,
java.lang.String pattern,
TreeWizard.ContextVisitor visitor)
For all subtrees that match the pattern, execute the visit action. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected TreeAdaptor adaptor
protected java.util.Map tokenNameToTypeMap
Constructor Detail |
---|
public TreeWizard(TreeAdaptor adaptor)
public TreeWizard(TreeAdaptor adaptor, java.util.Map tokenNameToTypeMap)
public TreeWizard(TreeAdaptor adaptor, java.lang.String[] tokenNames)
public TreeWizard(java.lang.String[] tokenNames)
Method Detail |
---|
public java.util.Map computeTokenTypes(java.lang.String[] tokenNames)
public int getTokenType(java.lang.String tokenName)
public java.util.Map index(java.lang.Object t)
protected void _index(java.lang.Object t, java.util.Map m)
public java.util.List find(java.lang.Object t, int ttype)
public java.util.List find(java.lang.Object t, java.lang.String pattern)
public java.lang.Object findFirst(java.lang.Object t, int ttype)
public java.lang.Object findFirst(java.lang.Object t, java.lang.String pattern)
public void visit(java.lang.Object t, int ttype, TreeWizard.ContextVisitor visitor)
protected void _visit(java.lang.Object t, java.lang.Object parent, int childIndex, int ttype, TreeWizard.ContextVisitor visitor)
public void visit(java.lang.Object t, java.lang.String pattern, TreeWizard.ContextVisitor visitor)
public boolean parse(java.lang.Object t, java.lang.String pattern, java.util.Map labels)
public boolean parse(java.lang.Object t, java.lang.String pattern)
protected boolean _parse(java.lang.Object t1, TreeWizard.TreePattern tpattern, java.util.Map labels)
public java.lang.Object create(java.lang.String pattern)
public static boolean equals(java.lang.Object t1, java.lang.Object t2, TreeAdaptor adaptor)
public boolean equals(java.lang.Object t1, java.lang.Object t2)
protected static boolean _equals(java.lang.Object t1, java.lang.Object t2, TreeAdaptor adaptor)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |