summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-09-03 16:44:02 +0200
committerNadrieril2019-09-03 17:30:11 +0200
commitf1c3d1d7487fbb18b228a1082fc1c966f34b6dc3 (patch)
treea4b8409d0d89d741a11b7227388ad0d0b1079ed7 /dhall
parent31a03bf9140a2fdf5eb52d0998d2d41efaf0d610 (diff)
Add mapping functions to InterpolatedTextContents
Diffstat (limited to 'dhall')
-rw-r--r--dhall/src/core/valuef.rs22
-rw-r--r--dhall/src/core/var.rs12
2 files changed, 8 insertions, 26 deletions
diff --git a/dhall/src/core/valuef.rs b/dhall/src/core/valuef.rs
index 7a2b51c..4e457e6 100644
--- a/dhall/src/core/valuef.rs
+++ b/dhall/src/core/valuef.rs
@@ -110,17 +110,11 @@ impl ValueF {
ValueF::UnionConstructor(l.clone(), kts.clone()).to_expr(opts),
v.to_expr(opts),
)),
- ValueF::TextLit(elts) => {
- use InterpolatedTextContents::{Expr, Text};
- rc(ExprF::TextLit(
- elts.iter()
- .map(|contents| match contents {
- Expr(e) => Expr(e.to_expr(opts)),
- Text(s) => Text(s.clone()),
- })
- .collect(),
- ))
- }
+ ValueF::TextLit(elts) => rc(ExprF::TextLit(
+ elts.iter()
+ .map(|contents| contents.map_ref(|e| e.to_expr(opts)))
+ .collect(),
+ )),
ValueF::Equivalence(x, y) => rc(ExprF::BinOp(
dhall_syntax::BinOp::Equivalence,
x.to_expr(opts),
@@ -187,11 +181,7 @@ impl ValueF {
}
ValueF::TextLit(elts) => {
for x in elts.iter_mut() {
- use InterpolatedTextContents::{Expr, Text};
- match x {
- Expr(v) => v.normalize_mut(),
- Text(_) => {}
- }
+ x.map_mut(Value::normalize_mut);
}
}
ValueF::Equivalence(x, y) => {
diff --git a/dhall/src/core/var.rs b/dhall/src/core/var.rs
index ce4d137..3795f10 100644
--- a/dhall/src/core/var.rs
+++ b/dhall/src/core/var.rs
@@ -224,11 +224,7 @@ where
impl<T: Shift> Shift for dhall_syntax::InterpolatedTextContents<T> {
fn shift(&self, delta: isize, var: &AlphaVar) -> Option<Self> {
- use dhall_syntax::InterpolatedTextContents::{Expr, Text};
- Some(match self {
- Expr(x) => Expr(x.shift(delta, var)?),
- Text(s) => Text(s.clone()),
- })
+ Some(self.traverse_ref(|x| Ok(x.shift(delta, var)?))?)
}
}
@@ -283,11 +279,7 @@ impl<S, T: Subst<S>> Subst<S> for Vec<T> {
impl<S, T: Subst<S>> Subst<S> for dhall_syntax::InterpolatedTextContents<T> {
fn subst_shift(&self, var: &AlphaVar, val: &S) -> Self {
- use dhall_syntax::InterpolatedTextContents::{Expr, Text};
- match self {
- Expr(x) => Expr(x.subst_shift(var, val)),
- Text(s) => Text(s.clone()),
- }
+ self.map_ref(|x| x.subst_shift(var, val))
}
}