本文整理了Java中org.antlr.v4.runtime.tree.xpath.XPath.findAll()
方法的一些代码示例,展示了XPath.findAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XPath.findAll()
方法的具体详情如下:
包路径:org.antlr.v4.runtime.tree.xpath.XPath
类名称:XPath
方法名:findAll
暂无
代码示例来源:origin: org.antlr/antlr4-runtime
/**
* 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;
}
代码示例来源:origin: antlr/intellij-plugin-v4
public static boolean ruleHasMultipleOutermostAlts(Parser parser, ParseTree ruleTree) {
Collection<ParseTree> ors = XPath.findAll(ruleTree, "/parserRuleSpec/ruleBlock/ruleAltList/OR", parser);
if ( ors.size()>=1 ) return true;
ors = XPath.findAll(ruleTree, "/lexerRule/lexerRuleBlock/lexerAltList/OR", parser);
return ors.size()>=1;
}
代码示例来源:origin: antlr/intellij-plugin-v4
public static TerminalNode getRuleDefNameNode(Parser parser, ParseTree tree, String ruleName) {
Collection<ParseTree> ruleDefRuleNodes;
if ( Grammar.isTokenName(ruleName) ) {
ruleDefRuleNodes = XPath.findAll(tree, "//lexerRule/TOKEN_REF", parser);
}
else {
ruleDefRuleNodes = XPath.findAll(tree, "//parserRuleSpec/RULE_REF", parser);
}
for (ParseTree node : ruleDefRuleNodes) {
String r = node.getText(); // always a TerminalNode; just get rule name of this def
if ( r.equals(ruleName) ) {
return (TerminalNode)node;
}
}
return null;
}
代码示例来源:origin: antlr/intellij-plugin-v4
public static List<TerminalNode> getAllRuleRefNodes(Parser parser, ParseTree tree, String ruleName) {
List<TerminalNode> nodes = new ArrayList<TerminalNode>();
Collection<ParseTree> ruleRefs;
if ( Grammar.isTokenName(ruleName) ) {
ruleRefs = XPath.findAll(tree, "//lexerRuleBlock//TOKEN_REF", parser);
}
else {
ruleRefs = XPath.findAll(tree, "//ruleBlock//RULE_REF", parser);
}
for (ParseTree node : ruleRefs) {
TerminalNode terminal = (TerminalNode)node;
Token rrefToken = terminal.getSymbol();
String r = rrefToken.getText();
if ( r.equals(ruleName) ) {
nodes.add(terminal);
}
}
if ( nodes.size()==0 ) return null;
return nodes;
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* 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;
}
代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime
/**
* 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;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* 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;
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
/**
* 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.
*/
@NotNull
public List<ParseTreeMatch> findAll(@NotNull ParseTree tree, @NotNull 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;
}
代码示例来源:origin: antlr/intellij-plugin-v4
Collection<ParseTree> literalNodes = XPath.findAll(tree, "//ruleBlock//STRING_LITERAL", parser);
LinkedHashMap<String, String> lexerRules = new LinkedHashMap<String, String>();
for (ParseTree node : literalNodes) {
Collection<ParseTree> allRuleNodes = XPath.findAll(tree, "//ruleSpec", parser);
for (ParseTree r : allRuleNodes) {
内容来源于网络,如有侵权,请联系作者删除!