Starting to implement ASTVisitor
This commit is contained in:
parent
d043036c61
commit
a187d43fc1
@ -19,6 +19,10 @@ impl<T> Meta<T> {
|
||||
pub fn node(&self) -> &T {
|
||||
&self.n
|
||||
}
|
||||
|
||||
pub fn node_mut(&mut self) -> &mut T {
|
||||
&mut self.n
|
||||
}
|
||||
}
|
||||
|
||||
//TODO this PartialEq is here to make tests work - find a way to make it not necessary
|
||||
|
@ -1,7 +1,29 @@
|
||||
use std::error::Error;
|
||||
use crate::ast::*;
|
||||
|
||||
pub type VResult<T> = Result<T, Box<dyn Error>>;
|
||||
|
||||
pub trait Visitor {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user