Class ParseTreePattern
- java.lang.Object
-
- org.antlr.v4.runtime.tree.pattern.ParseTreePattern
-
public class ParseTreePattern extends Object
A pattern like<ID> = <expr>;converted to aParseTreebyParseTreePatternMatcher.compile(String, int).
-
-
Constructor Summary
Constructors Constructor Description ParseTreePattern(ParseTreePatternMatcher matcher, String pattern, int patternRuleIndex, ParseTree patternTree)Construct a new instance of theParseTreePatternclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<ParseTreeMatch>findAll(ParseTree tree, String xpath)Find all nodes using XPath and then try to match those subtrees against this tree pattern.ParseTreePatternMatchergetMatcher()Get theParseTreePatternMatcherwhich created this tree pattern.StringgetPattern()Get the tree pattern in concrete syntax form.intgetPatternRuleIndex()Get the parser rule which serves as the outermost rule for the tree pattern.ParseTreegetPatternTree()Get the tree pattern as aParseTree.ParseTreeMatchmatch(ParseTree tree)Match a specific parse tree against this tree pattern.booleanmatches(ParseTree tree)Determine whether or not a parse tree matches this tree pattern.
-
-
-
Constructor Detail
-
ParseTreePattern
public ParseTreePattern(ParseTreePatternMatcher matcher, String pattern, int patternRuleIndex, ParseTree patternTree)
Construct a new instance of theParseTreePatternclass.- Parameters:
matcher- TheParseTreePatternMatcherwhich created this tree pattern.pattern- The tree pattern in concrete syntax form.patternRuleIndex- The parser rule which serves as the root of the tree pattern.patternTree- The tree pattern inParseTreeform.
-
-
Method Detail
-
match
public ParseTreeMatch match(ParseTree tree)
Match a specific parse tree against this tree pattern.- Parameters:
tree- The parse tree to match against this tree pattern.- Returns:
- A
ParseTreeMatchobject describing the result of the match operation. TheParseTreeMatch.succeeded()method can be used to determine whether or not the match was successful.
-
matches
public boolean matches(ParseTree tree)
Determine whether or not a parse tree matches this tree pattern.- Parameters:
tree- The parse tree to match against this tree pattern.- Returns:
trueiftreeis a match for the current tree pattern; otherwise,false.
-
findAll
public List<ParseTreeMatch> findAll(ParseTree tree, String xpath)
Find all nodes using XPath and then try to match those subtrees against this tree pattern.- Parameters:
tree- TheParseTreeto match against this pattern.xpath- An expression matching the nodes- Returns:
- A collection of
ParseTreeMatchobjects describing the successful matches. Unsuccessful matches are omitted from the result, regardless of the reason for the failure.
-
getMatcher
public ParseTreePatternMatcher getMatcher()
Get theParseTreePatternMatcherwhich created this tree pattern.- Returns:
- The
ParseTreePatternMatcherwhich created this tree pattern.
-
getPattern
public String getPattern()
Get the tree pattern in concrete syntax form.- Returns:
- The tree pattern in concrete syntax form.
-
getPatternRuleIndex
public int getPatternRuleIndex()
Get the parser rule which serves as the outermost rule for the tree pattern.- Returns:
- The parser rule which serves as the outermost rule for the tree pattern.
-
getPatternTree
public ParseTree getPatternTree()
Get the tree pattern as aParseTree. The rule and token tags from the pattern are present in the parse tree as terminal nodes with a symbol of typeRuleTagTokenorTokenTagToken.- Returns:
- The tree pattern as a
ParseTree.
-
-