Add Body AST item and visit_body in visitor
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
pub mod syn;
|
pub mod syn;
|
||||||
|
pub mod compile;
|
||||||
|
|
||||||
pub use runtime;
|
pub use runtime;
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
use crate::syn::visit::*;
|
use crate::syn::visit::*;
|
||||||
|
|
||||||
|
// TODO : add locations to parsed items
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct Body {
|
||||||
|
pub body: Vec<Stmt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// impl Accept for Body
|
||||||
|
//
|
||||||
|
impl<V: Visit> Accept<V> for Body {
|
||||||
|
fn accept(&self, visitor: &mut V) -> V::Out {
|
||||||
|
visitor.visit_body(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V: Visit<Out=()>> DefaultAccept<V> 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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum Stmt {
|
pub enum Stmt {
|
||||||
Expr(Expr),
|
Expr(Expr),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ pub trait DefaultAccept<V: Visit + ?Sized> {
|
|||||||
pub trait Visit {
|
pub trait Visit {
|
||||||
type Out;
|
type Out;
|
||||||
|
|
||||||
|
fn visit_body(&mut self, body: &Body) -> Self::Out;
|
||||||
fn visit_stmt(&mut self, stmt: &Stmt) -> Self::Out;
|
fn visit_stmt(&mut self, stmt: &Stmt) -> Self::Out;
|
||||||
fn visit_assign_stmt(&mut self, assign: &AssignStmt) -> Self::Out;
|
fn visit_assign_stmt(&mut self, assign: &AssignStmt) -> Self::Out;
|
||||||
fn visit_lhs_expr(&mut self, lhs_expr: &LhsExpr) -> Self::Out;
|
fn visit_lhs_expr(&mut self, lhs_expr: &LhsExpr) -> Self::Out;
|
||||||
|
|||||||
Reference in New Issue
Block a user