本文整理了Java中org.antlr.v4.runtime.tree.xpath.XPath
类的一些代码示例,展示了XPath
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XPath
类的具体详情如下:
包路径:org.antlr.v4.runtime.tree.xpath.XPath
类名称:XPath
[英]Represent a subset of XPath XML path syntax for use in identifying nodes in parse trees.
Split path into words and separators / and // via ANTLR itself then walk path elements from left to right. At each separator-word pair, find set of nodes. Next stage uses those as work list.
The basic interface is XPath#findAll (tree, pathString, parser). But that is just shorthand for:
XPath p = new
XPath#XPath(parser, pathString);
return p.
#evaluate(tree);
See org.antlr.v4.test.TestXPath for descriptions. In short, this allows operators:
/ root // anywhere ! invert; this must appear directly after root or anywhere operator
and path elements:
ID token name 'string' any string literal token from the grammar expr rule name * wildcard matching any node
Whitespace is not allowed.
[中]表示用于在解析树中标识节点的XPath XML路径语法的子集。
通过ANTLR本身将路径拆分为单词和分隔符/和//然后从左向右遍历路径元素。在每个分隔词对中,找到一组节点。下一阶段使用这些作为工作列表。
基本接口是XPath#findAll(树、路径字符串、解析器)。但这只是以下的简写:
XPath p = new
XPath#XPath(parser, pathString);
return p.
#evaluate(tree);
见org。安特尔。v4。测验TestXPath用于描述。简而言之,这允许操作员:
/根//任何地方!倒转这必须直接出现在root或anywhere运算符之后
和路径元素:
ID标记名称“string”语法表达式规则名称*匹配任何节点的通配符中的任何字符串文字标记
空格是不允许的。
代码示例来源: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: org.antlr/antlr4-runtime
public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser) {
XPath p = new XPath(parser, xpath);
return p.evaluate(tree);
}
代码示例来源:origin: org.antlr/antlr4-runtime
next = tokens.get(i);
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
case XPathLexer.RULE_REF :
case XPathLexer.WILDCARD :
elements.add( getXPathElement(el, false) );
i++;
break;
代码示例来源:origin: org.antlr/antlr4-runtime
public XPath(Parser parser, String path) {
this.parser = parser;
this.path = path;
elements = split(path);
// System.out.println(Arrays.toString(elements));
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
public XPath(Parser parser, String path) {
this.parser = parser;
this.path = path;
elements = split(path);
// System.out.println(Arrays.toString(elements));
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser) {
XPath p = new XPath(parser, xpath);
return p.evaluate(tree);
}
代码示例来源: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: com.impetus.fabric/fabric-jdbc-driver-shaded
public XPath(Parser parser, String path) {
this.parser = parser;
this.path = path;
elements = split(path);
// System.out.println(Arrays.toString(elements));
}
代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime
next = tokens.get(i);
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
case XPathLexer.RULE_REF :
case XPathLexer.WILDCARD :
elements.add( getXPathElement(el, false) );
i++;
break;
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser) {
XPath p = new XPath(parser, xpath);
return p.evaluate(tree);
}
代码示例来源: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: uk.co.nichesolutions/antlr4-runtime
public XPath(Parser parser, String path) {
this.parser = parser;
this.path = path;
elements = split(path);
// System.out.println(Arrays.toString(elements));
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
next = tokens.get(i);
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
case XPathLexer.RULE_REF :
case XPathLexer.WILDCARD :
elements.add( getXPathElement(el, false) );
i++;
break;
代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime
public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser) {
XPath p = new XPath(parser, xpath);
return p.evaluate(tree);
}
代码示例来源: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
public XPath(Parser parser, String path) {
this.parser = parser;
this.path = path;
elements = split(path);
// System.out.println(Arrays.toString(elements));
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
next = tokens.get(i);
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
case XPathLexer.RULE_REF :
case XPathLexer.WILDCARD :
elements.add( getXPathElement(el, false) );
i++;
break;
代码示例来源:origin: io.virtdata/virtdata-lib-realer
public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser) {
XPath p = new XPath(parser, xpath);
return p.evaluate(tree);
}
代码示例来源: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: com.tunnelvisionlabs/antlr4-runtime
next = tokens.get(i);
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
case XPathLexer.RULE_REF :
case XPathLexer.WILDCARD :
elements.add( getXPathElement(el, false) );
i++;
break;
内容来源于网络,如有侵权,请联系作者删除!