Move stuff around

This commit is contained in:
greg 2018-11-19 21:38:39 -08:00
parent 0246e510ca
commit 98de15c07d

View File

@ -11,15 +11,7 @@ pub fn dispatch<V: ASTVisitor>(visitor: &mut V, ast: &AST) {
visitor.expression(e); visitor.expression(e);
}, },
Statement::Declaration(decl) => { Statement::Declaration(decl) => {
match decl { dispatch_declaration(visitor, 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),
}
visitor.declaration(decl); visitor.declaration(decl);
}, },
}; };
@ -55,6 +47,17 @@ fn dispatch_expression<V: ASTVisitor>(visitor: &mut V, expression: &Expression)
} }
} }
fn dispatch_declaration<V: ASTVisitor>(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 { pub trait ASTVisitor {
fn ast(&mut self, _ast: &AST) { } fn ast(&mut self, _ast: &AST) { }
@ -117,7 +120,7 @@ impl ASTVisitor for SchalaPrinter {
self.s.push_str("some_expr"); self.s.push_str("some_expr");
} }
fn binding(&mut self, name: &Rc<String>, constant: &bool, _expr: &Expression) { fn binding(&mut self, name: &Rc<String>, constant: &bool, _expr: &Expression) {
self.s.push_str(&format!("let{} {} = {}", self.s.push_str(&format!("let{} {} = {}",
if *constant { "" } else { " mut" }, if *constant { "" } else { " mut" },
name, name,