C# Class Antlr4.Runtime.Tree.Xpath.XPath

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.

Mostra file Open project: antlr/antlr4 Class Usage Examples

Protected Properties

Property Type Description
elements Antlr4.Runtime.Tree.Xpath.XPathElement[]
parser Parser
path string

Public Methods

Method Description
Evaluate ( IParseTree t ) : ICollection

Return a list of all nodes starting at t as root that satisfy the path. The root / is relative to the node passed to Evaluate(Antlr4.Runtime.Tree.IParseTree) .

FindAll ( IParseTree tree, string xpath, Parser parser ) : ICollection
Split ( string path ) : Antlr4.Runtime.Tree.Xpath.XPathElement[]
XPath ( Parser parser, string path ) : System

Protected Methods

Method Description
GetXPathElement ( IToken wordToken, bool anywhere ) : XPathElement

Convert word like * or ID or expr to a path element. anywhere is if // precedes the word.

Method Details

Evaluate() public method

Return a list of all nodes starting at t as root that satisfy the path. The root / is relative to the node passed to Evaluate(Antlr4.Runtime.Tree.IParseTree) .
public Evaluate ( IParseTree t ) : ICollection
t IParseTree
return ICollection

FindAll() public static method

public static FindAll ( IParseTree tree, string xpath, Parser parser ) : ICollection
tree IParseTree
xpath string
parser Parser
return ICollection

GetXPathElement() protected method

Convert word like * or ID or expr to a path element. anywhere is if // precedes the word.
protected GetXPathElement ( IToken wordToken, bool anywhere ) : XPathElement
wordToken IToken
anywhere bool
return XPathElement

Split() public method

public Split ( string path ) : Antlr4.Runtime.Tree.Xpath.XPathElement[]
path string
return Antlr4.Runtime.Tree.Xpath.XPathElement[]

XPath() public method

public XPath ( Parser parser, string path ) : System
parser Parser
path string
return System

Property Details

elements protected_oe property

protected XPathElement[],Antlr4.Runtime.Tree.Xpath elements
return Antlr4.Runtime.Tree.Xpath.XPathElement[]

parser protected_oe property

protected Parser parser
return Parser

path protected_oe property

protected string path
return string