use malloc_size_of_derive::MallocSizeOf;
use markup5ever::QualName;
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub enum Expression {
Binary(Box<Expression>, BinaryOperator, Box<Expression>),
Negate(Box<Expression>),
Path(PathExpression),
LocationStep(LocationStepExpression),
Filter(FilterExpression),
Literal(Literal),
Variable(QName),
ContextItem,
Function(CoreFunction),
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub enum BinaryOperator {
Or,
And,
Union,
Equal,
NotEqual,
LessThan,
GreaterThan,
LessThanOrEqual,
GreaterThanOrEqual,
Add,
Subtract,
Multiply,
Divide,
Modulo,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct PathExpression {
pub(crate) is_absolute: bool,
pub(crate) has_implicit_descendant_or_self_step: bool,
pub(crate) steps: Vec<Expression>,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct PredicateListExpression {
pub(crate) predicates: Vec<Expression>,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct FilterExpression {
pub(crate) expression: Box<Expression>,
pub(crate) predicates: PredicateListExpression,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct LocationStepExpression {
pub(crate) axis: Axis,
pub(crate) node_test: NodeTest,
pub(crate) predicate_list: PredicateListExpression,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub(crate) enum Axis {
Child,
Descendant,
Attribute,
Self_,
DescendantOrSelf,
FollowingSibling,
Following,
Namespace,
Parent,
Ancestor,
PrecedingSibling,
Preceding,
AncestorOrSelf,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub(crate) enum NodeTest {
Name(QualName),
Wildcard,
Kind(KindTest),
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct QName {
pub(crate) prefix: Option<String>,
pub(crate) local_part: String,
}
impl std::fmt::Display for QName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.prefix {
Some(prefix) => write!(f, "{}:{}", prefix, self.local_part),
None => write!(f, "{}", self.local_part),
}
}
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub(crate) enum KindTest {
PI(Option<String>),
Comment,
Text,
Node,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub enum Literal {
Integer(i64),
Decimal(f64),
String(String),
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub enum CoreFunction {
Last,
Position,
Count(Box<Expression>),
Id(Box<Expression>),
LocalName(Option<Box<Expression>>),
NamespaceUri(Option<Box<Expression>>),
Name(Option<Box<Expression>>),
String(Option<Box<Expression>>),
Concat(Vec<Expression>),
StartsWith(Box<Expression>, Box<Expression>),
Contains(Box<Expression>, Box<Expression>),
SubstringBefore(Box<Expression>, Box<Expression>),
SubstringAfter(Box<Expression>, Box<Expression>),
Substring(Box<Expression>, Box<Expression>, Option<Box<Expression>>),
StringLength(Option<Box<Expression>>),
NormalizeSpace(Option<Box<Expression>>),
Translate(Box<Expression>, Box<Expression>, Box<Expression>),
Number(Option<Box<Expression>>),
Sum(Box<Expression>),
Floor(Box<Expression>),
Ceiling(Box<Expression>),
Round(Box<Expression>),
Boolean(Box<Expression>),
Not(Box<Expression>),
True,
False,
Lang(Box<Expression>),
}