Top Description Fields Constructors Methods
org.antlr.v4.runtime.tree.pattern

public Class ParseTreeMatch

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.misc.MultiMap, org.antlr.v4.runtime.tree.ParseTree, java.util.Collections, .List

Represents the result of matching a ParseTree against a tree pattern.

Field Summary

Modifier and TypeField and Description
private final MultiMap<String, ParseTree>
labels

This is the backing field for getLabels().

private final ParseTree
mismatchedNode

This is the backing field for getMismatchedNode().

private final ParseTreePattern
pattern

This is the backing field for getPattern().

private final ParseTree
tree

This is the backing field for getTree().

Constructor Summary

AccessConstructor and Description
public
ParseTreeMatch(ParseTree
The parse tree to match against the pattern.
tree
,
ParseTreePattern
The parse tree pattern.
pattern
,
MultiMap<String, ParseTree>
A mapping from label names to collections of ParseTree objects located by the tree pattern matching process.
labels
,
ParseTree
The first node which failed to match the tree pattern during the matching process.
mismatchedNode
)

Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.

Method Summary

Modifier and TypeMethod and Description
public ParseTree

Returns:

The last ParseTree to match a tag with the specified label, or null if no parse tree matched a tag with the label.
get
(String
The label to check.
label
)

Get the last node associated with a specific label.

public List<ParseTree>

Returns:

A collection of all ParseTree nodes matching tags with the specified label. If no nodes matched the label, an empty list is returned.
getAll
(String
The label.
label
)

Return all nodes matching a rule or token tag with the specified label.

public MultiMap<String, ParseTree>

Returns:

A mapping from labels to parse tree nodes. If the parse tree pattern did not contain any rule or token tags, this map will be empty.
getLabels
()

Return a mapping from label → [list of nodes].

public ParseTree

Returns:

the node at which we first detected a mismatch, or null if the match was successful.
getMismatchedNode
()

Get the node at which we first detected a mismatch.

public ParseTreePattern

Returns:

The tree pattern we are matching against.
getPattern
()

Get the tree pattern we are matching against.

public ParseTree

Returns:

The ParseTree we are trying to match to a pattern.
getTree
()

Get the parse tree we are trying to match to a pattern.

public boolean

Returns:

true if the match operation succeeded; otherwise, false.
succeeded
()

Gets a value indicating whether the match operation succeeded.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

labelsback to summary
private final MultiMap<String, ParseTree> labels

This is the backing field for getLabels().

mismatchedNodeback to summary
private final ParseTree mismatchedNode

This is the backing field for getMismatchedNode().

patternback to summary
private final ParseTreePattern pattern

This is the backing field for getPattern().

treeback to summary
private final ParseTree tree

This is the backing field for getTree().

Constructor Detail

ParseTreeMatchback to summary
public ParseTreeMatch(ParseTree tree, ParseTreePattern pattern, MultiMap<String, ParseTree> labels, ParseTree mismatchedNode)

Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.

Parameters
tree:ParseTree

The parse tree to match against the pattern.

pattern:ParseTreePattern

The parse tree pattern.

labels:MultiMap<String, ParseTree>

A mapping from label names to collections of ParseTree objects located by the tree pattern matching process.

mismatchedNode:ParseTree

The first node which failed to match the tree pattern during the matching process.

Exceptions
IllegalArgumentException:
  • if tree is null
  • if pattern is null
  • if labels is null

Method Detail

getback to summary
public ParseTree get(String label)

Get the last node associated with a specific 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.

Parameters
label:String

The label to check.

Returns:ParseTree

The last ParseTree to match a tag with the specified label, or null if no parse tree matched a tag with the label.

getAllback to summary
public List<ParseTree> getAll(String label)

Return all nodes matching a rule or token tag with the specified 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.

  • Parse tree nodes matching tags of the form <foo:anyRuleName> and <foo:AnyTokenName>.
  • Parse tree nodes matching tags of the form <anyLabel:foo>.
  • Parse tree nodes matching tags of the form <foo>.
Parameters
label:String

The label.

Returns:List<ParseTree>

A collection of all ParseTree nodes matching tags with the specified label. If no nodes matched the label, an empty list is returned.

getLabelsback to summary
public MultiMap<String, ParseTree> getLabels()

Return a mapping from label → [list of nodes].

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).

Returns:MultiMap<String, ParseTree>

A mapping from labels to parse tree nodes. If the parse tree pattern did not contain any rule or token tags, this map will be empty.

getMismatchedNodeback to summary
public ParseTree getMismatchedNode()

Get the node at which we first detected a mismatch.

Returns:ParseTree

the node at which we first detected a mismatch, or null if the match was successful.

getPatternback to summary
public ParseTreePattern getPattern()

Get the tree pattern we are matching against.

Returns:ParseTreePattern

The tree pattern we are matching against.

getTreeback to summary
public ParseTree getTree()

Get the parse tree we are trying to match to a pattern.

Returns:ParseTree

The ParseTree we are trying to match to a pattern.

succeededback to summary
public boolean succeeded()

Gets a value indicating whether the match operation succeeded.

Returns:boolean

true if the match operation succeeded; otherwise, false.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override