summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dhall/src/normalize.rs46
-rw-r--r--dhall_core/src/text.rs8
2 files changed, 35 insertions, 19 deletions
diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs
index d006cc5..5eada3f 100644
--- a/dhall/src/normalize.rs
+++ b/dhall/src/normalize.rs
@@ -282,17 +282,35 @@ impl WHNF {
})
.collect(),
)),
- WHNF::TextLit(elts) => rc(ExprF::TextLit(
- elts.into_iter()
- .map(|contents| {
- use InterpolatedTextContents::{Expr, Text};
- match contents {
- Expr(n) => Expr(n.normalize().normalize_to_expr()),
- Text(s) => Text(s),
- }
- })
- .collect(),
- )),
+ WHNF::TextLit(elts) => {
+ fn normalize_textlit(
+ elts: Vec<InterpolatedTextContents<Now>>,
+ ) -> InterpolatedText<OutputSubExpr> {
+ elts.into_iter()
+ .flat_map(|contents| {
+ use InterpolatedTextContents::{Expr, Text};
+ let new_interpolated = match contents {
+ Expr(n) => match n.normalize() {
+ WHNF::TextLit(elts2) => {
+ normalize_textlit(elts2)
+ }
+ e => InterpolatedText::from((
+ String::new(),
+ vec![(
+ e.normalize_to_expr(),
+ String::new(),
+ )],
+ )),
+ },
+ Text(s) => InterpolatedText::from(s),
+ };
+ new_interpolated.into_iter()
+ })
+ .collect()
+ }
+
+ rc(ExprF::TextLit(normalize_textlit(elts)))
+ }
WHNF::Expr(e) => e,
}
}
@@ -821,8 +839,6 @@ fn normalize_last_layer(
App(Builtin(_), _) => unreachable!(),
App(Lam(_, _, _), _) => unreachable!(),
BoolIf(BoolLit(_), _, _) => unreachable!(),
- // TODO: interpolation
- // TextLit(t) =>
OldOptionalLit(_, _) => unreachable!(),
BinOp(BoolAnd, BoolLit(_), BoolLit(_)) => unreachable!(),
BinOp(BoolOr, BoolLit(_), BoolLit(_)) => unreachable!(),
@@ -1006,7 +1022,7 @@ mod spec_tests {
norm!(success_prelude_Optional_unzip_1, "prelude/Optional/unzip/1");
norm!(success_prelude_Text_concat_0, "prelude/Text/concat/0");
norm!(success_prelude_Text_concat_1, "prelude/Text/concat/1");
- // norm!(success_prelude_Text_concatMap_0, "prelude/Text/concatMap/0");
+ norm!(success_prelude_Text_concatMap_0, "prelude/Text/concatMap/0");
norm!(success_prelude_Text_concatMap_1, "prelude/Text/concatMap/1");
// norm!(success_prelude_Text_concatMapSep_0, "prelude/Text/concatMapSep/0");
// norm!(success_prelude_Text_concatMapSep_1, "prelude/Text/concatMapSep/1");
@@ -1192,7 +1208,7 @@ mod spec_tests {
norm!(success_unit_SomeNormalizeArguments, "unit/SomeNormalizeArguments");
norm!(success_unit_Sort, "unit/Sort");
norm!(success_unit_Text, "unit/Text");
- // norm!(success_unit_TextInterpolate, "unit/TextInterpolate");
+ norm!(success_unit_TextInterpolate, "unit/TextInterpolate");
norm!(success_unit_TextLiteral, "unit/TextLiteral");
norm!(success_unit_TextNormalizeInterpolations, "unit/TextNormalizeInterpolations");
norm!(success_unit_TextShow, "unit/TextShow");
diff --git a/dhall_core/src/text.rs b/dhall_core/src/text.rs
index e886659..ff5c441 100644
--- a/dhall_core/src/text.rs
+++ b/dhall_core/src/text.rs
@@ -86,7 +86,7 @@ impl<SubExpr> InterpolatedText<SubExpr> {
}
}
-impl<'a, SubExpr: 'a> FromIterator<InterpolatedTextContents<SubExpr>>
+impl<SubExpr> FromIterator<InterpolatedTextContents<SubExpr>>
for InterpolatedText<SubExpr>
{
fn from_iter<T>(iter: T) -> Self
@@ -94,15 +94,15 @@ impl<'a, SubExpr: 'a> FromIterator<InterpolatedTextContents<SubExpr>>
T: IntoIterator<Item = InterpolatedTextContents<SubExpr>>,
{
let mut res = InterpolatedText {
- head: "".to_owned(),
- tail: vec![],
+ head: String::new(),
+ tail: Vec::new(),
};
let mut crnt_str = &mut res.head;
for x in iter.into_iter() {
match x {
InterpolatedTextContents::Text(s) => crnt_str.push_str(&s),
InterpolatedTextContents::Expr(e) => {
- res.tail.push((e, "".to_owned()));
+ res.tail.push((e, String::new()));
crnt_str = &mut res.tail.last_mut().unwrap().1;
}
}