From 250525a05e1af17bb46ceb72879f471e54fb5091 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 2 Sep 2019 23:07:12 +0200 Subject: No need to change the type of Embed when resolving anymore --- dhall/src/phase/mod.rs | 4 ++-- dhall_syntax/src/core/expr.rs | 25 ++++++++++++++++--------- dhall_syntax/src/core/visitor.rs | 11 ++++++----- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 2c5505c..337ce3d 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -16,8 +16,8 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub type ParsedExpr = Expr; -pub type DecodedExpr = Expr; +pub type ParsedExpr = Expr; +pub type DecodedExpr = Expr; pub type ResolvedExpr = Expr; pub type NormalizedExpr = Expr; diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index eeee4d8..f46cafb 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -313,21 +313,25 @@ impl ExprF { } impl RawExpr { - pub fn traverse_resolve( + pub fn traverse_resolve( &self, - visit_import: impl FnMut(&Import>) -> Result, - ) -> Result, Err> { + visit_import: impl FnMut(&Import>) -> Result, + ) -> Result, Err> + where + E: Clone, + { self.traverse_resolve_with_visitor(&mut visitor::ResolveVisitor( visit_import, )) } - pub(crate) fn traverse_resolve_with_visitor( + pub(crate) fn traverse_resolve_with_visitor( &self, visitor: &mut visitor::ResolveVisitor, - ) -> Result, Err> + ) -> Result, Err> where - F1: FnMut(&Import>) -> Result, + E: Clone, + F1: FnMut(&Import>) -> Result, { match self { ExprF::BinOp(BinOp::ImportAlt, l, r) => l @@ -368,10 +372,13 @@ impl Expr { } impl Expr { - pub fn traverse_resolve( + pub fn traverse_resolve( &self, - visit_import: impl FnMut(&Import>) -> Result, - ) -> Result, Err> { + visit_import: impl FnMut(&Import>) -> Result, + ) -> Result, Err> + where + E: Clone, + { Ok(self.rewrap(self.as_ref().traverse_resolve(visit_import)?)) } } diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs index 435771e..addb282 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall_syntax/src/core/visitor.rs @@ -250,24 +250,25 @@ where pub struct ResolveVisitor(pub F1); -impl<'a, 'b, E, E2, Err, F1> ExprFFallibleVisitor<'a, Expr, Expr, E, E2> +impl<'a, 'b, E, Err, F1> ExprFFallibleVisitor<'a, Expr, Expr, E, E> for &'b mut ResolveVisitor where - F1: FnMut(&Import>) -> Result, + E: Clone, + F1: FnMut(&Import>) -> Result, { type Error = Err; fn visit_subexpr( &mut self, subexpr: &'a Expr, - ) -> Result, Self::Error> { + ) -> Result, Self::Error> { Ok(subexpr.rewrap( subexpr .as_ref() .traverse_resolve_with_visitor(&mut **self)?, )) } - fn visit_embed(self, _embed: &'a E) -> Result { - unimplemented!() + fn visit_embed(self, embed: &'a E) -> Result { + Ok(embed.clone()) } } -- cgit v1.2.3