pub enum Expr<A> {
Atom(A),
Not(Box<Expr<A>>),
And(Box<Expr<A>>, Box<Expr<A>>),
Or(Box<Expr<A>>, Box<Expr<A>>),
}Expand description
A parsed boolean filter expression, generic over its atom representation.
The parser produces an Expr<RawAtom>. Consumer crates lift
atoms to a typed representation (e.g. Expr<TagName>,
Expr<PathPattern>, Expr<RelationalAtom>) before evaluation.
Trees built by the parser are left-associative for binary
operators and follow the precedence order of QRY-002:
! tightest, then &, then |.
Variants§
Atom(A)
A leaf atom.
Not(Box<Expr<A>>)
Negation of an inner expression.
And(Box<Expr<A>>, Box<Expr<A>>)
Logical conjunction of two sub-expressions.
Or(Box<Expr<A>>, Box<Expr<A>>)
Logical disjunction of two sub-expressions.
Implementations§
Source§impl<A> Expr<A>
impl<A> Expr<A>
Sourcepub fn try_map<B, E, F>(self, f: F) -> Result<Expr<B>, E>
pub fn try_map<B, E, F>(self, f: F) -> Result<Expr<B>, E>
Apply f to every atom in the tree in canonical
left-to-right order, returning a new expression whose
atoms are of type B. The traversal is fail-fast: the
first error returned by f short-circuits the rest.
§Errors
Returns the first E produced by f. Subsequent atoms
are not visited; consumers that want to accumulate every
atom-level error MUST layer their own collection on top.
Sourcepub fn eval<F>(&self, f: F) -> bool
pub fn eval<F>(&self, f: F) -> bool
Evaluate the expression by applying f to each atom and
folding the results under the boolean operators of
QRY-002.
Short-circuits in the standard way: And stops at the
first false, Or stops at the first true.
Sourcepub fn try_eval<F, E>(&self, f: F) -> Result<bool, E>
pub fn try_eval<F, E>(&self, f: F) -> Result<bool, E>
Evaluate the expression by applying a fallible predicate
f to each atom.
Short-circuits in two ways: an Err propagates
immediately, and And / Or stop as soon as the result
is determined. Atoms past the short-circuit point are not
visited and their predicates are not invoked.
§Errors
Returns the first E produced by f.