/** * The same as {@link #compileParseTreePattern(String, int)} but specify a * {@link Lexer} rather than trying to deduce it from this parser. */ public ParseTreePattern compileParseTreePattern(String pattern, int patternRuleIndex, Lexer lexer) { ParseTreePatternMatcher m = new ParseTreePatternMatcher(lexer, this); return m.compile(pattern, patternRuleIndex); }
/** * Find all nodes using XPath and then try to match those subtrees against * this tree pattern. * * @param tree The {@link ParseTree} to match against this pattern. * @param xpath An expression matching the nodes * * @return A collection of {@link ParseTreeMatch} objects describing the * successful matches. Unsuccessful matches are omitted from the result, * regardless of the reason for the failure. */ public List<ParseTreeMatch> findAll(ParseTree tree, String xpath) { Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser()); List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>(); for (ParseTree t : subtrees) { ParseTreeMatch match = match(t); if ( match.succeeded() ) { matches.add(match); } } return matches; }
/** * Compare {@code pattern} matched as rule {@code patternRuleIndex} against * {@code tree} and return a {@link ParseTreeMatch} object that contains the * matched elements, or the node at which the match failed. */ public ParseTreeMatch match(ParseTree tree, String pattern, int patternRuleIndex) { ParseTreePattern p = compile(pattern, patternRuleIndex); return match(tree, p); }
ParseTree mismatchedNode = null; RuleTagToken ruleTagToken = getRuleTagToken(r2); if ( ruleTagToken!=null ) { ParseTreeMatch m = null; ParseTree childMatch = matchImpl(r1.getChild(i), patternTree.getChild(i), labels); if ( childMatch != null ) { return childMatch;
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
/** * Match a specific parse tree against this tree pattern. * * @param tree The parse tree to match against this tree pattern. * @return A {@link ParseTreeMatch} object describing the result of the * match operation. The {@link ParseTreeMatch#succeeded()} method can be * used to determine whether or not the match was successful. */ public ParseTreeMatch match(ParseTree tree) { return matcher.match(tree, this); }
List<? extends Token> tokenList = tokenize(pattern); ListTokenSource tokenSrc = new ListTokenSource(tokenList); CommonTokenStream tokens = new CommonTokenStream(tokenSrc);
public List<? extends Token> tokenize(String pattern) { List<Chunk> chunks = split(pattern);
ParseTree mismatchedNode = null; RuleTagToken ruleTagToken = getRuleTagToken(r2); if ( ruleTagToken!=null ) { ParseTreeMatch m = null; ParseTree childMatch = matchImpl(r1.getChild(i), patternTree.getChild(i), labels); if ( childMatch != null ) { return childMatch;
/** * Compare {@code pattern} matched against {@code tree} and return a * {@link 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. */ public ParseTreeMatch match(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return new ParseTreeMatch(tree, pattern, labels, mismatchedNode); }
/** * Determine whether or not a parse tree matches this tree pattern. * * @param tree The parse tree to match against this tree pattern. * @return {@code true} if {@code tree} is a match for the current tree * pattern; otherwise, {@code false}. */ public boolean matches(ParseTree tree) { return matcher.match(tree, this).succeeded(); }
List<? extends Token> tokenList = tokenize(pattern); ListTokenSource tokenSrc = new ListTokenSource(tokenList); CommonTokenStream tokens = new CommonTokenStream(tokenSrc);
public List<? extends Token> tokenize(String pattern) { List<Chunk> chunks = split(pattern);
/** * Compare {@code pattern} matched as rule {@code patternRuleIndex} against * {@code tree} and return a {@link ParseTreeMatch} object that contains the * matched elements, or the node at which the match failed. */ public ParseTreeMatch match(ParseTree tree, String pattern, int patternRuleIndex) { ParseTreePattern p = compile(pattern, patternRuleIndex); return match(tree, p); }
/** * The same as {@link #compileParseTreePattern(String, int)} but specify a * {@link Lexer} rather than trying to deduce it from this parser. */ public ParseTreePattern compileParseTreePattern(String pattern, int patternRuleIndex, Lexer lexer) { ParseTreePatternMatcher m = new ParseTreePatternMatcher(lexer, this); return m.compile(pattern, patternRuleIndex); }
ParseTree mismatchedNode = null; RuleTagToken ruleTagToken = getRuleTagToken(r2); if ( ruleTagToken!=null ) { ParseTreeMatch m = null; ParseTree childMatch = matchImpl(r1.getChild(i), patternTree.getChild(i), labels); if ( childMatch != null ) { return childMatch;
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }