From 89649273d8e2bf4a454eb2d0071723071ae717a8 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 27 Sep 2019 22:34:00 -0700 Subject: [PATCH] Still more visitor stuff --- schala-lang/language/src/ast.rs | 2 +- schala-lang/language/src/ast/visitor.rs | 14 ++++++++++- schala-lang/language/src/ast/visitor_test.rs | 1 + schala-lang/language/src/ast/walker.rs | 25 ++++++++++---------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index 5dbf79a..c181327 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -92,7 +92,7 @@ pub enum Declaration { body: TypeBody, mutable: bool }, - TypeAlias(Rc, Rc), //should have TypeSingletonName in it, or maybe just String, not sure + TypeAlias(Rc, Rc), //TODO should have TypeSingletonName in it, or maybe just String, not sure Binding { name: Rc, constant: bool, diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index 1abd227..a0a1bf7 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -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, new_name: &Rc) { } fn binding(&mut self, name: &Rc, 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) { + } + + fn interface(&mut self, name: &Rc, signatures: &Vec) { + } + fn expression(&mut self, expression: &Expression) { - println!("expr yo"); walker::expression(self, expression); } diff --git a/schala-lang/language/src/ast/visitor_test.rs b/schala-lang/language/src/ast/visitor_test.rs index bda48ad..ed33edf 100644 --- a/schala-lang/language/src/ast/visitor_test.rs +++ b/schala-lang/language/src/ast/visitor_test.rs @@ -27,6 +27,7 @@ import gragh let a = 20 + 84 let b = 28 + 1 + 2 + 2.0 + "#); tester.visit(&ast); diff --git a/schala-lang/language/src/ast/walker.rs b/schala-lang/language/src/ast/walker.rs index edf27a5..e884a7d 100644 --- a/schala-lang/language/src/ast/walker.rs +++ b/schala-lang/language/src/ast/walker.rs @@ -32,24 +32,23 @@ pub fn declaration(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, - block: Vec, - }, - Interface { - name: Rc, - signatures: Vec + 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: &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: &mut V, expression: &Expression) {