Class ParseTreePattern

java.lang.Object
org.antlr.v4.runtime.tree.pattern.ParseTreePattern

public class ParseTreePattern extends Object
A pattern like <ID> = <expr>; converted to a ParseTree by ParseTreePatternMatcher.compile(String, int).
  • Field Details

  • Constructor Details

  • Method Details

    • match

      Match a specific parse tree against this tree pattern.
      Parameters:
      tree - The parse tree to match against this tree pattern.
      Returns:
      A ParseTreeMatch object describing the result of the match operation. The ParseTreeMatch.succeeded() method can be used to determine whether or not the match was successful.
    • matches

      public boolean matches(@NotNull 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:
      true if tree is a match for the current tree pattern; otherwise, false.
    • findAll

      @NotNull public List<ParseTreeMatch> findAll(@NotNull ParseTree tree, @NotNull String xpath)
      Find all nodes using XPath and then try to match those subtrees against this tree pattern.
      Parameters:
      tree - The ParseTree to match against this pattern.
      xpath - An expression matching the nodes
      Returns:
      A collection of ParseTreeMatch objects describing the successful matches. Unsuccessful matches are omitted from the result, regardless of the reason for the failure.
    • getMatcher

      @NotNull public ParseTreePatternMatcher getMatcher()
      Get the ParseTreePatternMatcher which created this tree pattern.
      Returns:
      The ParseTreePatternMatcher which created this tree pattern.
    • getPattern

      @NotNull 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

      @NotNull public ParseTree getPatternTree()
      Get the tree pattern as a ParseTree. The rule and token tags from the pattern are present in the parse tree as terminal nodes with a symbol of type RuleTagToken or TokenTagToken.
      Returns:
      The tree pattern as a ParseTree.