public class TreeWizard extends Object
Modifier and Type | Class | Description |
---|---|---|
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 |
Modifier and Type | Field | Description |
---|---|---|
protected TreeAdaptor |
adaptor |
|
protected Map<String,Integer> |
tokenNameToTypeMap |
Constructor | Description |
---|---|
TreeWizard(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,
String[] tokenNames) |
|
TreeWizard(TreeAdaptor adaptor,
Map<String,Integer> tokenNameToTypeMap) |
Modifier and Type | Method | Description |
---|---|---|
protected static boolean |
_equals(Object t1,
Object t2,
TreeAdaptor adaptor) |
|
protected void |
_index(Object t,
Map<Integer,List<Object>> m) |
Do the work for index
|
protected boolean |
_parse(Object t1,
TreeWizard.TreePattern tpattern,
Map<String,Object> labels) |
Do the work for parse.
|
protected void |
_visit(Object t,
Object parent,
int childIndex,
int ttype,
TreeWizard.ContextVisitor visitor) |
Do the recursive work for visit
|
Map<String,Integer> |
computeTokenTypes(String[] tokenNames) |
Compute a Map<String, Integer> that is an inverted index of
tokenNames (which maps int token types to names).
|
Object |
create(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(Object t1,
Object t2) |
Compare type, structure, and text of two trees, assuming adaptor in
this instance of a TreeWizard.
|
static boolean |
equals(Object t1,
Object t2,
TreeAdaptor adaptor) |
Compare t1 and t2; return true if token types/text, structure match exactly.
|
List<? extends Object> |
find(Object t,
int ttype) |
Return a List of tree nodes with token type ttype
|
List<? extends Object> |
find(Object t,
String pattern) |
Return a List of subtrees matching pattern.
|
Object |
findFirst(Object t,
int ttype) |
|
Object |
findFirst(Object t,
String pattern) |
|
int |
getTokenType(String tokenName) |
Using the map of token names to token types, return the type.
|
Map<Integer,List<Object>> |
index(Object t) |
Walk the entire tree and make a node name to nodes mapping.
|
boolean |
parse(Object t,
String pattern) |
|
boolean |
parse(Object t,
String pattern,
Map<String,Object> 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(Object t,
int ttype,
TreeWizard.ContextVisitor visitor) |
Visit every ttype node in t, invoking the visitor.
|
void |
visit(Object t,
String pattern,
TreeWizard.ContextVisitor visitor) |
For all subtrees that match the pattern, execute the visit action.
|
protected TreeAdaptor adaptor
public TreeWizard(TreeAdaptor adaptor)
public TreeWizard(TreeAdaptor adaptor, Map<String,Integer> tokenNameToTypeMap)
public TreeWizard(TreeAdaptor adaptor, String[] tokenNames)
public TreeWizard(String[] tokenNames)
public Map<String,Integer> computeTokenTypes(String[] tokenNames)
public int getTokenType(String tokenName)
public Map<Integer,List<Object>> index(Object t)
public List<? extends Object> find(Object t, int ttype)
public List<? extends Object> find(Object t, String pattern)
public void visit(Object t, int ttype, TreeWizard.ContextVisitor visitor)
protected void _visit(Object t, Object parent, int childIndex, int ttype, TreeWizard.ContextVisitor visitor)
public void visit(Object t, String pattern, TreeWizard.ContextVisitor visitor)
public boolean parse(Object t, String pattern, Map<String,Object> labels)
protected boolean _parse(Object t1, TreeWizard.TreePattern tpattern, Map<String,Object> labels)
public Object create(String pattern)
public static boolean equals(Object t1, Object t2, TreeAdaptor adaptor)
public boolean equals(Object t1, Object t2)
protected static boolean _equals(Object t1, Object t2, TreeAdaptor adaptor)
Copyright © 1992–2018 ANTLR. All rights reserved.