XPathElem

sealed trait XPathElem extends ElemLike[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.

class Object
trait Matchable
class Any
object Plus
object Minus
trait Argument
trait Comp
object Eq
object Ne
object Lt
object Le
object Gt
object Ge
trait NodeComp
object Is
object Precedes
object Follows
trait ValueComp
object Eq
object Ne
object Lt
object Le
object Gt
object Ge
object Child
object Descendant
object Attribute
object Self
object Following
object Namespace
object Intersect
object Except
trait ItemType
trait ArrayTest
trait MapTest
object AnyMapTest
trait LeafElem
object Times
object Div
object IDiv
object Mod
object Parent
object Ancestor
object Preceding
trait StepOp
object TextTest
trait UnaryOp
object Plus
object Minus
class VarRef
trait NodeTest
trait KindTest
trait PITest
trait NameTest
trait Wildcard
class Param
class ParamList
trait Postfix
class Predicate
class ForExpr
class LetExpr
trait XPathExpr
trait Expr
class IfExpr
trait OrExpr
trait AndExpr
trait RangeExpr
trait UnionExpr
trait TreatExpr
trait CastExpr
trait ArrowExpr
trait UnaryExpr
trait ValueExpr
trait PathExpr
trait StepExpr
trait AxisStep
trait Literal

Value members

Abstract methods

def children: IndexedSeq[XPathElem]

Returns the (immediate) child elements of this element.

Returns the (immediate) child elements of this element.

Inherited methods

final def filterElems(p: XPathElem => Boolean): IndexedSeq[XPathElem]
Inherited from
ElemLike
final def filterElemsOfType[A <: XPathElem](cls: ClassTag[A])(p: A => Boolean): IndexedSeq[A]
Inherited from
ElemLike
final def filterElemsOrSelf(p: XPathElem => Boolean): IndexedSeq[XPathElem]
Inherited from
ElemLike
final def filterElemsOrSelfOfType[A <: XPathElem](cls: ClassTag[A])(p: A => Boolean): IndexedSeq[A]
Inherited from
ElemLike
final def findAllElems: IndexedSeq[XPathElem]
Inherited from
ElemLike
final def findAllElemsOfType[A <: XPathElem](cls: ClassTag[A]): IndexedSeq[A]
Inherited from
ElemLike
final def findAllElemsOrSelf: IndexedSeq[XPathElem]
Inherited from
ElemLike
final def findAllElemsOrSelfOfType[A <: XPathElem](cls: ClassTag[A]): IndexedSeq[A]
Inherited from
ElemLike
final def findAllTopmostElemsOfType[A <: XPathElem](cls: ClassTag[A]): IndexedSeq[A]
Inherited from
ElemLike
final def findAllTopmostElemsOrSelfOfType[A <: XPathElem](cls: ClassTag[A]): IndexedSeq[A]
Inherited from
ElemLike
final def findElem(p: XPathElem => Boolean): Option[XPathElem]
Inherited from
ElemLike
final def findElemOfType[A <: XPathElem](cls: ClassTag[A])(p: A => Boolean): Option[A]
Inherited from
ElemLike
final def findElemOrSelf(p: XPathElem => Boolean): Option[XPathElem]
Inherited from
ElemLike
final def findElemOrSelfOfType[A <: XPathElem](cls: ClassTag[A])(p: A => Boolean): Option[A]
Inherited from
ElemLike
final def findFirstElemOfType[A <: XPathElem](cls: ClassTag[A]): Option[A]
Inherited from
ElemLike
final def findFirstElemOrSelfOfType[A <: XPathElem](cls: ClassTag[A]): Option[A]
Inherited from
ElemLike
final def findTopmostElems(p: XPathElem => Boolean): IndexedSeq[XPathElem]
Inherited from
ElemLike
final def findTopmostElemsOfType[A <: XPathElem](cls: ClassTag[A])(p: A => Boolean): IndexedSeq[A]
Inherited from
ElemLike
final def findTopmostElemsOrSelf(p: XPathElem => Boolean): IndexedSeq[XPathElem]
Inherited from
ElemLike
final def findTopmostElemsOrSelfOfType[A <: XPathElem](cls: ClassTag[A])(p: A => Boolean): IndexedSeq[A]
Inherited from
ElemLike