mod ast;
mod eval;
mod parser;
pub use ast::{Axis, BinaryOp, Expr, NodeTest, Step};
pub use eval::Value;
pub use parser::XPathError;
use crate::tree::{Document, NodeId};
#[derive(Debug, Clone, PartialEq)]
pub struct XPath {
expr: Expr,
}
impl XPath {
pub fn compile(expr: &str) -> Result<Self, XPathError> {
Ok(Self {
expr: parser::compile(expr)?,
})
}
#[must_use]
pub fn evaluate(&self, doc: &Document) -> Value {
eval::evaluate(doc, &self.expr, doc.root())
}
#[must_use]
pub fn evaluate_from(&self, doc: &Document, context: NodeId) -> Value {
eval::evaluate(doc, &self.expr, context)
}
#[must_use]
pub const fn expr(&self) -> &Expr {
&self.expr
}
}