From c427646e75f1ae327f6c3c7f1ebaf6354d0a8704 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 28 Sep 2019 02:42:18 -0700 Subject: [PATCH] Change type alias --- schala-lang/language/src/ast.rs | 6 +++++- schala-lang/language/src/ast/visitor.rs | 2 +- schala-lang/language/src/ast/walker.rs | 2 +- schala-lang/language/src/parsing.rs | 2 +- schala-lang/language/src/parsing/test.rs | 2 +- schala-lang/language/src/reduced_ast.rs | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index c181327..7f03fad 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -92,7 +92,11 @@ pub enum Declaration { body: TypeBody, mutable: bool }, - TypeAlias(Rc, Rc), //TODO should have TypeSingletonName in it, or maybe just String, not sure + //TODO this needs to be more sophisticated + TypeAlias { + alias: Rc, + original: Rc, + }, Binding { name: Rc, constant: bool, diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index 2e8692e..9a1558d 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -11,7 +11,7 @@ pub trait ASTVisitor: Sized { fn declaration(&mut self, _declaration: &Declaration) {} fn signature(&mut self, _signature: &Signature) {} fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: bool) {} - fn type_alias(&mut self, _old_name: &Rc, _new_name: &Rc) {} + fn type_alias(&mut self, _alias: &Rc, _original: &Rc) {} fn binding(&mut self, _name: &Rc, _constant: bool, _type_anno: Option<&TypeIdentifier>, _expr: &Expression) {} fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &Vec) {} fn interface(&mut self, _name: &Rc, _signatures: &Vec) {} diff --git a/schala-lang/language/src/ast/walker.rs b/schala-lang/language/src/ast/walker.rs index 9d8fe20..ea8782b 100644 --- a/schala-lang/language/src/ast/walker.rs +++ b/schala-lang/language/src/ast/walker.rs @@ -44,7 +44,7 @@ fn declaration(v: &mut V, decl: &Declaration) { walk_block(v, block); }, TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable), - TypeAlias(n, a) => v.type_alias(n, a), + TypeAlias { alias, original} => v.type_alias(alias, original), Binding { name, constant, type_anno, expr } => { v.binding(name, *constant, type_anno.as_ref(), expr); v.type_annotation(type_anno.as_ref()); diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 4a4f5d7..280ec53 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -388,7 +388,7 @@ impl Parser { let alias = self.identifier()?; expect!(self, Equals); let original = self.identifier()?; - Ok(Declaration::TypeAlias(alias, original)) + Ok(Declaration::TypeAlias { alias, original }) } #[recursive_descent_method] diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 8e9312c..fcfadfe 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -298,7 +298,7 @@ fn parsing_strings() { fn parsing_types() { parse_test_wrap_ast!("type Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: false} )); parse_test_wrap_ast!("type mut Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: true} )); - parse_test_wrap_ast!("type alias Sex = Drugs", decl!(TypeAlias(rc!(Sex), rc!(Drugs)))); + parse_test_wrap_ast!("type alias Sex = Drugs", decl!(TypeAlias { alias: rc!(Sex), original: rc!(Drugs) })); parse_test_wrap_ast!("type Sanchez = Miguel | Alejandro(Int, Option) | Esperanza { a: Int, b: String }", decl!(TypeDecl { name: tys!("Sanchez"), diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 08ee499..7e3b6c5 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -334,7 +334,7 @@ impl<'a> Reducer<'a> { } }, TypeDecl { .. } => Stmt::Noop, - TypeAlias(_, _) => Stmt::Noop, + TypeAlias{ .. } => Stmt::Noop, Interface { .. } => Stmt::Noop, Impl { .. } => Stmt::Expr(Expr::UnimplementedSigilValue), _ => Stmt::Expr(Expr::UnimplementedSigilValue)