diff options
Diffstat (limited to 'dhall_core/src')
-rw-r--r-- | dhall_core/src/core.rs | 78 | ||||
-rw-r--r-- | dhall_core/src/parser.rs | 38 |
2 files changed, 58 insertions, 58 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index a7b6b53..34738bb 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -176,13 +176,13 @@ pub enum BinOp { #[derive(Debug, Clone, PartialEq)] pub struct InterpolatedText<Note, Embed> { head: String, - tail: Vec<(Expr<Note, Embed>, String)>, + tail: Vec<(Box<Expr<Note, Embed>>, String)>, } -impl<N, E> From<(String, Vec<(Expr<N, E>, String)>)> +impl<N, E> From<(String, Vec<(Box<Expr<N, E>>, String)>)> for InterpolatedText<N, E> { - fn from(x: (String, Vec<(Expr<N, E>, String)>)) -> Self { + fn from(x: (String, Vec<(Box<Expr<N, E>>, String)>)) -> Self { InterpolatedText { head: x.0, tail: x.1, @@ -203,7 +203,7 @@ impl<N, E> From<String> for InterpolatedText<N, E> { // This one is needed when parsing, because we need to own the Expr pub enum OwnedInterpolatedTextContents<'a, Note, Embed> { Text(&'a str), - Expr(Expr<Note, Embed>), + Expr(Box<Expr<Note, Embed>>), } // This one is needed everywhere else, because we don't want Clone traits bounds @@ -222,7 +222,7 @@ impl<'a, N: Clone + 'a, E: Clone + 'a> OwnedInterpolatedTextContents::Text(s) } BorrowedInterpolatedTextContents::Expr(e) => { - OwnedInterpolatedTextContents::Expr(e.clone()) + OwnedInterpolatedTextContents::Expr(bx(e.clone())) } } } @@ -231,7 +231,7 @@ impl<'a, N: Clone + 'a, E: Clone + 'a> impl<N, E> InterpolatedText<N, E> { pub fn map<N2, E2, F>(&self, mut f: F) -> InterpolatedText<N2, E2> where - F: FnMut(&Expr<N, E>) -> Expr<N2, E2>, + F: FnMut(&Box<Expr<N, E>>) -> Box<Expr<N2, E2>>, { InterpolatedText { head: self.head.clone(), @@ -304,7 +304,7 @@ pub enum Expr<Note, Embed> { /// `Pi x A B ~ ∀(x : A) -> B` Pi(Label, Box<Expr<Note, Embed>>, Box<Expr<Note, Embed>>), /// `App f A ~ f A` - App(Box<Expr<Note, Embed>>, Vec<Expr<Note, Embed>>), + App(Box<Expr<Note, Embed>>, Vec<Box<Expr<Note, Embed>>>), /// `Let x Nothing r e ~ let x = r in e` /// `Let x (Just t) r e ~ let x : t = r in e` Let( @@ -336,7 +336,7 @@ pub enum Expr<Note, Embed> { /// `TextLit t ~ t` TextLit(InterpolatedText<Note, Embed>), /// `ListLit t [x, y, z] ~ [x, y, z] : List t` - ListLit(Option<Box<Expr<Note, Embed>>>, Vec<Expr<Note, Embed>>), + ListLit(Option<Box<Expr<Note, Embed>>>, Vec<Box<Expr<Note, Embed>>>), /// `OptionalLit t [e] ~ [e] : Optional t` /// `OptionalLit t [] ~ [] : Optional t` OptionalLit( @@ -344,16 +344,16 @@ pub enum Expr<Note, Embed> { Option<Box<Expr<Note, Embed>>>, ), /// `Record [(k1, t1), (k2, t2)] ~ { k1 : t1, k2 : t1 }` - Record(BTreeMap<Label, Expr<Note, Embed>>), + Record(BTreeMap<Label, Box<Expr<Note, Embed>>>), /// `RecordLit [(k1, v1), (k2, v2)] ~ { k1 = v1, k2 = v2 }` - RecordLit(BTreeMap<Label, Expr<Note, Embed>>), + RecordLit(BTreeMap<Label, Box<Expr<Note, Embed>>>), /// `Union [(k1, t1), (k2, t2)] ~ < k1 : t1, k2 : t2 >` - Union(BTreeMap<Label, Expr<Note, Embed>>), + Union(BTreeMap<Label, Box<Expr<Note, Embed>>>), /// `UnionLit (k1, v1) [(k2, t2), (k3, t3)] ~ < k1 = t1, k2 : t2, k3 : t3 >` UnionLit( Label, Box<Expr<Note, Embed>>, - BTreeMap<Label, Expr<Note, Embed>>, + BTreeMap<Label, Box<Expr<Note, Embed>>>, ), /// `Merge x y t ~ merge x y : t` Merge( @@ -848,12 +848,15 @@ where Expr::Pi(var.into(), bx(ty.into()), bx(value.into())) } -pub fn app<S, A, Ef, Ex>(f: Ef, x: Vec<Ex>) -> Expr<S, A> +pub fn app<S, A, Ef, Ex>(f: Ef, x: Vec<Box<Ex>>) -> Expr<S, A> where Ef: Into<Expr<S, A>>, Ex: Into<Expr<S, A>>, { - Expr::App(bx(f.into()), x.into_iter().map(|x| x.into()).collect()) + Expr::App( + bx(f.into()), + x.into_iter().map(|x| bx((*x).into())).collect(), + ) } pub type Double = f64; @@ -902,6 +905,7 @@ where { use crate::Expr::*; let bxmap = |x: &Expr<S, A>| -> Box<Expr<T, B>> { bx(map(x)) }; + let bxbxmap = |x: &Box<Expr<S, A>>| -> Box<Expr<T, B>> { bx(map(&**x)) }; let opt = |x| map_opt_box(x, &map); match *e { Const(k) => Const(k), @@ -909,7 +913,7 @@ where Lam(ref x, ref t, ref b) => Lam(map_label(x), bxmap(t), bxmap(b)), Pi(ref x, ref t, ref b) => Pi(map_label(x), bxmap(t), bxmap(b)), App(ref f, ref args) => { - let args = args.iter().map(&map).collect(); + let args = args.iter().map(bxbxmap).collect(); App(bxmap(f), args) } Let(ref l, ref t, ref a, ref b) => { @@ -922,24 +926,26 @@ where NaturalLit(n) => NaturalLit(n), IntegerLit(n) => IntegerLit(n), DoubleLit(n) => DoubleLit(n), - TextLit(ref t) => TextLit(t.map(|e| map(e))), + TextLit(ref t) => TextLit(t.map(&bxbxmap)), BinOp(o, ref x, ref y) => BinOp(o, bxmap(x), bxmap(y)), ListLit(ref t, ref es) => { - let es = es.iter().map(&map).collect(); + let es = es.iter().map(&bxbxmap).collect(); ListLit(opt(t), es) } OptionalLit(ref t, ref es) => OptionalLit(opt(t), opt(es)), Record(ref kts) => { - Record(map_record_value_and_keys(kts, map, map_label)) + Record(map_record_value_and_keys(kts, bxbxmap, map_label)) } RecordLit(ref kvs) => { - RecordLit(map_record_value_and_keys(kvs, map, map_label)) + RecordLit(map_record_value_and_keys(kvs, bxbxmap, map_label)) + } + Union(ref kts) => { + Union(map_record_value_and_keys(kts, bxbxmap, map_label)) } - Union(ref kts) => Union(map_record_value_and_keys(kts, map, map_label)), UnionLit(ref k, ref v, ref kvs) => UnionLit( map_label(k), bxmap(v), - map_record_value_and_keys(kvs, map, map_label), + map_record_value_and_keys(kvs, bxbxmap, map_label), ), Merge(ref x, ref y, ref t) => Merge(bxmap(x), bxmap(y), opt(t)), Field(ref r, ref x) => Field(bxmap(r), map_label(x)), @@ -1087,7 +1093,7 @@ pub fn shift<S, T, A: Clone>(d: isize, v: &V, e: &Expr<S, A>) -> Expr<T, A> { } App(f, args) => { let f = shift(d, v, f); - let args = args.iter().map(|a| shift(d, v, a)).collect(); + let args = args.iter().map(|a| bx(shift(d, v, a))).collect(); app(f, args) } Let(f, mt, r, e) => { @@ -1107,22 +1113,24 @@ pub fn shift<S, T, A: Clone>(d: isize, v: &V, e: &Expr<S, A>) -> Expr<T, A> { NaturalLit(a) => NaturalLit(*a), IntegerLit(a) => IntegerLit(*a), DoubleLit(a) => DoubleLit(*a), - TextLit(a) => TextLit(a.map(|e| shift(d, v, e))), + TextLit(a) => TextLit(a.map(|e| bx(shift(d, v, &*e)))), ListLit(t, es) => ListLit( t.as_ref().map(|t| bx(shift(d, v, t))), - es.iter().map(|e| shift(d, v, e)).collect(), + es.iter().map(|e| bx(shift(d, v, e))).collect(), ), OptionalLit(t, e) => OptionalLit( t.as_ref().map(|t| bx(shift(d, v, t))), e.as_ref().map(|t| bx(shift(d, v, t))), ), - Record(a) => Record(map_record_value(a, |val| shift(d, v, val))), - RecordLit(a) => RecordLit(map_record_value(a, |val| shift(d, v, val))), - Union(a) => Union(map_record_value(a, |val| shift(d, v, val))), + Record(a) => Record(map_record_value(a, |val| bx(shift(d, v, &*val)))), + RecordLit(a) => { + RecordLit(map_record_value(a, |val| bx(shift(d, v, &*val)))) + } + Union(a) => Union(map_record_value(a, |val| bx(shift(d, v, &*val)))), UnionLit(k, uv, a) => UnionLit( k.clone(), bx(shift(d, v, uv)), - map_record_value(a, |val| shift(d, v, val)), + map_record_value(a, |val| bx(shift(d, v, &*val))), ), Merge(a, b, c) => Merge( bx(shift(d, v, a)), @@ -1182,7 +1190,7 @@ where } App(f, args) => { let f2 = subst(v, e, f); - let args = args.iter().map(|a| subst(v, e, a)).collect(); + let args = args.iter().map(|a| bx(subst(v, e, a))).collect(); app(f2, args) } Var(v2) => { @@ -1210,10 +1218,10 @@ where NaturalLit(a) => NaturalLit(*a), IntegerLit(a) => IntegerLit(*a), DoubleLit(a) => DoubleLit(*a), - TextLit(a) => TextLit(a.map(|b| subst(v, e, b))), + TextLit(a) => TextLit(a.map(|b| bx(subst(v, e, &*b)))), ListLit(a, b) => { let a2 = a.as_ref().map(|a| bx(subst(v, e, a))); - let b2 = b.iter().map(|be| subst(v, e, be)).collect(); + let b2 = b.iter().map(|be| bx(subst(v, e, be))).collect(); ListLit(a2, b2) } OptionalLit(a, b) => { @@ -1221,15 +1229,15 @@ where let b2 = b.as_ref().map(|a| bx(subst(v, e, a))); OptionalLit(a2, b2) } - Record(kts) => Record(map_record_value(kts, |t| subst(v, e, t))), + Record(kts) => Record(map_record_value(kts, |t| bx(subst(v, e, &*t)))), RecordLit(kvs) => { - RecordLit(map_record_value(kvs, |val| subst(v, e, val))) + RecordLit(map_record_value(kvs, |val| bx(subst(v, e, &*val)))) } - Union(kts) => Union(map_record_value(kts, |t| subst(v, e, t))), + Union(kts) => Union(map_record_value(kts, |t| bx(subst(v, e, &*t)))), UnionLit(k, uv, kvs) => UnionLit( k.clone(), bx(subst(v, e, uv)), - map_record_value(kvs, |val| subst(v, e, val)), + map_record_value(kvs, |val| bx(subst(v, e, &*val))), ), Merge(a, b, c) => Merge( bx(subst(v, e, a)), diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 9cbd878..b2955fb 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -437,7 +437,7 @@ rule!(double_quote_literal<ParsedText>; // TODO: parse escapes rule!(double_quote_chunk<ParsedTextContents<'a>>; children!(c: interpolation) => { - OwnedInterpolatedTextContents::Expr(*c) + OwnedInterpolatedTextContents::Expr(c) }, captured_str!(s) => { OwnedInterpolatedTextContents::Text(s) @@ -461,7 +461,7 @@ rule!(interpolation<BoxExpr>; rule!(single_quote_continue<Vec<ParsedTextContents<'a>>>; children!(c: interpolation, rest: single_quote_continue) => { - rest.push(OwnedInterpolatedTextContents::Expr(*c)); rest + rest.push(OwnedInterpolatedTextContents::Expr(c)); rest }, children!(c: escaped_quote_pair, rest: single_quote_continue) => { rest.push(OwnedInterpolatedTextContents::Text(c)); rest @@ -746,7 +746,7 @@ rule!(annotated_expression<BoxExpr>; rule!(application_expression<BoxExpr>; children!(first: expression, rest*: expression) => { - let rest: Vec<_> = rest.map(|x| *x).collect(); + let rest: Vec<_> = rest.collect(); if rest.is_empty() { first } else { @@ -799,27 +799,23 @@ rule!(empty_record_type<BoxExpr>; rule!(non_empty_record_type_or_literal<BoxExpr>; children!(first_label: label, rest: non_empty_record_type) => { let (first_expr, mut map) = rest; - map.insert(first_label, *first_expr); + map.insert(first_label, first_expr); bx(Expr::Record(map)) }, children!(first_label: label, rest: non_empty_record_literal) => { let (first_expr, mut map) = rest; - map.insert(first_label, *first_expr); + map.insert(first_label, first_expr); bx(Expr::RecordLit(map)) }, ); -rule!(non_empty_record_type<(BoxExpr, BTreeMap<Label, ParsedExpr>)>; +rule!(non_empty_record_type<(BoxExpr, BTreeMap<Label, BoxExpr>)>; self!(x: partial_record_entries) => x ); -named!(partial_record_entries<(BoxExpr, BTreeMap<Label, ParsedExpr>)>; +named!(partial_record_entries<(BoxExpr, BTreeMap<Label, BoxExpr>)>; children!(expr: expression, entries*: record_entry) => { - let mut map: BTreeMap<Label, ParsedExpr> = BTreeMap::new(); - for (n, e) in entries { - map.insert(n, *e); - } - (expr, map) + (expr, entries.collect()) } ); @@ -827,7 +823,7 @@ named!(record_entry<(Label, BoxExpr)>; children!(name: label, expr: expression) => (name, expr) ); -rule!(non_empty_record_literal<(BoxExpr, BTreeMap<Label, ParsedExpr>)>; +rule!(non_empty_record_literal<(BoxExpr, BTreeMap<Label, BoxExpr>)>; self!(x: partial_record_entries) => x ); @@ -846,29 +842,25 @@ rule!(union_type_or_literal<BoxExpr>; rule!(empty_union_type<()>; children!() => ()); rule!(non_empty_union_type_or_literal - <(Option<(Label, BoxExpr)>, BTreeMap<Label, ParsedExpr>)>; + <(Option<(Label, BoxExpr)>, BTreeMap<Label, BoxExpr>)>; children!(l: label, e: expression, entries: union_type_entries) => { (Some((l, e)), entries) }, children!(l: label, e: expression, rest: non_empty_union_type_or_literal) => { let (x, mut entries) = rest; - entries.insert(l, *e); + entries.insert(l, e); (x, entries) }, children!(l: label, e: expression) => { let mut entries = BTreeMap::new(); - entries.insert(l, *e); + entries.insert(l, e); (None, entries) }, ); -rule!(union_type_entries<BTreeMap<Label, ParsedExpr>>; +rule!(union_type_entries<BTreeMap<Label, BoxExpr>>; children!(entries*: union_type_entry) => { - let mut map: BTreeMap<Label, ParsedExpr> = BTreeMap::new(); - for (n, e) in entries { - map.insert(n, *e); - } - map + entries.collect() } ); @@ -878,7 +870,7 @@ rule!(union_type_entry<(Label, BoxExpr)>; rule!(non_empty_list_literal_raw<BoxExpr>; children!(items*: expression) => { - bx(Expr::ListLit(None, items.map(|x| *x).collect())) + bx(Expr::ListLit(None, items.collect())) } ); |