use fhp_core::tag::Tag;
#[derive(Debug, Clone, PartialEq)]
pub enum XPathExpr {
DescendantByTag(Tag),
DescendantByAttr {
tag: Tag,
attr: String,
value: String,
},
DescendantByAttrExists {
tag: Tag,
attr: String,
},
AbsolutePath(Vec<PathStep>),
ContainsPredicate {
tag: Tag,
attr: String,
substr: String,
},
PositionPredicate {
tag: Tag,
pos: usize,
},
TextExtract(Box<XPathExpr>),
DescendantWildcard,
DescendantWildcardByAttr {
attr: String,
value: String,
},
DescendantWildcardByAttrExists {
attr: String,
},
Parent,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PathStep {
pub tag: Tag,
pub predicate: Option<Predicate>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Predicate {
AttrEquals {
attr: String,
value: String,
},
Contains {
attr: String,
substr: String,
},
Position(usize),
AttrExists {
attr: String,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum XPathResult {
Nodes(Vec<fhp_tree::node::NodeId>),
Strings(Vec<String>),
Boolean(bool),
}
impl XPathResult {
pub fn is_empty(&self) -> bool {
match self {
Self::Nodes(v) => v.is_empty(),
Self::Strings(v) => v.is_empty(),
Self::Boolean(_) => false,
}
}
pub fn len(&self) -> usize {
match self {
Self::Nodes(v) => v.len(),
Self::Strings(v) => v.len(),
Self::Boolean(_) => 1,
}
}
}