Change type alias

This commit is contained in:
greg 2019-09-28 02:42:18 -07:00
parent f06b5922de
commit c427646e75
6 changed files with 10 additions and 6 deletions

View File

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

View File

@ -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<String>, _new_name: &Rc<String>) {}
fn type_alias(&mut self, _alias: &Rc<String>, _original: &Rc<String>) {}
fn binding(&mut self, _name: &Rc<String>, _constant: bool, _type_anno: Option<&TypeIdentifier>, _expr: &Expression) {}
fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &Vec<Declaration>) {}
fn interface(&mut self, _name: &Rc<String>, _signatures: &Vec<Signature>) {}

View File

@ -44,7 +44,7 @@ fn declaration<V: ASTVisitor>(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());

View File

@ -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]

View File

@ -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<a>) | Esperanza { a: Int, b: String }",
decl!(TypeDecl {
name: tys!("Sanchez"),

View File

@ -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)