Represent a subset of XPath XML path syntax for use in identifying nodes in parse trees.
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 ParseTree.findAll (tree, pathString, parser) . But that is just shorthand for:

 XPath p = new 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.

Ejemplo n.º 1
0
 public static ICollection <IParseTree> FindAll(IParseTree tree, string xpath, Parser parser)
 {
     Antlr4.Runtime.Tree.Xpath.XPath p = new Antlr4.Runtime.Tree.Xpath.XPath(parser, xpath);
     return(p.Evaluate(tree));
 }
Ejemplo n.º 2
0
 private void AssertTree(VBAParser parser, ParserRuleContext root, string xpath, Predicate<ICollection<IParseTree>> assertion)
 {
     var matches = new XPath(parser, xpath).Evaluate(root);
     Assert.IsTrue(assertion(matches));
 }
Ejemplo n.º 3
0
 public static ICollection<IParseTree> FindAll(IParseTree tree, string xpath, Parser parser)
 {
     Antlr4.Runtime.Tree.Xpath.XPath p = new Antlr4.Runtime.Tree.Xpath.XPath(parser, xpath);
     return p.Evaluate(tree);
 }