summaryrefslogtreecommitdiff
path: root/dhall_generator
diff options
context:
space:
mode:
authorNadrieril2019-03-06 16:43:17 +0100
committerNadrieril2019-03-06 16:43:17 +0100
commit932c4842bbc631a77fa518d3cfb55f11fea73ee7 (patch)
tree557de669a36f940223bde9bd5ef135dec56339ab /dhall_generator
parent4d92f06c98c98c014a02c218b6c31cf81d9f0fec (diff)
Simplify normalization using dhall! macro
Diffstat (limited to 'dhall_generator')
-rw-r--r--dhall_generator/src/lib.rs31
1 files changed, 24 insertions, 7 deletions
diff --git a/dhall_generator/src/lib.rs b/dhall_generator/src/lib.rs
index 85f9ce2..d0d8d98 100644
--- a/dhall_generator/src/lib.rs
+++ b/dhall_generator/src/lib.rs
@@ -19,7 +19,10 @@ fn dhall_to_tokenstream(expr: &Expr<X, X>) -> TokenStream {
match expr {
Var(V(s, _)) => {
let v: TokenStream = s.parse().unwrap();
- quote!{ (*#v).clone() }
+ quote!{ {
+ let x: Expr<_, _> = (*#v).clone();
+ x
+ } }
},
Lam(x, ref t, ref b) => {
let x = Literal::string(x);
@@ -36,11 +39,22 @@ fn dhall_to_tokenstream(expr: &Expr<X, X>) -> TokenStream {
let b = builtin_to_tokenstream(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) }
+ }
OptionalLit(ref t, ref es) => {
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) }
}
+ ListLit(ref t, ref es) => {
+ 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) }
+ }
e => unimplemented!("{:?}", e),
}
}
@@ -51,18 +65,21 @@ fn dhall_to_tokenstream_bx(expr: &Expr<X, X>) -> TokenStream {
match expr {
Var(V(s, _)) => {
let v: TokenStream = s.parse().unwrap();
- quote!{ #v.clone() }
+ quote!{ {
+ let x: Box<Expr<_, _>> = #v.clone();
+ x
+ } }
},
e => bx(dhall_to_tokenstream(e)),
}
}
fn builtin_to_tokenstream(b: &Builtin) -> TokenStream {
- use dhall_core::Builtin::*;
- match b {
- Optional => quote!{ Optional },
- b => unimplemented!("{:?}", b),
- }
+ format!("{:?}", b).parse().unwrap()
+}
+
+fn binop_to_tokenstream(b: &BinOp) -> TokenStream {
+ format!("{:?}", b).parse().unwrap()
}
fn deref<T>(x: &Box<T>) -> &T {