XPath

@uml Represent a subset of XPath XML path syntax for use in identifying nodes in parse trees.

<p> Split path into words and separators {@code /} and {@code //} 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.</p>

<p> The basic interface is {@link XPath#findAll ParseTree.findAll}{@code (tree, pathString, parser)}. But that is just shorthand for:</p>

<pre> {@link XPath} p = new {@link XPath#XPath XPath}(parser, pathString); return p.{@link #evaluate evaluate}(tree); </pre>

<p> See {@code org.antlr.v4.test.TestXPath} for descriptions. In short, this allows operators:</p>

<dl> <dt>/</dt> <dd>root</dd> <dt>//</dt> <dd>anywhere</dd> <dt>!</dt> <dd>invert; this must appear directly after root or anywhere operator</dd> </dl>

<p> and path elements:</p>

<dl> <dt>ID</dt> <dd>token name</dd> <dt>'string'</dt> <dd>any string literal token from the grammar</dd> <dt>expr</dt> <dd>rule name</dd> <dt>*</dt> <dd>wildcard matching any node</dd> </dl>

<p> Whitespace is not allowed.</p>

Constructors

this
this(Parser parser, string path)
Undocumented in source.

Members

Functions

evaluate
ParseTree[] evaluate(ParseTree t)

@uml Return a list of all nodes starting at {@code t} as root that satisfy the path. The root {@code /} is relative to the node passed to {@link #evaluate}.

getXPathElement
XPathElement getXPathElement(Token wordToken, bool anywhere)

@uml Convert word like {@code *} or {@code ID} or {@code expr} to a path element. {@code anywhere} is {@code true} if {@code //} precedes the word.

split
XPathElement[] split(string path)

@uml TODO: check for invalid token/rule names, bad syntax

Static functions

findAll
ParseTree[] findAll(ParseTree tree, string xpath, Parser parser)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

NOT
enum string NOT;

@uml word for invert operator

WILDCARD
enum string WILDCARD;

@uml word not operator/separator

elements
XPathElement[] elements;
Undocumented in source.
parser
Parser parser;
Undocumented in source.
path
string path;
Undocumented in source.

Meta