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, body: TypeBody,
mutable: bool 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 { Binding {
name: Rc<String>, name: Rc<String>,
constant: bool, constant: bool,

View File

@ -28,6 +28,13 @@ pub trait ASTVisitor: Sized {
} }
fn signature(&mut self, signature: &Signature) { 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) { 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); 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) { fn expression(&mut self, expression: &Expression) {
println!("expr yo");
walker::expression(self, expression); walker::expression(self, expression);
} }

View File

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

View File

@ -32,26 +32,25 @@ pub fn declaration<V: ASTVisitor>(v: &mut V, decl: &Declaration) {
v.signature(&sig); v.signature(&sig);
v.block(&block); v.block(&block);
}, },
TypeDecl { .. } => unimplemented!(), TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable),
TypeAlias(_, _) => unimplemented!(), TypeAlias(n, a) => v.type_alias(n, a),
Binding { name, constant, type_anno, expr } => { Binding { name, constant, type_anno, expr } => {
v.binding(name, *constant, type_anno.as_ref(), expr); v.binding(name, *constant, type_anno.as_ref(), expr);
}, },
/* Impl { type_name, interface_name, block } => {
Impl { v.implemention(type_name, interface_name.as_ref(), block);
type_name: TypeIdentifier,
interface_name: Option<TypeSingletonName>,
block: Vec<Declaration>,
},
Interface {
name: Rc<String>,
signatures: Vec<Signature>
} }
*/ 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) { pub fn expression<V: ASTVisitor>(v: &mut V, expression: &Expression) {
v.expression_kind(&expression.kind); v.expression_kind(&expression.kind);
v.maybe_type_identifier(expression.type_anno.as_ref()); v.maybe_type_identifier(expression.type_anno.as_ref());