From 98de15c07d8e8e0b67e6b7f7863a68f5f035859c Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 19 Nov 2018 21:38:39 -0800 Subject: [PATCH] Move stuff around --- schala-lang/language/src/ast_visitor.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/schala-lang/language/src/ast_visitor.rs b/schala-lang/language/src/ast_visitor.rs index ebf9d76..0bc5445 100644 --- a/schala-lang/language/src/ast_visitor.rs +++ b/schala-lang/language/src/ast_visitor.rs @@ -11,15 +11,7 @@ pub fn dispatch(visitor: &mut V, ast: &AST) { visitor.expression(e); }, Statement::Declaration(decl) => { - match decl { - Declaration::FuncSig(sig) => visitor.func_signature(sig), - Declaration::FuncDecl(sig, block) => visitor.func_declaration(sig, block), - Declaration::TypeDecl { name, body, mutable } => visitor.type_declaration(name, body, mutable), - Declaration::TypeAlias(alias, name) => visitor.type_alias(alias, name), - Declaration::Binding { name, constant, expr} => visitor.binding(name, constant, expr), - Declaration::Impl { type_name, interface_name, block } => visitor.impl_block(type_name, interface_name, block), - Declaration::Interface { name, signatures } => visitor.interface(name, signatures), - } + dispatch_declaration(visitor, decl); visitor.declaration(decl); }, }; @@ -55,6 +47,17 @@ fn dispatch_expression(visitor: &mut V, expression: &Expression) } } +fn dispatch_declaration(visitor: &mut V, declaration: &Declaration) { + match declaration { + Declaration::FuncSig(sig) => visitor.func_signature(sig), + Declaration::FuncDecl(sig, block) => visitor.func_declaration(sig, block), + Declaration::TypeDecl { name, body, mutable } => visitor.type_declaration(name, body, mutable), + Declaration::TypeAlias(alias, name) => visitor.type_alias(alias, name), + Declaration::Binding { name, constant, expr} => visitor.binding(name, constant, expr), + Declaration::Impl { type_name, interface_name, block } => visitor.impl_block(type_name, interface_name, block), + Declaration::Interface { name, signatures } => visitor.interface(name, signatures), + } +} pub trait ASTVisitor { fn ast(&mut self, _ast: &AST) { } @@ -117,7 +120,7 @@ impl ASTVisitor for SchalaPrinter { self.s.push_str("some_expr"); } - fn binding(&mut self, name: &Rc, constant: &bool, _expr: &Expression) { + fn binding(&mut self, name: &Rc, constant: &bool, _expr: &Expression) { self.s.push_str(&format!("let{} {} = {}", if *constant { "" } else { " mut" }, name,