From a1f370cb68974c1e69f8f85345e91ec763b23ae2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 18 Mar 2020 22:28:41 +0000 Subject: Expose simple::Val/Ty properly in the API --- serde_dhall/src/value.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'serde_dhall/src/value.rs') diff --git a/serde_dhall/src/value.rs b/serde_dhall/src/value.rs index a24f211..62632e5 100644 --- a/serde_dhall/src/value.rs +++ b/serde_dhall/src/value.rs @@ -1,11 +1,11 @@ -use dhall::semantics::Hir; +use dhall::semantics::{Hir, Nir}; use dhall::syntax::Expr; -use dhall::{Normalized, Parsed}; +use dhall::Parsed; -use crate::simple::{SimpleType, SimpleValue}; +use crate::simple::{Type as SimpleType, Value as SimpleValue}; use crate::Error; -/// A Dhall value. +/// An arbitrary Dhall value. #[derive(Debug, Clone)] pub struct Value { /// Invariant: in normal form @@ -21,28 +21,27 @@ impl Value { /// annotation. pub fn from_str_with_annot( s: &str, - ty: Option<&Self>, + ty: Option<&SimpleType>, ) -> Result { Self::from_str_with_annot_dhall_error(s, ty).map_err(Error::Dhall) } - fn from_normalized(x: &Normalized) -> Self { + fn from_nir(x: &Nir) -> Self { Value { - hir: x.to_hir(), - as_simple_val: SimpleValue::from_nir(x.as_nir()), - as_simple_ty: SimpleType::from_nir(x.as_nir()), + hir: x.to_hir_noenv(), + as_simple_val: SimpleValue::from_nir(x), + as_simple_ty: SimpleType::from_nir(x), } } - fn from_str_with_annot_dhall_error( s: &str, - ty: Option<&Self>, + ty: Option<&SimpleType>, ) -> Result { let resolved = Parsed::parse_str(s)?.resolve()?; let typed = match ty { None => resolved.typecheck()?, - Some(ty) => resolved.typecheck_with(&ty.hir)?, + Some(ty) => resolved.typecheck_with(&ty.to_value().hir)?, }; - Ok(Self::from_normalized(&typed.normalize())) + Ok(Self::from_nir(typed.normalize().as_nir())) } /// Converts a Value into a SimpleValue. @@ -55,7 +54,7 @@ impl Value { } /// Converts a value back to the corresponding AST expression. - pub fn to_expr(&self) -> Expr { + pub(crate) fn to_expr(&self) -> Expr { self.hir.to_expr(Default::default()) } } -- cgit v1.2.3