Class ParseTreePatternMatcher

    • Constructor Detail

      • ParseTreePatternMatcher

        public ParseTreePatternMatcher​(Lexer lexer,
                                       Parser parser)
        Constructs a ParseTreePatternMatcher or from a Lexer and Parser object. The lexer input stream is altered for tokenizing the tree patterns. The parser is used as a convenient mechanism to get the grammar name, plus token, rule names.
    • Method Detail

      • setDelimiters

        public void setDelimiters​(String start,
                                  String stop,
                                  String escapeLeft)
        Set the delimiters used for marking rule and token tags within concrete syntax used by the tree pattern parser.
        Parameters:
        start - The start delimiter.
        stop - The stop delimiter.
        escapeLeft - The escape sequence to use for escaping a start or stop delimiter.
        Throws:
        IllegalArgumentException - if start is null or empty.
        IllegalArgumentException - if stop is null or empty.
      • matches

        public boolean matches​(ParseTree tree,
                               String pattern,
                               int patternRuleIndex)
        Does pattern matched as rule patternRuleIndex match tree?
      • matches

        public boolean matches​(ParseTree tree,
                               ParseTreePattern pattern)
        Does pattern matched as rule patternRuleIndex match tree? Pass in a compiled pattern instead of a string representation of a tree pattern.
      • match

        public ParseTreeMatch match​(ParseTree tree,
                                    String pattern,
                                    int patternRuleIndex)
        Compare pattern matched as rule patternRuleIndex against tree and return a ParseTreeMatch object that contains the matched elements, or the node at which the match failed.
      • match

        public ParseTreeMatch match​(ParseTree tree,
                                    ParseTreePattern pattern)
        Compare pattern matched against tree and return a ParseTreeMatch object that contains the matched elements, or the node at which the match failed. Pass in a compiled pattern instead of a string representation of a tree pattern.
      • getLexer

        public Lexer getLexer()
        Used to convert the tree pattern string into a series of tokens. The input stream is reset.
      • getParser

        public Parser getParser()
        Used to collect to the grammar file name, token names, rule names for used to parse the pattern into a parse tree.
      • matchImpl

        protected ParseTree matchImpl​(ParseTree tree,
                                      ParseTree patternTree,
                                      MultiMap<String,​ParseTree> labels)
        Recursively walk tree against patternTree, filling match.labels.
        Returns:
        the first node encountered in tree which does not match a corresponding node in patternTree, or null if the match was successful. The specific node returned depends on the matching algorithm used by the implementation, and may be overridden.