pub enum GenericExpr<Head, Leaf> {
Var(Span, Leaf),
Call(Span, Head, Vec<GenericExpr<Head, Leaf>>),
Lit(Span, Literal),
}Variants§
Implementations§
Source§impl<Head, Leaf> GenericExpr<Head, Leaf>
impl<Head, Leaf> GenericExpr<Head, Leaf>
pub fn visit_vars(&self, f: &mut impl FnMut(&Span, &Leaf))
pub fn span(&self) -> Span
pub fn is_var(&self) -> bool
pub fn get_var(&self) -> Option<Leaf>
pub fn ast_size(&self) -> usize
Sourcepub fn walk(
&self,
pre: &mut impl FnMut(&GenericExpr<Head, Leaf>),
post: &mut impl FnMut(&GenericExpr<Head, Leaf>),
)
pub fn walk( &self, pre: &mut impl FnMut(&GenericExpr<Head, Leaf>), post: &mut impl FnMut(&GenericExpr<Head, Leaf>), )
Traverse the expression tree, calling pre before visiting children
and post after visiting children. Visits all nodes in the tree.
Sourcepub fn fold<Out>(
&self,
f: &mut impl FnMut(&GenericExpr<Head, Leaf>, Vec<Out>) -> Out,
) -> Out
pub fn fold<Out>( &self, f: &mut impl FnMut(&GenericExpr<Head, Leaf>, Vec<Out>) -> Out, ) -> Out
Fold over the expression tree bottom-up, collecting results from children.
The function f is called on each node with the node itself and the results
from folding over its children. Results are computed from leaves to root.
Sourcepub fn find<Out>(
&self,
f: &mut impl FnMut(&GenericExpr<Head, Leaf>) -> Option<Out>,
) -> Option<Out>
pub fn find<Out>( &self, f: &mut impl FnMut(&GenericExpr<Head, Leaf>) -> Option<Out>, ) -> Option<Out>
Search for the first node matching a predicate, returning early once found. Traverses the tree in pre-order (top-down).
Sourcepub fn visit_exprs(
self,
f: &mut impl FnMut(GenericExpr<Head, Leaf>) -> GenericExpr<Head, Leaf>,
) -> GenericExpr<Head, Leaf>
pub fn visit_exprs( self, f: &mut impl FnMut(GenericExpr<Head, Leaf>) -> GenericExpr<Head, Leaf>, ) -> GenericExpr<Head, Leaf>
Applys f to all sub-expressions (including self)
bottom-up, collecting the results.
Sourcepub fn subst<Head2, Leaf2>(
&self,
subst_leaf: &mut impl FnMut(&Span, &Leaf) -> GenericExpr<Head2, Leaf2>,
subst_head: &mut impl FnMut(&Head) -> Head2,
) -> GenericExpr<Head2, Leaf2>
pub fn subst<Head2, Leaf2>( &self, subst_leaf: &mut impl FnMut(&Span, &Leaf) -> GenericExpr<Head2, Leaf2>, subst_head: &mut impl FnMut(&Head) -> Head2, ) -> GenericExpr<Head2, Leaf2>
subst replaces occurrences of variables and head symbols in the expression.
pub fn subst_leaf<Leaf2>( &self, subst_leaf: &mut impl FnMut(&Span, &Leaf) -> GenericExpr<Head, Leaf2>, ) -> GenericExpr<Head, Leaf2>
Sourcepub fn map_symbols<Head2, Leaf2>(
self,
head: &mut impl FnMut(Head) -> Head2,
leaf: &mut impl FnMut(Leaf) -> Leaf2,
) -> GenericExpr<Head2, Leaf2>
pub fn map_symbols<Head2, Leaf2>( self, head: &mut impl FnMut(Head) -> Head2, leaf: &mut impl FnMut(Leaf) -> Leaf2, ) -> GenericExpr<Head2, Leaf2>
Applies the provided head and leaf mappings to every symbol within the expression.
Sourcepub fn make_unresolved(self) -> GenericExpr<String, String>
pub fn make_unresolved(self) -> GenericExpr<String, String>
Converts all heads and leaves to strings.
pub fn vars(&self) -> impl Iterator<Item = Leaf>
Trait Implementations§
Source§impl<Head, Leaf> Clone for GenericExpr<Head, Leaf>
impl<Head, Leaf> Clone for GenericExpr<Head, Leaf>
Source§fn clone(&self) -> GenericExpr<Head, Leaf>
fn clone(&self) -> GenericExpr<Head, Leaf>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Head, Leaf> Debug for GenericExpr<Head, Leaf>
impl<Head, Leaf> Debug for GenericExpr<Head, Leaf>
Source§impl<Head, Leaf> Display for GenericExpr<Head, Leaf>
impl<Head, Leaf> Display for GenericExpr<Head, Leaf>
Source§impl<Head, Leaf> Hash for GenericExpr<Head, Leaf>
impl<Head, Leaf> Hash for GenericExpr<Head, Leaf>
Source§impl<Head, Leaf> PartialEq for GenericExpr<Head, Leaf>
impl<Head, Leaf> PartialEq for GenericExpr<Head, Leaf>
impl<Head, Leaf> Eq for GenericExpr<Head, Leaf>
impl<Head, Leaf> StructuralPartialEq for GenericExpr<Head, Leaf>
Auto Trait Implementations§
impl<Head, Leaf> Freeze for GenericExpr<Head, Leaf>
impl<Head, Leaf> RefUnwindSafe for GenericExpr<Head, Leaf>where
Leaf: RefUnwindSafe,
Head: RefUnwindSafe,
impl<Head, Leaf> Send for GenericExpr<Head, Leaf>
impl<Head, Leaf> Sync for GenericExpr<Head, Leaf>
impl<Head, Leaf> Unpin for GenericExpr<Head, Leaf>
impl<Head, Leaf> UnwindSafe for GenericExpr<Head, Leaf>where
Leaf: UnwindSafe,
Head: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more