///|
/// Validated, reusable XPath expression.
///
/// The lexer tokens, AST and evaluator plan remain private to this package so
/// the compiler and evaluator can share them without exposing internal IR.
declare pub type CompiledXPath

///|
/// Original expression text retained for diagnostics.
declare pub fn CompiledXPath::source(self : CompiledXPath) -> String

///|
/// Span covering the complete expression.
declare pub fn CompiledXPath::span(
  self : CompiledXPath,
) -> @diagnostic.SourceSpan

///|
/// Compile the complete XPath 1.0 expression grammar.
///
/// The implementation will apply explicit source-length, token-count and
/// nesting-depth limits and return checked diagnostics with UTF-16 spans.
declare pub fn compile(
  source : String,
  static_context : @context.StaticContext,
) -> CompiledXPath raise @diagnostic.XPathError

///|
/// Normalize a raw axis result to unique document order.
///
/// Kept private because callers observe only XPath node-set semantics.
declare fn normalize_document_order(
  document : @model.Document,
  nodes : Array[@model.NodeId],
) -> @value.NodeSet raise @diagnostic.XPathError

///|
/// Evaluate a compiled expression with XPath 1.0 semantics.
declare pub fn evaluate(
  expression : CompiledXPath,
  context : @context.DynamicContext,
) -> @value.XPathValue raise @diagnostic.XPathError

///|
/// Evaluate and require a node-set result.
declare pub fn select(
  expression : CompiledXPath,
  context : @context.DynamicContext,
) -> @value.NodeSet raise @diagnostic.XPathError