XPathElem
XPath 3.1 AST. The root of the type hierarchy is XPathElem. It offers the ElemApi query API.
The requirements on this AST are as follows:
-
It must represent the syntax tree of a successfully parsed XPath expression
-
It is not annotated with more semantic information, like type information that is not included in the XPath expression
-
It does not know anything about the context in which it runs, like bound namespaces etc.
-
It is rich enough to be able to serialize the AST back to XPath, knowing exactly where to place parentheses, braces, etc.
-
It should help evaluation, so it should model operator associativity and precedence correctly, where feasible
-
It must be readable in that object composition trees are not unnecessarily deep and therefore hard to comprehend
-
Serialization of the AST to XPath may lead to differences in whitespace (and operator aliases), but other than that the result must be the same
-
The AST class hierarchy does not have to use the exact same names as the XPath grammar
-
Instances of the AST classes are easy to create in an ad-hoc manner, so they contain no parsing state
-
The AST classes are case classes, with value equality and good support for pattern matching
It would be natural for the AST types to have IS-A relationships modeled as type inheritance, and HAS-A relationships modeled as composition. Where feasible, this approach has been followed. Consequently, sealed trait inheritance has been used a lot (IS-A instead of HAS-A), and unnecessarily deep object trees are prevented in this way.
Having such an AST of a successfully parsed XPath expression, it must be easy to reliably find used namespace prefixes, for example.
The AST, as well as the parser, were developed using the XPath 3.1 specification as input. In particular, see https://www.w3.org/TR/xpath-31/#id-grammar and https://www.w3.org/TR/xpath-31/#id-precedence-order. Note that the grammar in isolation does not clearly convey left or right associativity of operators, so the extra information about operator precedence and associativity is essential for understanding the "structure" of compound expressions.
TODO Improve several class names.
Value members
Abstract methods
Inherited methods
- Inherited from
- ElemLike