From 39bb1757222dafad6126b893db5c0e9f6fa08861 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 25 Sep 2019 18:41:07 -0700 Subject: [PATCH] Initial WIP code --- schala-lang/language/src/ast.rs | 1 + schala-lang/language/src/ast/visitor.rs | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 schala-lang/language/src/ast/visitor.rs diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index c6d11aa..918ca72 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -2,6 +2,7 @@ use std::rc::Rc; use crate::derivative::Derivative; +mod visitor; mod operators; pub use operators::*; diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs new file mode 100644 index 0000000..0fdd0a8 --- /dev/null +++ b/schala-lang/language/src/ast/visitor.rs @@ -0,0 +1,33 @@ +use std::error::Error; +use crate::ast::*; + + +pub trait ASTVisitor { + fn visit(&mut self, ast: &mut AST) { + self.block(&ast.statements); + } + + fn block(&mut self, statements: &Vec) { + for statement in statements { + self.statement(statement); + } + } + + fn statement(&mut self, statement: &Statement) { + use StatementKind::*; + match statement.kind { + Expression(ref expr) => self.expression(expr), + Declaration(ref decl) => self.declaration(decl), + Import(ref import_spec) => self.import(import_spec), + } + } + + fn expression(&mut self, expression: &Expression) { + } + + fn declaration(&mut self, declaration: &Declaration) { + } + + fn import(&mut self, import: &ImportSpecifier) { + } +}