| Modifier and Type | Class and Description |
|---|---|
| public static interface | |
| public static class | TreeWizard.TreePattern
When using %label:TOKENNAME in a tree for parse(), we must track the label. |
| public static class | TreeWizard.TreePatternTreeAdaptor
This adaptor creates TreePattern objects for use during scan() |
| public abstract static class | |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| protected TreeAdaptor | |
| protected Map |
| Access | Constructor and Description |
|---|---|
| public | 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. |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected static boolean | |
| protected void | |
| protected boolean | _parse(Object t1, TreeWizard.
Do the work for parse. |
| protected void | _visit(Object t, Object parent, int childIndex, int ttype, TreeWizard.
Do the recursive work for visit |
| public Map | computeTokenTypes(String[] tokenNames)
Compute a Map<String, Integer> that is an inverted index of tokenNames (which maps int token types to names). |
| public Object | |
| public static boolean | equals(Object t1, Object t2, TreeAdaptor adaptor)
Compare t1 and t2; return true if token types/text, structure match exactly. |
| public boolean | |
| public List | |
| public List | |
| public Object | |
| public Object | |
| public int | |
| public Map | |
| public boolean | |
| public boolean | |
| public void | visit(Object t, int ttype, TreeWizard.
Visit every ttype node in t, invoking the visitor. |
| public void | visit(Object t, final String pattern, final TreeWizard.
For all subtrees that match the pattern, execute the visit action. |
| adaptor | back to summary |
|---|---|
| protected TreeAdaptor adaptor | |
| tokenNameToTypeMap | back to summary |
|---|---|
| protected Map<String, Integer> tokenNameToTypeMap | |
| TreeWizard | back to summary |
|---|---|
| public 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. This lets us convert a node pointer to a stream index semi-efficiently for a list of interesting nodes such as function definition nodes (you'll want to seek to their bodies for an interpreter). Also useful for doing dynamic searches; i.e., go find me all PLUS nodes. protected Map tokenTypeToStreamIndexesMap; /** If tokenTypesToReverseIndex set to INDEX_ALL then indexing occurs for all token types. public static final Set INDEX_ALL = new HashSet(); /** A set of token types user would like to index for faster lookup. If this is INDEX_ALL, then all token types are tracked. If null, then none are indexed. protected Set tokenTypesToReverseIndex = null; | |
| TreeWizard | back to summary |
|---|---|
| public TreeWizard(TreeAdaptor adaptor, Map<String, Integer> tokenNameToTypeMap) | |
| TreeWizard | back to summary |
|---|---|
| public TreeWizard(TreeAdaptor adaptor, String[] tokenNames) | |
| TreeWizard | back to summary |
|---|---|
| public TreeWizard(String[] tokenNames) | |
| _equals | back to summary |
|---|---|
| protected static boolean _equals(Object t1, Object t2, TreeAdaptor adaptor) | |
| _index | back to summary |
|---|---|
| protected void _index(Object t, Map<Integer, List<Object>> m) Do the work for index | |
| _parse | back to summary |
|---|---|
| protected boolean _parse(Object t1, TreeWizard. Do the work for parse. Check to see if the t2 pattern fits the structure and token types in t1. Check text if the pattern has text arguments on nodes. Fill labels map with pointers to nodes in tree matched against nodes in pattern with labels. | |
| _visit | back to summary |
|---|---|
| protected void _visit(Object t, Object parent, int childIndex, int ttype, TreeWizard. Do the recursive work for visit | |
| computeTokenTypes | back to summary |
|---|---|
| public Map Compute a Map<String, Integer> that is an inverted index of tokenNames (which maps int token types to names). | |
| create | back to summary |
|---|---|
| public 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 ... child2). You can also just pass in a node: ID Any node can have a text argument: ID[foo] (notice there are no quotes around foo--it's clear it's a string). nil is a special name meaning "give me a nil node". Useful for making lists: (nil A B C) is a list of A B C. | |
| equals | back to summary |
|---|---|
| public static boolean equals(Object t1, Object t2, TreeAdaptor adaptor) Compare t1 and t2; return true if token types/text, structure match exactly. The trees are examined in their entirety so that (A B) does not match (A B C) nor (A (B C)). // TODO: allow them to pass in a comparator TODO: have a version that is nonstatic so it can use instance adaptor I cannot rely on the tree node's equals() implementation as I make no constraints at all on the node types nor interface etc... | |
| equals | back to summary |
|---|---|
| public boolean equals(Object t1, Object t2) Compare type, structure, and text of two trees, assuming adaptor in this instance of a TreeWizard. | |
| find | back to summary |
|---|---|
| public List Return a List of tree nodes with token type ttype | |
| find | back to summary |
|---|---|
| public List Return a List of subtrees matching pattern. | |
| findFirst | back to summary |
|---|---|
| public Object findFirst(Object t, int ttype) | |
| findFirst | back to summary |
|---|---|
| public Object findFirst(Object t, String pattern) | |
| getTokenType | back to summary |
|---|---|
| public int getTokenType(String tokenName) Using the map of token names to token types, return the type. | |
| index | back to summary |
|---|---|
| public Map Walk the entire tree and make a node name to nodes mapping. For now, use recursion but later nonrecursive version may be more efficient. Returns Map<Integer, List> where the List is of your AST node type. The Integer is the token type of the node. TODO: save this index so that find and visit are faster | |
| parse | back to summary |
|---|---|
| public 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. Return false if the pattern is malformed or the tree does not match. If a node specifies a text arg in pattern, then that must match for that node in t. TODO: what's a better way to indicate bad pattern? Exceptions are a hassle | |
| parse | back to summary |
|---|---|
| public boolean parse(Object t, String pattern) | |
| visit | back to summary |
|---|---|
| public void visit(Object t, int ttype, TreeWizard. Visit every ttype node in t, invoking the visitor. This is a quicker version of the general visit(t, pattern) method. The labels arg of the visitor action method is never set (it's null) since using a token type rather than a pattern doesn't let us set a label. | |
| visit | back to summary |
|---|---|
| public void visit(Object t, final String pattern, final TreeWizard. For all subtrees that match the pattern, execute the visit action. The implementation uses the root node of the pattern in combination with visit(t, ttype, visitor) so nil-rooted patterns are not allowed. Patterns with wildcard roots are also not allowed. | |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| Modifier and Type | Field and Description |
|---|---|
| public boolean | |
| public String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | toString()
Overrides org. Implements org. |
| hasTextArg | back to summary |
|---|---|
| public boolean hasTextArg | |
| label | back to summary |
|---|---|
| public String label | |
| TreePattern | back to summary |
|---|---|
| public TreePattern(Token payload) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Implements org. Doc from org. Override to say how a node (not a tree) should look as text
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | create(Token payload)
Overrides org. Implements org. |
| TreePatternTreeAdaptor | back to summary |
|---|---|
| public TreePatternTreeAdaptor() | |
| create | back to summary |
|---|---|
| public Object create(Token payload) Overrides org. Implements org. Doc from org. Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload. This is the most common create call. Override if you want another kind of node to be built.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public abstract void |
| Visitor | back to summary |
|---|---|
| public Visitor() | |
| visit | back to summary |
|---|---|
| public void visit(Object t, Object parent, int childIndex, Map<String, Object> labels) Implements org.
| |
| visit | back to summary |
|---|---|
| public abstract void visit(Object t) | |
| Access | Constructor and Description |
|---|---|
| public |
| WildcardTreePattern | back to summary |
|---|---|
| public WildcardTreePattern(Token payload) | |