PureXML/Sources/XPath/NodeTest.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
496 B
Swift

extension PureXML.XPath {
/// The node test of a location step: which nodes on the axis qualify.
enum NodeTest: Equatable {
/// A local-name match (`book`).
case name(String)
/// The `*` wildcard (any element, or any attribute on the attribute axis).
case wildcard
/// `text()`: character-data and CDATA nodes.
case text
/// `node()`: any node.
case node
/// `comment()`: comment nodes.
case comment
}
}