2019-07-11 23:58:03 -07:00

30 lines
559 B
Rust

use std::error::Error;
use crate::ast::*;
pub type VResult = Result<(), Box<dyn Error>>;
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(())
}
}