From c42b63e016b26d41f5fee03e20cf26f16c2b443c Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 3 Sep 2020 18:47:48 -0700 Subject: [PATCH] Add Body AST item and visit_body in visitor Signed-off-by: Alek Ratzloff --- src/lib.rs | 1 + src/syn/ast.rs | 24 ++++++++++++++++++++++++ src/syn/visit.rs | 1 + 3 files changed, 26 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0afca50..e2828da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod syn; +pub mod compile; pub use runtime; diff --git a/src/syn/ast.rs b/src/syn/ast.rs index adbce92..dd5ab5b 100644 --- a/src/syn/ast.rs +++ b/src/syn/ast.rs @@ -1,5 +1,29 @@ use crate::syn::visit::*; +// TODO : add locations to parsed items + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Body { + pub body: Vec, +} + +// +// impl Accept for Body +// +impl Accept for Body { + fn accept(&self, visitor: &mut V) -> V::Out { + visitor.visit_body(self) + } +} + +impl> DefaultAccept for Body { + fn default_accept(&self, visitor: &mut V) -> V::Out { + self.body + .iter() + .for_each(|stmt| visitor.visit_stmt(stmt)); + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum Stmt { Expr(Expr), diff --git a/src/syn/visit.rs b/src/syn/visit.rs index e32eafe..86ee183 100644 --- a/src/syn/visit.rs +++ b/src/syn/visit.rs @@ -11,6 +11,7 @@ pub trait DefaultAccept { pub trait Visit { type Out; + fn visit_body(&mut self, body: &Body) -> Self::Out; fn visit_stmt(&mut self, stmt: &Stmt) -> Self::Out; fn visit_assign_stmt(&mut self, assign: &AssignStmt) -> Self::Out; fn visit_lhs_expr(&mut self, lhs_expr: &LhsExpr) -> Self::Out;