///|
/// Public diagnostics.
pub using @diagnostic {type SourceSpan, type XPathError, type XPathPhase}

///|
/// Public XPath document model and adapter builder.
pub using @model {
  type Document,
  type DocumentBuilder,
  type NodeId,
  type NodeKind,
  type QName,
}

///|
/// Public XPath values.
pub using @value {type NodeSet, type XPathValue}

///|
/// Public compiled-expression and context types.
pub using @engine {type CompiledXPath}

///|
pub using @context {
  type CompileLimits,
  type DynamicContext,
  type EvaluationLimits,
  type StaticContext,
}

///|
/// Public compiler, evaluator and XML adapter entry points.
pub using @engine {compile}

///|
pub using @engine {evaluate, select}

///|
pub using @xml {parse_document}

///|
/// Parse XML, compile an expression and evaluate it once.
///
/// Prefer the separate APIs when one expression or document is reused. The
/// expression is compiled before XML parsing so expression errors win when
/// both inputs are invalid.
pub fn evaluate_xml(
  expression : String,
  xml : String,
  static_context? : @context.StaticContext,
) -> @value.XPathValue raise @diagnostic.XPathError {
  let effective_static_context = static_context.unwrap_or(
    @context.StaticContext::new(),
  )
  let compiled = @engine.compile(expression, effective_static_context)
  let document = @xml.parse_document(xml)
  let context = @context.DynamicContext::new(document, document.root())
  @engine.evaluate(compiled, context)
}