Skip to content

Commit

Permalink
feat: add Expr::traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Nov 5, 2024
1 parent 03613bc commit f22afbe
Show file tree
Hide file tree
Showing 2 changed files with 456 additions and 2 deletions.
19 changes: 19 additions & 0 deletions crates/erg_common/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,3 +1413,22 @@ impl<T: Immutable, U: Immutable, V: Immutable> Immutable for (T, U, V) {}
impl<T: Immutable + ?Sized> Immutable for Box<T> {}
impl<T: Immutable + ?Sized> Immutable for std::rc::Rc<T> {}
impl<T: Immutable + ?Sized> Immutable for std::sync::Arc<T> {}

pub trait Traversable {
type Target;
fn traverse(&self, rec_f: &mut impl FnMut(&Self::Target));
}

#[macro_export]
macro_rules! impl_traversable_for_enum {
($Enum: ident; $Target: ty; $($Variant: ident $(,)?)*) => {
impl Traversable for $Enum {
type Target = $Target;
fn traverse(&self, rec_f: &mut impl FnMut(&Self::Target)) {
match self {
$($Enum::$Variant(v) => v.traverse(rec_f),)*
}
}
}
}
}
Loading

0 comments on commit f22afbe

Please sign in to comment.