diff options
author | Nadrieril | 2019-03-06 23:48:55 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-06 23:48:55 +0100 |
commit | 474744de28034e9558b1a3ff4f9e21ec1425d794 (patch) | |
tree | 8316d086b816e62bd185826fc8f58b46ffe17e92 /dhall | |
parent | e3813e7d4e3450704c1213fd6cdff7c801ccbc34 (diff) |
rustfmt
Diffstat (limited to '')
-rw-r--r-- | dhall/src/imports.rs | 7 | ||||
-rw-r--r-- | dhall/src/lib.rs | 2 | ||||
-rw-r--r-- | dhall/src/normalize.rs | 72 | ||||
-rw-r--r-- | dhall_core/src/core.rs | 8 | ||||
-rw-r--r-- | dhall_generator/src/lib.rs | 3 |
5 files changed, 51 insertions, 41 deletions
diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 32ddfd7..6d8d670 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -1,11 +1,12 @@ -use dhall_core::{Expr, Import, ImportLocation, ImportMode, FilePrefix, X}; - +use dhall_core::{Expr, FilePrefix, Import, ImportLocation, ImportMode, X}; // fn resolve_import(import: Import) -> Expr<X, Import> { // } -pub fn resolve_imports<'i, S: Clone>(expr: &Expr<'i, S, Import>) -> Expr<'i, S, X> { +pub fn resolve_imports<'i, S: Clone>( + expr: &Expr<'i, S, Import>, +) -> Expr<'i, S, X> { let no_import = |_: &Import| -> X { panic!("ahhh import") }; expr.map_embed(&no_import) } diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 54f0983..4e56264 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -4,5 +4,5 @@ mod normalize; pub use crate::normalize::*; -pub mod typecheck; pub mod imports; +pub mod typecheck; diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index b46722a..9dd384a 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -145,37 +145,47 @@ where }, // Normalize everything else before matching - e => match e.map_shallow(normalize, |_| unreachable!(), |x| x.clone()) { - BinOp(BoolAnd, box BoolLit(x), box BoolLit(y)) => BoolLit(x && y), - 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(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 { - t1.or(t2) - } else { - None - }; - let xs = xs.into_iter(); - let ys = ys.into_iter(); - ListLit(t, xs.chain(ys).collect()) + e => { + match e.map_shallow(normalize, |_| unreachable!(), |x| x.clone()) { + BinOp(BoolAnd, box BoolLit(x), box BoolLit(y)) => { + BoolLit(x && y) + } + 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(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 { + t1.or(t2) + } else { + None + }; + let xs = xs.into_iter(); + let ys = ys.into_iter(); + ListLit(t, xs.chain(ys).collect()) + } + Merge(_x, _y, _t) => unimplemented!(), + Field(box RecordLit(kvs), x) => match kvs.get(x) { + Some(r) => r.clone(), + None => Field(bx(RecordLit(kvs)), x), + }, + e => e, } - Merge(_x, _y, _t) => unimplemented!(), - Field(box RecordLit(kvs), x) => match kvs.get(x) { - Some(r) => r.clone(), - None => Field(bx(RecordLit(kvs)), x), - }, - e => e, - }, + } } } diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index cb4d6ca..f2177b1 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -278,16 +278,14 @@ impl<'i, S, A> Expr<'i, S, A> { map_shallow(self, map_expr, map_note, map_embed) } - pub fn map_embed<B, F>( - &self, - map_embed: &F, - ) -> Expr<'i, S, B> + pub fn map_embed<B, F>(&self, map_embed: &F) -> Expr<'i, S, B> where A: Clone, S: Clone, F: Fn(&A) -> B, { - let recurse = |e: &Expr<'i, S, A>| -> Expr<'i, S, B> { e.map_embed(map_embed) }; + let recurse = + |e: &Expr<'i, S, A>| -> Expr<'i, S, B> { e.map_embed(map_embed) }; map_shallow(self, recurse, |x| x.clone(), map_embed) } diff --git a/dhall_generator/src/lib.rs b/dhall_generator/src/lib.rs index 5cd93f3..e43db43 100644 --- a/dhall_generator/src/lib.rs +++ b/dhall_generator/src/lib.rs @@ -9,7 +9,8 @@ use quote::quote; pub fn dhall(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input_str = input.to_string(); let expr: Box<Expr<X, Import>> = parser::parse_expr(&input_str).unwrap(); - let no_import = |_: &Import| -> X { panic!("Don't use import in dhall!()") }; + let no_import = + |_: &Import| -> X { panic!("Don't use import in dhall!()") }; let expr = expr.map_embed(&no_import); let output = dhall_to_tokenstream(&expr, &Context::new()); output.into() |