use std::error::Error; use crate::ast::*; pub type VResult = Result<(), Box>; pub trait ASTVisitor { fn visit_expression(&mut self, _: &mut Expression) -> VResult { Ok(()) } } pub trait Visitable { fn visit(&mut self, v: &mut dyn ASTVisitor) -> VResult; } impl Visitable for AST { fn visit(&mut self, v: &mut dyn ASTVisitor) -> VResult { for s in self.0.iter_mut() { s.node_mut().visit(v)? } Ok(()) } } impl Visitable for Statement { fn visit(&mut self, _v: &mut dyn ASTVisitor) -> VResult { Ok(()) } }