diff options
-rw-r--r-- | dhall/src/typecheck.rs | 2 | ||||
-rw-r--r-- | dhall_core/src/core.rs | 12 | ||||
-rw-r--r-- | dhall_core/src/lib.rs | 2 | ||||
-rw-r--r-- | dhall_generator/src/lib.rs | 43 | ||||
-rw-r--r-- | dhall_normalize/src/normalize.rs | 12 |
5 files changed, 44 insertions, 27 deletions
diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index aa8aa08..8cab0ac 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -10,7 +10,7 @@ use dhall_core::core::Const::*; use dhall_core::core::Expr::*; use dhall_core::core::{app, pi}; use dhall_core::core::{bx, shift, subst, Expr, V, X}; -use dhall_normalize::{normalize}; +use dhall_normalize::normalize; use self::TypeMessage::*; diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 675345e..fcb7713 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -231,7 +231,11 @@ impl<'i, S, A> From<Builtin> for Expr<'i, S, A> { } impl<'i, S, A> Expr<'i, S, A> { - pub fn map_shallow<T, F1, F2>(&self, map_expr: F1, map_note: F2) -> Expr<'i, T, A> + pub fn map_shallow<T, F1, F2>( + &self, + map_expr: F1, + map_note: F2, + ) -> Expr<'i, T, A> where A: Clone, T: Clone, @@ -639,7 +643,11 @@ fn add_ui(u: usize, i: isize) -> usize { } } -pub fn map_shallow<'i, S, T, A, F1, F2>(e: &Expr<'i, S, A>, map: F1, map_note: F2) -> Expr<'i, T, A> +pub fn map_shallow<'i, S, T, A, F1, F2>( + e: &Expr<'i, S, A>, + map: F1, + map_note: F2, +) -> Expr<'i, T, A> where A: Clone, S: Clone, diff --git a/dhall_core/src/lib.rs b/dhall_core/src/lib.rs index dbdd08c..76f436d 100644 --- a/dhall_core/src/lib.rs +++ b/dhall_core/src/lib.rs @@ -5,7 +5,7 @@ pub mod core; pub use crate::core::*; use lalrpop_util::lalrpop_mod; lalrpop_mod!(pub grammar); +pub mod context; mod grammar_util; pub mod lexer; pub mod parser; -pub mod context; diff --git a/dhall_generator/src/lib.rs b/dhall_generator/src/lib.rs index d0d8d98..066db2e 100644 --- a/dhall_generator/src/lib.rs +++ b/dhall_generator/src/lib.rs @@ -1,8 +1,8 @@ extern crate proc_macro; -use proc_macro2::TokenStream; +use dhall_core::*; use proc_macro2::Literal; +use proc_macro2::TokenStream; use quote::quote; -use dhall_core::*; #[proc_macro] pub fn dhall(input: proc_macro::TokenStream) -> proc_macro::TokenStream { @@ -19,41 +19,43 @@ fn dhall_to_tokenstream(expr: &Expr<X, X>) -> TokenStream { match expr { Var(V(s, _)) => { let v: TokenStream = s.parse().unwrap(); - quote!{ { + quote! { { let x: Expr<_, _> = (*#v).clone(); x } } - }, + } Lam(x, ref t, ref b) => { let x = Literal::string(x); let t = dhall_to_tokenstream_bx(t); let b = dhall_to_tokenstream_bx(b); - quote!{ Lam(#x, #t, #b) } + quote! { Lam(#x, #t, #b) } } App(ref f, ref a) => { let f = dhall_to_tokenstream_bx(f); let a = dhall_to_tokenstream_bx(a); - quote!{ App(#f, #a) } + quote! { App(#f, #a) } } Builtin(ref b) => { let b = builtin_to_tokenstream(b); - quote!{ Builtin(#b) } - }, + quote! { Builtin(#b) } + } BinOp(ref o, ref a, ref b) => { let o = binop_to_tokenstream(o); let a = dhall_to_tokenstream_bx(a); let b = dhall_to_tokenstream_bx(b); - quote!{ BinOp(#o, #a, #b) } + quote! { BinOp(#o, #a, #b) } } OptionalLit(ref t, ref es) => { - let t = option_tks(t.as_ref().map(deref).map(dhall_to_tokenstream_bx)); + let t = + option_tks(t.as_ref().map(deref).map(dhall_to_tokenstream_bx)); let es = vec_tks(es.into_iter().map(dhall_to_tokenstream)); - quote!{ OptionalLit(#t, #es) } + quote! { OptionalLit(#t, #es) } } ListLit(ref t, ref es) => { - let t = option_tks(t.as_ref().map(deref).map(dhall_to_tokenstream_bx)); + let t = + option_tks(t.as_ref().map(deref).map(dhall_to_tokenstream_bx)); let es = vec_tks(es.into_iter().map(dhall_to_tokenstream)); - quote!{ ListLit(#t, #es) } + quote! { ListLit(#t, #es) } } e => unimplemented!("{:?}", e), } @@ -65,11 +67,11 @@ fn dhall_to_tokenstream_bx(expr: &Expr<X, X>) -> TokenStream { match expr { Var(V(s, _)) => { let v: TokenStream = s.parse().unwrap(); - quote!{ { + quote! { { let x: Box<Expr<_, _>> = #v.clone(); x } } - }, + } e => bx(dhall_to_tokenstream(e)), } } @@ -87,18 +89,19 @@ fn deref<T>(x: &Box<T>) -> &T { } fn bx(x: TokenStream) -> TokenStream { - quote!{ bx(#x) } + quote! { bx(#x) } } fn option_tks(x: Option<TokenStream>) -> TokenStream { match x { - Some(x) => quote!{ Some(#x) }, - None => quote!{ None }, + Some(x) => quote! { Some(#x) }, + None => quote! { None }, } } fn vec_tks<T>(x: T) -> TokenStream -where T: Iterator<Item=TokenStream> +where + T: Iterator<Item = TokenStream>, { - quote!{ vec![ #(#x),* ] } + quote! { vec![ #(#x),* ] } } diff --git a/dhall_normalize/src/normalize.rs b/dhall_normalize/src/normalize.rs index 0e46ee0..fb8079a 100644 --- a/dhall_normalize/src/normalize.rs +++ b/dhall_normalize/src/normalize.rs @@ -153,9 +153,15 @@ where BinOp(BoolOr, box BoolLit(x), box BoolLit(y)) => BoolLit(x || y), BinOp(BoolEQ, box BoolLit(x), box BoolLit(y)) => BoolLit(x == y), BinOp(BoolNE, box BoolLit(x), box BoolLit(y)) => BoolLit(x != y), - BinOp(NaturalPlus, box NaturalLit(x), box NaturalLit(y)) => NaturalLit(x + y), - BinOp(NaturalTimes, box NaturalLit(x), box NaturalLit(y)) => NaturalLit(x * y), - BinOp(TextAppend, box TextLit(x), box TextLit(y)) => TextLit(x + &y), + BinOp(NaturalPlus, box NaturalLit(x), box NaturalLit(y)) => { + NaturalLit(x + y) + } + BinOp(NaturalTimes, box NaturalLit(x), box NaturalLit(y)) => { + NaturalLit(x * y) + } + BinOp(TextAppend, box TextLit(x), box TextLit(y)) => { + TextLit(x + &y) + } BinOp(ListAppend, box ListLit(t1, xs), box ListLit(t2, ys)) => { // Drop type annotation if the result is nonempty let t = if xs.len() == 0 && ys.len() == 0 { |