Constructor and Description |
---|
ParseTreeMatch(ParseTree tree,
ParseTreePattern pattern,
MultiMap<String,ParseTree> labels,
ParseTree mismatchedNode)
Constructs a new instance of
ParseTreeMatch from the specified
parse tree and pattern. |
Modifier and Type | Method and Description |
---|---|
ParseTree |
get(String label)
Get the last node associated with a specific
label . |
List<ParseTree> |
getAll(String label)
Return all nodes matching a rule or token tag with the specified label.
|
MultiMap<String,ParseTree> |
getLabels()
Return a mapping from label → [list of nodes].
|
ParseTree |
getMismatchedNode()
Get the node at which we first detected a mismatch.
|
ParseTreePattern |
getPattern()
Get the tree pattern we are matching against.
|
ParseTree |
getTree()
Get the parse tree we are trying to match to a pattern.
|
boolean |
succeeded()
Gets a value indicating whether the match operation succeeded.
|
String |
toString() |
public ParseTreeMatch(ParseTree tree, ParseTreePattern pattern, MultiMap<String,ParseTree> labels, ParseTree mismatchedNode)
ParseTreeMatch
from the specified
parse tree and pattern.tree
- The parse tree to match against the pattern.pattern
- The parse tree pattern.labels
- A mapping from label names to collections of
ParseTree
objects located by the tree pattern matching process.mismatchedNode
- The first node which failed to match the tree
pattern during the matching process.IllegalArgumentException
- if tree
is null
IllegalArgumentException
- if pattern
is null
IllegalArgumentException
- if labels
is null
public ParseTree get(String label)
label
.
For example, for pattern <id:ID>
, get("id")
returns the
node matched for that ID
. If more than one node
matched the specified label, only the last is returned. If there is
no node associated with the label, this returns null
.
Pattern tags like <ID>
and <expr>
without labels are
considered to be labeled with ID
and expr
, respectively.
label
- The label to check.ParseTree
to match a tag with the specified
label, or null
if no parse tree matched a tag with the label.public List<ParseTree> getAll(String label)
If the label
is the name of a parser rule or token in the
grammar, the resulting list will contain both the parse trees matching
rule or tags explicitly labeled with the label and the complete set of
parse trees matching the labeled and unlabeled tags in the pattern for
the parser rule or token. For example, if label
is "foo"
,
the result will contain all of the following.
<foo:anyRuleName>
and
<foo:AnyTokenName>
.<anyLabel:foo>
.<foo>
.label
- The label.ParseTree
nodes matching tags with
the specified label
. If no nodes matched the label, an empty list
is returned.public MultiMap<String,ParseTree> getLabels()
The map includes special entries corresponding to the names of rules and
tokens referenced in tags in the original pattern. For additional
information, see the description of getAll(String)
.
public ParseTree getMismatchedNode()
null
if the match was successful.public boolean succeeded()
true
if the match operation succeeded; otherwise,
false
.public ParseTreePattern getPattern()
public ParseTree getTree()
ParseTree
we are trying to match to a pattern.Copyright © 1992–2016 ANTLR. All rights reserved.