#[derive(Clone, Debug)]
pub(super) enum Expr {
Path(Path),
Filter {
primary: Box<Expr>,
predicates: Vec<Expr>,
},
Union(Box<Expr>, Box<Expr>),
Binary(BinOp, Box<Expr>, Box<Expr>),
Negate(Box<Expr>),
Literal(String),
Number(f64),
Call(Func, Vec<Expr>),
}
#[derive(Clone, Debug)]
pub(super) struct Path {
pub base: Option<Box<Expr>>,
pub absolute: bool,
pub steps: Vec<Step>,
}
#[derive(Clone, Debug)]
pub(super) struct Step {
pub axis: Axis,
pub test: NodeTest,
pub predicates: Vec<Expr>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Axis {
Child,
Descendant,
DescendantOrSelf,
Self_,
Parent,
Ancestor,
Attribute,
FollowingSibling,
PrecedingSibling,
}
#[derive(Clone, Debug)]
pub(super) enum NodeTest {
Any,
Name(String),
Text,
Node,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum BinOp {
Or,
And,
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
Add,
Sub,
Mul,
Div,
Mod,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Func {
Position,
Last,
Count,
Not,
True,
False,
Name,
LocalName,
String,
Number,
Boolean,
Contains,
StartsWith,
NormalizeSpace,
Concat,
Substring,
SubstringBefore,
SubstringAfter,
StringLength,
Translate,
Sum,
Floor,
Ceiling,
Round,
Id,
Lang,
NamespaceUri,
}
impl Func {
pub(super) fn lookup(name: &str) -> Option<Self> {
Some(match name {
"position" => Self::Position,
"last" => Self::Last,
"count" => Self::Count,
"not" => Self::Not,
"true" => Self::True,
"false" => Self::False,
"name" => Self::Name,
"local-name" => Self::LocalName,
"string" => Self::String,
"number" => Self::Number,
"boolean" => Self::Boolean,
"contains" => Self::Contains,
"starts-with" => Self::StartsWith,
"normalize-space" => Self::NormalizeSpace,
"concat" => Self::Concat,
"substring" => Self::Substring,
"substring-before" => Self::SubstringBefore,
"substring-after" => Self::SubstringAfter,
"string-length" => Self::StringLength,
"translate" => Self::Translate,
"sum" => Self::Sum,
"floor" => Self::Floor,
"ceiling" => Self::Ceiling,
"round" => Self::Round,
"id" => Self::Id,
"lang" => Self::Lang,
"namespace-uri" => Self::NamespaceUri,
_ => return None,
})
}
}