Still more visitor stuff

This commit is contained in:
greg 2019-09-27 22:34:00 -07:00
parent 9fa4e3797c
commit 89649273d8
4 changed files with 27 additions and 15 deletions

View File

@ -92,7 +92,7 @@ pub enum Declaration {
body: TypeBody,
mutable: bool
},
TypeAlias(Rc<String>, Rc<String>), //should have TypeSingletonName in it, or maybe just String, not sure
TypeAlias(Rc<String>, Rc<String>), //TODO should have TypeSingletonName in it, or maybe just String, not sure
Binding {
name: Rc<String>,
constant: bool,

View File

@ -28,6 +28,13 @@ pub trait ASTVisitor: Sized {
}
fn signature(&mut self, signature: &Signature) {
walker::signature(self, signature);
}
fn type_declaration(&mut self, name: &TypeSingletonName, body: &TypeBody, mutable: bool) {
}
fn type_alias(&mut self, old_name: &Rc<String>, new_name: &Rc<String>) {
}
fn binding(&mut self, name: &Rc<String>, constant: bool, type_anno: Option<&TypeIdentifier>, expr: &Expression) {
@ -35,8 +42,13 @@ pub trait ASTVisitor: Sized {
walker::expression(self, expr);
}
fn implemention(&mut self, type_name: &TypeIdentifier, interface_name: Option<&TypeSingletonName>, block: &Vec<Declaration>) {
}
fn interface(&mut self, name: &Rc<String>, signatures: &Vec<Signature>) {
}
fn expression(&mut self, expression: &Expression) {
println!("expr yo");
walker::expression(self, expression);
}

View File

@ -27,6 +27,7 @@ import gragh
let a = 20 + 84
let b = 28 + 1 + 2 + 2.0
"#);
tester.visit(&ast);

View File

@ -32,24 +32,23 @@ pub fn declaration<V: ASTVisitor>(v: &mut V, decl: &Declaration) {
v.signature(&sig);
v.block(&block);
},
TypeDecl { .. } => unimplemented!(),
TypeAlias(_, _) => unimplemented!(),
TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable),
TypeAlias(n, a) => v.type_alias(n, a),
Binding { name, constant, type_anno, expr } => {
v.binding(name, *constant, type_anno.as_ref(), expr);
},
/*
Impl {
type_name: TypeIdentifier,
interface_name: Option<TypeSingletonName>,
block: Vec<Declaration>,
},
Interface {
name: Rc<String>,
signatures: Vec<Signature>
Impl { type_name, interface_name, block } => {
v.implemention(type_name, interface_name.as_ref(), block);
}
Interface { name, signatures } => v.interface(name, signatures),
}
*/
_ => (),
}
pub fn signature<V: ASTVisitor>(v: &mut V, signature: &Signature) {
for p in signature.params.iter() {
v.formal_param(p);
}
v.maybe_type_identifier(signature.type_anno.as_ref());
}
pub fn expression<V: ASTVisitor>(v: &mut V, expression: &Expression) {