2019-09-26 02:29:20 -07:00
|
|
|
use std::rc::Rc;
|
2019-09-25 18:41:07 -07:00
|
|
|
use std::error::Error;
|
|
|
|
use crate::ast::*;
|
2019-09-26 02:29:20 -07:00
|
|
|
use crate::ast::walker;
|
2019-09-25 18:41:07 -07:00
|
|
|
|
2019-09-26 02:29:20 -07:00
|
|
|
//TODO maybe these functions should take closures that return a KeepRecursing | StopHere type,
|
|
|
|
//or a tuple of (T, <that type>)
|
2019-09-25 18:41:07 -07:00
|
|
|
|
2019-09-26 02:29:20 -07:00
|
|
|
//TODO default implmentations should call walk methods - then I can test printing
|
|
|
|
pub trait ASTVisitor: Sized {
|
|
|
|
fn visit(&mut self, ast: &AST) {
|
|
|
|
println!("FUCK");
|
|
|
|
walker::ast(self, ast);
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn block(&mut self, statements: &Vec<Statement>) {
|
2019-09-26 02:29:20 -07:00
|
|
|
println!("oi");
|
|
|
|
walker::block(self, statements);
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn statement(&mut self, statement: &Statement) {
|
2019-09-26 02:29:20 -07:00
|
|
|
println!("stmt");
|
|
|
|
walker::statement(self, statement);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn declaration(&mut self, declaration: &Declaration) {
|
|
|
|
walker::declaration(self, declaration);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&mut self, signature: &Signature) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn binding(&mut self, name: &Rc<String>, constant: bool, type_anno: Option<&TypeIdentifier>, expr: &Expression) {
|
|
|
|
walker::maybe_type_identifier(self, type_anno);
|
|
|
|
walker::expression(self, expr);
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn expression(&mut self, expression: &Expression) {
|
2019-09-26 02:29:20 -07:00
|
|
|
println!("expr yo");
|
|
|
|
walker::expression(self, expression);
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
|
|
|
|
2019-09-26 02:29:20 -07:00
|
|
|
fn expression_kind(&mut self, kind: &ExpressionKind) {
|
|
|
|
walker::expression_kind(self, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn maybe_type_identifier(&mut self, type_anno: Option<&TypeIdentifier>) {
|
|
|
|
walker::maybe_type_identifier(self, type_anno);
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
|
|
|
|
2019-09-26 03:26:14 -07:00
|
|
|
fn named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc<String>, Expression)>) {
|
|
|
|
self.qualified_name(name);
|
|
|
|
for (_, expr) in fields.iter() {
|
|
|
|
walker::expression(self, expr);
|
|
|
|
}
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
2019-09-26 02:29:20 -07:00
|
|
|
|
2019-09-26 03:26:14 -07:00
|
|
|
fn import(&mut self, import: &ImportSpecifier) {}
|
|
|
|
fn qualified_name(&mut self, name: &QualifiedName) {}
|
2019-09-26 02:29:20 -07:00
|
|
|
fn nat_literal(&mut self, n: u64) {}
|
|
|
|
fn float_literal(&mut self, f: f64) {}
|
|
|
|
fn string_literal(&mut self, s: &Rc<String>) {}
|
|
|
|
fn bool_literal(&mut self, b: bool) {}
|
|
|
|
fn binexp(&mut self, op: &BinOp, lhs: &Expression, rhs: &Expression) {
|
|
|
|
walker::expression(self, lhs);
|
|
|
|
walker::expression(self, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn prefix_exp(&mut self, op: &PrefixOp, arg: &Expression) {
|
|
|
|
walker::expression(self, arg);
|
|
|
|
}
|
2019-09-25 18:41:07 -07:00
|
|
|
}
|
2019-09-26 02:29:20 -07:00
|
|
|
|
|
|
|
|