diff options
author | Griffin Smith <root@gws.fyi> | 2021-03-13T18·12-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2021-03-13T18·12-0500 |
commit | f8beda81fbe8d04883aee71ff4ea078f897c6de4 (patch) | |
tree | ad61046d7e86c8a71381ee6b936fcd46ec3a89ac /src/ast/mod.rs | |
parent | 3dff189499af1ddd60d8fc128b794d15f1cb19ae (diff) |
Allow exprs+bindings to optionally be ascripted
Diffstat (limited to 'src/ast/mod.rs')
-rw-r--r-- | src/ast/mod.rs | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 7f3543271db8..dc22ac3cdb56 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -110,6 +110,23 @@ pub enum Literal { } #[derive(Debug, PartialEq, Eq, Clone)] +pub struct Binding<'a> { + pub ident: Ident<'a>, + pub type_: Option<Type>, + pub body: Expr<'a>, +} + +impl<'a> Binding<'a> { + fn to_owned(&self) -> Binding<'static> { + Binding { + ident: self.ident.to_owned(), + type_: self.type_.clone(), + body: self.body.to_owned(), + } + } +} + +#[derive(Debug, PartialEq, Eq, Clone)] pub enum Expr<'a> { Ident(Ident<'a>), @@ -127,7 +144,7 @@ pub enum Expr<'a> { }, Let { - bindings: Vec<(Ident<'a>, Expr<'a>)>, + bindings: Vec<Binding<'a>>, body: Box<Expr<'a>>, }, @@ -143,6 +160,11 @@ pub enum Expr<'a> { fun: Box<Expr<'a>>, args: Vec<Expr<'a>>, }, + + Ascription { + expr: Box<Expr<'a>>, + type_: Type, + }, } impl<'a> Expr<'a> { @@ -160,10 +182,7 @@ impl<'a> Expr<'a> { rhs: Box::new((**rhs).to_owned()), }, Expr::Let { bindings, body } => Expr::Let { - bindings: bindings - .iter() - .map(|(id, expr)| (id.to_owned(), expr.to_owned())) - .collect(), + bindings: bindings.iter().map(|binding| binding.to_owned()).collect(), body: Box::new((**body).to_owned()), }, Expr::If { @@ -180,6 +199,10 @@ impl<'a> Expr<'a> { fun: Box::new((**fun).to_owned()), args: args.iter().map(|arg| arg.to_owned()).collect(), }, + Expr::Ascription { expr, type_ } => Expr::Ascription { + expr: Box::new((**expr).to_owned()), + type_: type_.clone(), + }, } } } |