PureXML/Sources/XPath/Axis.swift
Mihaela Mihaljevic 1ae6680d94 feat(xpath): add an XPath 1.0 location-path subset
Add PureXML.XPath: a compiled location-path query engine reimplemented from the
XPath 1.0 specification; no upstream code copied.

- Compiler parses a path into steps; Evaluator walks the tree returning a
  Selection node-set (node or attribute) in document order.
- Forward axes only (child, descendant //, self ., attribute @), since the value
  model has no parent pointers. Node tests: name, *, text(), node(), comment().
  Predicates: [n], [@a], [@a='v'], [child], [child='v'].
- Public surface: XPath.Query (init compiles, evaluate/elements/strings), the
  Selection enum (element / stringValue), QueryError, and the one-shot
  PureXML.xpath(_:over:). Upward/sibling axes and the full expression language
  are explicitly out of scope.
- 12 XPath tests; 61 total.
2026-06-08 01:32:23 +02:00

16 lines
579 B
Swift

extension PureXML.XPath {
/// The supported XPath axes. The model is a value tree without parent
/// pointers, so only the forward axes are available; upward axes (parent,
/// ancestor) and sibling axes are intentionally out of scope.
enum Axis: Equatable {
/// Immediate children (the default axis).
case child
/// All descendants at any depth (reached with `//`).
case descendant
/// The context node itself (`.`).
case selfNode
/// Attributes of the context element (`@`).
case attribute
}
}