Package org.antlr.v4.runtime.tree.xpath
Class XPath
- java.lang.Object
-
- org.antlr.v4.runtime.tree.xpath.XPath
-
public class XPath extends Object
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 = newXPath
(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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<ParseTree>
evaluate(ParseTree t)
Return a list of all nodes starting att
as root that satisfy the path.static Collection<ParseTree>
findAll(ParseTree tree, String xpath, Parser parser)
protected XPathElement
getXPathElement(Token wordToken, boolean anywhere)
Convert word like*
orID
orexpr
to a path element.XPathElement[]
split(String path)
-
-
-
Field Detail
-
WILDCARD
public static final String WILDCARD
- See Also:
- Constant Field Values
-
NOT
public static final String NOT
- See Also:
- Constant Field Values
-
path
protected String path
-
elements
protected XPathElement[] elements
-
parser
protected Parser parser
-
-
Method Detail
-
split
public XPathElement[] split(String path)
-
getXPathElement
protected XPathElement getXPathElement(Token wordToken, boolean anywhere)
Convert word like*
orID
orexpr
to a path element.anywhere
istrue
if//
precedes the word.
-
findAll
public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser)
-
evaluate
public Collection<ParseTree> evaluate(ParseTree t)
Return a list of all nodes starting att
as root that satisfy the path. The root/
is relative to the node passed toevaluate(org.antlr.v4.runtime.tree.ParseTree)
.
-
-