diff options
author | Nadrieril | 2019-08-27 23:18:13 +0200 |
---|---|---|
committer | Nadrieril | 2019-08-28 13:16:07 +0200 |
commit | a7363042a16364a6dafdd545f4069dcf04a4197e (patch) | |
tree | fc915b8f5e5f41eb20571c4ad67dd4bb9ace72bc | |
parent | a981afc465f4279a7a4d6ce3ac5844e04846613b (diff) |
Rename SubExpr to Expr, and Expr to RawExpr
For clarity, and consistency with Value
-rw-r--r-- | dhall/src/core/value.rs | 8 | ||||
-rw-r--r-- | dhall/src/core/valuef.rs | 6 | ||||
-rw-r--r-- | dhall/src/error/mod.rs | 8 | ||||
-rw-r--r-- | dhall/src/phase/binary.rs | 49 | ||||
-rw-r--r-- | dhall/src/phase/mod.rs | 22 | ||||
-rw-r--r-- | dhall/src/phase/resolve.rs | 4 | ||||
-rw-r--r-- | dhall/src/phase/typecheck.rs | 16 | ||||
-rw-r--r-- | dhall_syntax/src/core/expr.rs | 64 | ||||
-rw-r--r-- | dhall_syntax/src/core/visitor.rs | 9 | ||||
-rw-r--r-- | dhall_syntax/src/parser.rs | 64 | ||||
-rw-r--r-- | dhall_syntax/src/printer.rs | 6 | ||||
-rw-r--r-- | serde_dhall/src/lib.rs | 4 | ||||
-rw-r--r-- | serde_dhall/src/serde.rs | 4 |
13 files changed, 129 insertions, 135 deletions
diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index 21ac288..49e30cd 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -9,7 +9,7 @@ use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::{TypeError, TypeMessage}; use crate::phase::normalize::{apply_any, normalize_whnf}; use crate::phase::typecheck::{builtin_to_value, const_to_value}; -use crate::phase::{NormalizedSubExpr, Typed}; +use crate::phase::{NormalizedExpr, Typed}; #[derive(Debug, Clone, Copy)] pub(crate) enum Form { @@ -166,11 +166,11 @@ impl Value { } // TODO: rename `normalize_to_expr` - pub(crate) fn to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr(&self) -> NormalizedExpr { self.as_whnf().normalize_to_expr() } // TODO: rename `normalize_to_expr_maybe_alpha` - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { self.as_whnf().normalize_to_expr_maybe_alpha(true) } pub(crate) fn to_whnf_ignore_type(&self) -> ValueF { @@ -226,7 +226,7 @@ impl Value { pub(crate) fn normalize_to_expr_maybe_alpha( &self, alpha: bool, - ) -> NormalizedSubExpr { + ) -> NormalizedExpr { self.as_nf().normalize_to_expr_maybe_alpha(alpha) } diff --git a/dhall/src/core/valuef.rs b/dhall/src/core/valuef.rs index 9ea2467..959f299 100644 --- a/dhall/src/core/valuef.rs +++ b/dhall/src/core/valuef.rs @@ -7,7 +7,7 @@ use dhall_syntax::{ use crate::core::value::Value; use crate::core::var::{AlphaLabel, AlphaVar, Shift, Subst}; -use crate::phase::{Normalized, NormalizedSubExpr}; +use crate::phase::{Normalized, NormalizedExpr}; /// A semantic value. Subexpressions are Values, which are partially evaluated expressions that are /// normalized on-demand. @@ -52,7 +52,7 @@ impl ValueF { } /// Convert the value to a fully normalized syntactic expression - pub(crate) fn normalize_to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn normalize_to_expr(&self) -> NormalizedExpr { self.normalize_to_expr_maybe_alpha(false) } /// Convert the value to a fully normalized syntactic expression. Also alpha-normalize @@ -60,7 +60,7 @@ impl ValueF { pub(crate) fn normalize_to_expr_maybe_alpha( &self, alpha: bool, - ) -> NormalizedSubExpr { + ) -> NormalizedExpr { match self { ValueF::Lam(x, t, e) => rc(ExprF::Lam( x.to_label_maybe_alpha(alpha), diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index 2ddaf3d..6d4e120 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -5,7 +5,7 @@ use dhall_syntax::{BinOp, Import, Label, ParseError, V}; use crate::core::context::TypecheckContext; use crate::core::value::Value; use crate::phase::resolve::ImportStack; -use crate::phase::NormalizedSubExpr; +use crate::phase::NormalizedExpr; pub type Result<T> = std::result::Result<T, Error>; @@ -22,9 +22,9 @@ pub enum Error { #[derive(Debug)] pub enum ImportError { - Recursive(Import<NormalizedSubExpr>, Box<Error>), - UnexpectedImport(Import<NormalizedSubExpr>), - ImportCycle(ImportStack, Import<NormalizedSubExpr>), + Recursive(Import<NormalizedExpr>, Box<Error>), + UnexpectedImport(Import<NormalizedExpr>), + ImportCycle(ImportStack, Import<NormalizedExpr>), } #[derive(Debug)] diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index 3746635..7dc9be2 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -4,28 +4,26 @@ use std::iter::FromIterator; use dhall_syntax::map::DupTreeMap; use dhall_syntax::{ - rc, ExprF, FilePrefix, Hash, Import, ImportLocation, ImportMode, Integer, - InterpolatedText, Label, Natural, Scheme, SubExpr, URL, V, + rc, Expr, ExprF, FilePrefix, Hash, Import, ImportLocation, ImportMode, + Integer, InterpolatedText, Label, Natural, Scheme, URL, V, }; use crate::error::{DecodeError, EncodeError}; -use crate::phase::DecodedSubExpr; +use crate::phase::DecodedExpr; -pub(crate) fn decode(data: &[u8]) -> Result<DecodedSubExpr, DecodeError> { +pub(crate) fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> { match serde_cbor::de::from_slice(data) { Ok(v) => cbor_value_to_dhall(&v), Err(e) => Err(DecodeError::CBORError(e)), } } -pub(crate) fn encode<E>(expr: &SubExpr<E>) -> Result<Vec<u8>, EncodeError> { +pub(crate) fn encode<E>(expr: &Expr<E>) -> Result<Vec<u8>, EncodeError> { serde_cbor::ser::to_vec(&Serialize::Expr(expr)) .map_err(|e| EncodeError::CBORError(e)) } -fn cbor_value_to_dhall( - data: &cbor::Value, -) -> Result<DecodedSubExpr, DecodeError> { +fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> { use cbor::Value::*; use dhall_syntax::{BinOp, Builtin, Const}; use ExprF::*; @@ -382,7 +380,7 @@ fn cbor_map_to_dhall_map<'a, T>( map: impl IntoIterator<Item = (&'a cbor::ObjectKey, &'a cbor::Value)>, ) -> Result<T, DecodeError> where - T: FromIterator<(Label, DecodedSubExpr)>, + T: FromIterator<(Label, DecodedExpr)>, { map.into_iter() .map(|(k, v)| -> Result<(_, _), _> { @@ -399,7 +397,7 @@ fn cbor_map_to_dhall_opt_map<'a, T>( map: impl IntoIterator<Item = (&'a cbor::ObjectKey, &'a cbor::Value)>, ) -> Result<T, DecodeError> where - T: FromIterator<(Label, Option<DecodedSubExpr>)>, + T: FromIterator<(Label, Option<DecodedExpr>)>, { map.into_iter() .map(|(k, v)| -> Result<(_, _), _> { @@ -416,10 +414,10 @@ where } enum Serialize<'a, E> { - Expr(&'a SubExpr<E>), + Expr(&'a Expr<E>), CBOR(cbor::Value), - RecordMap(&'a DupTreeMap<Label, SubExpr<E>>), - UnionMap(&'a DupTreeMap<Label, Option<SubExpr<E>>>), + RecordMap(&'a DupTreeMap<Label, Expr<E>>), + UnionMap(&'a DupTreeMap<Label, Option<Expr<E>>>), } macro_rules! count { @@ -439,7 +437,7 @@ macro_rules! ser_seq { }}; } -fn serialize_subexpr<S, E>(ser: S, e: &SubExpr<E>) -> Result<S::Ok, S::Error> +fn serialize_subexpr<S, E>(ser: S, e: &Expr<E>) -> Result<S::Ok, S::Error> where S: serde::ser::Serializer, { @@ -449,7 +447,7 @@ where use std::iter::once; use self::Serialize::{RecordMap, UnionMap}; - fn expr<E>(x: &SubExpr<E>) -> self::Serialize<'_, E> { + fn expr<E>(x: &Expr<E>) -> self::Serialize<'_, E> { self::Serialize::Expr(x) } let cbor = @@ -566,7 +564,7 @@ where fn serialize_import<S, E>( ser: S, - import: &Import<SubExpr<E>>, + import: &Import<Expr<E>>, ) -> Result<S::Ok, S::Error> where S: serde::ser::Serializer, @@ -675,12 +673,9 @@ impl<'a, E> serde::ser::Serialize for Serialize<'a, E> { } fn collect_nested_applications<'a, E>( - e: &'a SubExpr<E>, -) -> (&'a SubExpr<E>, Vec<&'a SubExpr<E>>) { - fn go<'a, E>( - e: &'a SubExpr<E>, - vec: &mut Vec<&'a SubExpr<E>>, - ) -> &'a SubExpr<E> { + e: &'a Expr<E>, +) -> (&'a Expr<E>, Vec<&'a Expr<E>>) { + fn go<'a, E>(e: &'a Expr<E>, vec: &mut Vec<&'a Expr<E>>) -> &'a Expr<E> { match e.as_ref() { ExprF::App(f, a) => { vec.push(a); @@ -694,15 +689,15 @@ fn collect_nested_applications<'a, E>( (e, vec) } -type LetBinding<'a, E> = (&'a Label, &'a Option<SubExpr<E>>, &'a SubExpr<E>); +type LetBinding<'a, E> = (&'a Label, &'a Option<Expr<E>>, &'a Expr<E>); fn collect_nested_lets<'a, E>( - e: &'a SubExpr<E>, -) -> (&'a SubExpr<E>, Vec<LetBinding<'a, E>>) { + e: &'a Expr<E>, +) -> (&'a Expr<E>, Vec<LetBinding<'a, E>>) { fn go<'a, E>( - e: &'a SubExpr<E>, + e: &'a Expr<E>, vec: &mut Vec<LetBinding<'a, E>>, - ) -> &'a SubExpr<E> { + ) -> &'a Expr<E> { match e.as_ref() { ExprF::Let(l, t, v, e) => { vec.push((l, t, v)); diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index bd8853a..ecc9213 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Builtin, Const, SubExpr}; +use dhall_syntax::{Builtin, Const, Expr}; use crate::core::value::Value; use crate::core::valuef::ValueF; @@ -16,19 +16,19 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub type ParsedSubExpr = SubExpr<!>; -pub type DecodedSubExpr = SubExpr<!>; -pub type ResolvedSubExpr = SubExpr<Normalized>; -pub type NormalizedSubExpr = SubExpr<Normalized>; +pub type ParsedExpr = Expr<!>; +pub type DecodedExpr = Expr<!>; +pub type ResolvedExpr = Expr<Normalized>; +pub type NormalizedExpr = Expr<Normalized>; #[derive(Debug, Clone)] -pub struct Parsed(ParsedSubExpr, ImportRoot); +pub struct Parsed(ParsedExpr, ImportRoot); /// An expression where all imports have been resolved /// /// Invariant: there must be no `Import` nodes or `ImportAlt` operations left. #[derive(Debug, Clone)] -pub struct Resolved(ResolvedSubExpr); +pub struct Resolved(ResolvedExpr); /// A typed expression #[derive(Debug, Clone)] @@ -102,10 +102,10 @@ impl Typed { Typed::from_const(Const::Type) } - pub fn to_expr(&self) -> NormalizedSubExpr { + pub fn to_expr(&self) -> NormalizedExpr { self.0.to_expr() } - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { self.0.to_expr_alpha() } pub(crate) fn to_value(&self) -> Value { @@ -162,10 +162,10 @@ impl Normalized { crate::phase::binary::encode(&self.to_expr()) } - pub(crate) fn to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr(&self) -> NormalizedExpr { self.0.to_expr() } - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { self.0.to_expr_alpha() } pub(crate) fn into_typed(self) -> Typed { diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index 27ae7a3..b715e72 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use crate::error::{Error, ImportError}; -use crate::phase::{Normalized, NormalizedSubExpr, Parsed, Resolved}; +use crate::phase::{Normalized, NormalizedExpr, Parsed, Resolved}; -type Import = dhall_syntax::Import<NormalizedSubExpr>; +type Import = dhall_syntax::Import<NormalizedExpr>; /// A root from which to resolve relative imports. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index ab6d882..52a4e47 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -2,7 +2,7 @@ use std::cmp::max; use std::collections::HashMap; use dhall_syntax::{ - rc, Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, SubExpr, + rc, Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, }; use crate::core::context::TypecheckContext; @@ -200,7 +200,7 @@ macro_rules! make_type { fn type_of_builtin<E>(b: Builtin) -> Expr<E> { use dhall_syntax::Builtin::*; - match b { + rc(match b { Bool | Natural | Integer | Double | Text => make_type!(Type), List | Optional => make_type!( Type -> Type @@ -280,14 +280,14 @@ fn type_of_builtin<E>(b: Builtin) -> Expr<E> { OptionalNone => make_type!( forall (a: Type) -> Optional a ), - } + }) } pub(crate) fn builtin_to_value(b: Builtin) -> Value { let ctx = TypecheckContext::new(); Value::from_valuef_and_type( ValueF::from_builtin(b), - type_with(&ctx, rc(type_of_builtin(b))).unwrap(), + type_with(&ctx, type_of_builtin(b)).unwrap(), ) } @@ -297,7 +297,7 @@ pub(crate) fn builtin_to_value(b: Builtin) -> Value { /// normalized as well. fn type_with( ctx: &TypecheckContext, - e: SubExpr<Normalized>, + e: Expr<Normalized>, ) -> Result<Value, TypeError> { use dhall_syntax::ExprF::{Annot, Embed, Lam, Let, Pi, Var}; @@ -791,13 +791,13 @@ fn type_last_layer( /// `type_of` is the same as `type_with` with an empty context, meaning that the /// expression must be closed (i.e. no free variables), otherwise type-checking /// will fail. -pub(crate) fn typecheck(e: SubExpr<Normalized>) -> Result<Value, TypeError> { +pub(crate) fn typecheck(e: Expr<Normalized>) -> Result<Value, TypeError> { type_with(&TypecheckContext::new(), e) } pub(crate) fn typecheck_with( - expr: SubExpr<Normalized>, - ty: SubExpr<Normalized>, + expr: Expr<Normalized>, + ty: Expr<Normalized>, ) -> Result<Value, TypeError> { typecheck(expr.rewrap(ExprF::Annot(expr.clone(), ty))) } diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 32166a6..2d73a64 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -166,19 +166,21 @@ pub enum Builtin { TextShow, } -// Each node carries an annotation. In practice it's either X (no annotation) or a Span. +// Each node carries an annotation. #[derive(Debug, Clone)] -pub struct SubExpr<Embed>(Box<(Expr<Embed>, Option<Span>)>); +pub struct Expr<Embed>(Box<(RawExpr<Embed>, Option<Span>)>); -impl<Embed: PartialEq> std::cmp::PartialEq for SubExpr<Embed> { +pub type RawExpr<Embed> = ExprF<Expr<Embed>, Embed>; + +impl<Embed: PartialEq> std::cmp::PartialEq for Expr<Embed> { fn eq(&self, other: &Self) -> bool { self.0.as_ref().0 == other.0.as_ref().0 } } -impl<Embed: Eq> std::cmp::Eq for SubExpr<Embed> {} +impl<Embed: Eq> std::cmp::Eq for Expr<Embed> {} -impl<Embed: std::hash::Hash> std::hash::Hash for SubExpr<Embed> { +impl<Embed: std::hash::Hash> std::hash::Hash for Expr<Embed> { fn hash<H>(&self, state: &mut H) where H: std::hash::Hasher, @@ -187,8 +189,6 @@ impl<Embed: std::hash::Hash> std::hash::Hash for SubExpr<Embed> { } } -pub type Expr<Embed> = ExprF<SubExpr<Embed>, Embed>; - /// Syntax tree for expressions // Having the recursion out of the enum definition enables writing // much more generic code and improves pattern-matching behind @@ -310,11 +310,11 @@ impl<SE, E> ExprF<SE, E> { } } -impl<E> Expr<E> { +impl<E> RawExpr<E> { pub fn traverse_resolve<E2, Err>( &self, - visit_import: impl FnMut(&Import<SubExpr<E2>>) -> Result<E2, Err>, - ) -> Result<Expr<E2>, Err> { + visit_import: impl FnMut(&Import<Expr<E2>>) -> Result<E2, Err>, + ) -> Result<RawExpr<E2>, Err> { self.traverse_resolve_with_visitor(&mut visitor::ResolveVisitor( visit_import, )) @@ -323,9 +323,9 @@ impl<E> Expr<E> { pub(crate) fn traverse_resolve_with_visitor<E2, Err, F1>( &self, visitor: &mut visitor::ResolveVisitor<F1>, - ) -> Result<Expr<E2>, Err> + ) -> Result<RawExpr<E2>, Err> where - F1: FnMut(&Import<SubExpr<E2>>) -> Result<E2, Err>, + F1: FnMut(&Import<Expr<E2>>) -> Result<E2, Err>, { match self { ExprF::BinOp(BinOp::ImportAlt, l, r) => l @@ -343,52 +343,52 @@ impl<E> Expr<E> { } } -impl<E> SubExpr<E> { - pub fn as_ref(&self) -> &Expr<E> { +impl<E> Expr<E> { + pub fn as_ref(&self) -> &RawExpr<E> { &self.0.as_ref().0 } - pub fn new(x: Expr<E>, n: Span) -> Self { - SubExpr(Box::new((x, Some(n)))) + pub fn new(x: RawExpr<E>, n: Span) -> Self { + Expr(Box::new((x, Some(n)))) } - pub fn from_expr_no_span(x: Expr<E>) -> Self { - SubExpr(Box::new((x, None))) + pub fn from_expr_no_span(x: RawExpr<E>) -> Self { + Expr(Box::new((x, None))) } pub fn from_builtin(b: Builtin) -> Self { - SubExpr::from_expr_no_span(ExprF::Builtin(b)) + Expr::from_expr_no_span(ExprF::Builtin(b)) } - pub fn rewrap<E2>(&self, x: Expr<E2>) -> SubExpr<E2> { - SubExpr(Box::new((x, (self.0).1.clone()))) + pub fn rewrap<E2>(&self, x: RawExpr<E2>) -> Expr<E2> { + Expr(Box::new((x, (self.0).1.clone()))) } } -impl<E> SubExpr<E> { +impl<E> Expr<E> { pub fn traverse_resolve<E2, Err>( &self, - visit_import: impl FnMut(&Import<SubExpr<E2>>) -> Result<E2, Err>, - ) -> Result<SubExpr<E2>, Err> { + visit_import: impl FnMut(&Import<Expr<E2>>) -> Result<E2, Err>, + ) -> Result<Expr<E2>, Err> { Ok(self.rewrap(self.as_ref().traverse_resolve(visit_import)?)) } } // Should probably rename this -pub fn rc<E>(x: Expr<E>) -> SubExpr<E> { - SubExpr::from_expr_no_span(x) +pub fn rc<E>(x: RawExpr<E>) -> Expr<E> { + Expr::from_expr_no_span(x) } pub(crate) fn spanned( span: Span, - x: crate::parser::ParsedExpr, -) -> crate::parser::ParsedSubExpr { - SubExpr::new(x, span) + x: crate::parser::ParsedRawExpr, +) -> crate::parser::ParsedExpr { + Expr::new(x, span) } pub(crate) fn unspanned( - x: crate::parser::ParsedExpr, -) -> crate::parser::ParsedSubExpr { - SubExpr::from_expr_no_span(x) + x: crate::parser::ParsedRawExpr, +) -> crate::parser::ParsedExpr { + Expr::from_expr_no_span(x) } /// Add an isize to an usize diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs index 5a5fcc9..49fff60 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall_syntax/src/core/visitor.rs @@ -247,18 +247,17 @@ where pub struct ResolveVisitor<F1>(pub F1); -impl<'a, 'b, E, E2, Err, F1> - ExprFFallibleVisitor<'a, SubExpr<E>, SubExpr<E2>, E, E2> +impl<'a, 'b, E, E2, Err, F1> ExprFFallibleVisitor<'a, Expr<E>, Expr<E2>, E, E2> for &'b mut ResolveVisitor<F1> where - F1: FnMut(&Import<SubExpr<E2>>) -> Result<E2, Err>, + F1: FnMut(&Import<Expr<E2>>) -> Result<E2, Err>, { type Error = Err; fn visit_subexpr( &mut self, - subexpr: &'a SubExpr<E>, - ) -> Result<SubExpr<E2>, Self::Error> { + subexpr: &'a Expr<E>, + ) -> Result<Expr<E2>, Self::Error> { Ok(subexpr.rewrap( subexpr .as_ref() diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index d631a19..defa79b 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -18,10 +18,10 @@ use crate::*; // their own crate because they are quite general and useful. For now they // are here and hopefully you can figure out how they work. +pub(crate) type ParsedRawExpr = RawExpr<!>; pub(crate) type ParsedExpr = Expr<!>; -pub(crate) type ParsedSubExpr = SubExpr<!>; -type ParsedText = InterpolatedText<ParsedSubExpr>; -type ParsedTextContents = InterpolatedTextContents<ParsedSubExpr>; +type ParsedText = InterpolatedText<ParsedExpr>; +type ParsedTextContents = InterpolatedTextContents<ParsedExpr>; pub type ParseError = pest::error::Error<Rule>; @@ -551,7 +551,7 @@ make_parser! { rule!(escaped_interpolation<&'a str>; captured_str!(_) => "${" ); - rule!(interpolation<ParsedSubExpr>; children!( + rule!(interpolation<ParsedExpr>; children!( [expression(e)] => e )); @@ -593,7 +593,7 @@ make_parser! { }, )); - rule!(builtin<ParsedSubExpr>; span; + rule!(builtin<ParsedExpr>; span; captured_str!(s) => { spanned(span, match crate::Builtin::parse(s) { Some(b) => Builtin(b), @@ -650,7 +650,7 @@ make_parser! { } ); - rule!(identifier<ParsedSubExpr>; span; children!( + rule!(identifier<ParsedExpr>; span; children!( [variable(v)] => { spanned(span, Var(v)) }, @@ -708,7 +708,7 @@ make_parser! { _ => unreachable!(), }); - rule!(http_raw<URL<ParsedSubExpr>>; children!( + rule!(http_raw<URL<ParsedExpr>>; children!( [scheme(sch), authority(auth), path(p)] => URL { scheme: sch, authority: auth, @@ -729,7 +729,7 @@ make_parser! { rule!(query<String>; captured_str!(s) => s.to_owned()); - rule!(http<URL<ParsedSubExpr>>; children!( + rule!(http<URL<ParsedExpr>>; children!( [http_raw(url)] => url, [http_raw(url), import_expression(e)] => URL { headers: Some(e), ..url }, @@ -764,7 +764,7 @@ make_parser! { rule!(missing<()>); - rule!(import_type<ImportLocation<ParsedSubExpr>>; children!( + rule!(import_type<ImportLocation<ParsedExpr>>; children!( [missing(_)] => { ImportLocation::Missing }, @@ -789,7 +789,7 @@ make_parser! { Hash::SHA256(hex::decode(hash).unwrap()) }); - rule!(import_hashed<crate::Import<ParsedSubExpr>>; children!( + rule!(import_hashed<crate::Import<ParsedExpr>>; children!( [import_type(location)] => crate::Import {mode: ImportMode::Code, location, hash: None }, [import_type(location), hash(h)] => @@ -799,7 +799,7 @@ make_parser! { rule!(Text<()>); rule!(Location<()>); - rule!(import<ParsedSubExpr>; span; children!( + rule!(import<ParsedExpr>; span; children!( [import_hashed(imp)] => { spanned(span, Import(crate::Import { mode: ImportMode::Code, @@ -828,13 +828,13 @@ make_parser! { rule!(if_<()>); rule!(in_<()>); - rule!(empty_list_literal<ParsedSubExpr>; span; children!( + rule!(empty_list_literal<ParsedExpr>; span; children!( [application_expression(e)] => { spanned(span, EmptyListLit(e)) }, )); - rule!(expression<ParsedSubExpr>; span; children!( + rule!(expression<ParsedExpr>; span; children!( [lambda(()), label(l), expression(typ), arrow(()), expression(body)] => { spanned(span, Lam(l, typ, body)) @@ -869,7 +869,7 @@ make_parser! { }, )); - rule!(let_binding<(Label, Option<ParsedSubExpr>, ParsedSubExpr)>; + rule!(let_binding<(Label, Option<ParsedExpr>, ParsedExpr)>; children!( [label(name), expression(annot), expression(expr)] => (name, Some(annot), expr), @@ -880,7 +880,7 @@ make_parser! { rule!(List<()>); rule!(Optional<()>); - rule!(operator_expression<ParsedSubExpr>; prec_climb!( + rule!(operator_expression<ParsedExpr>; prec_climb!( application_expression, { use Rule::*; @@ -936,14 +936,14 @@ make_parser! { rule!(Some_<()>); rule!(toMap<()>); - rule!(application_expression<ParsedSubExpr>; children!( + rule!(application_expression<ParsedExpr>; children!( [first_application_expression(e)] => e, [first_application_expression(first), import_expression(rest)..] => { rest.fold(first, |acc, e| unspanned(App(acc, e))) }, )); - rule!(first_application_expression<ParsedSubExpr>; span; + rule!(first_application_expression<ParsedExpr>; span; children!( [Some_(()), import_expression(e)] => { spanned(span, SomeLit(e)) @@ -954,13 +954,13 @@ make_parser! { [import_expression(e)] => e, )); - rule!(import_expression<ParsedSubExpr>; span; + rule!(import_expression<ParsedExpr>; span; children!( [selector_expression(e)] => e, [import(e)] => e, )); - rule!(selector_expression<ParsedSubExpr>; children!( + rule!(selector_expression<ParsedExpr>; children!( [primitive_expression(e)] => e, [primitive_expression(first), selector(rest)..] => { rest.fold(first, |acc, e| unspanned(match e { @@ -980,7 +980,7 @@ make_parser! { [label(ls)..] => ls.collect(), )); - rule!(primitive_expression<ParsedSubExpr>; span; children!( + rule!(primitive_expression<ParsedExpr>; span; children!( [double_literal(n)] => spanned(span, DoubleLit(n)), [natural_literal(n)] => spanned(span, NaturalLit(n)), [integer_literal(n)] => spanned(span, IntegerLit(n)), @@ -995,15 +995,15 @@ make_parser! { [expression(e)] => e, )); - rule!(empty_record_literal<ParsedSubExpr>; span; + rule!(empty_record_literal<ParsedExpr>; span; captured_str!(_) => spanned(span, RecordLit(Default::default())) ); - rule!(empty_record_type<ParsedSubExpr>; span; + rule!(empty_record_type<ParsedExpr>; span; captured_str!(_) => spanned(span, RecordType(Default::default())) ); - rule!(non_empty_record_type_or_literal<ParsedSubExpr>; span; + rule!(non_empty_record_type_or_literal<ParsedExpr>; span; children!( [label(first_label), non_empty_record_type(rest)] => { let (first_expr, mut map) = rest; @@ -1018,28 +1018,28 @@ make_parser! { )); rule!(non_empty_record_type - <(ParsedSubExpr, DupTreeMap<Label, ParsedSubExpr>)>; children!( + <(ParsedExpr, DupTreeMap<Label, ParsedExpr>)>; children!( [expression(expr), record_type_entry(entries)..] => { (expr, entries.collect()) } )); - rule!(record_type_entry<(Label, ParsedSubExpr)>; children!( + rule!(record_type_entry<(Label, ParsedExpr)>; children!( [label(name), expression(expr)] => (name, expr) )); rule!(non_empty_record_literal - <(ParsedSubExpr, DupTreeMap<Label, ParsedSubExpr>)>; children!( + <(ParsedExpr, DupTreeMap<Label, ParsedExpr>)>; children!( [expression(expr), record_literal_entry(entries)..] => { (expr, entries.collect()) } )); - rule!(record_literal_entry<(Label, ParsedSubExpr)>; children!( + rule!(record_literal_entry<(Label, ParsedExpr)>; children!( [label(name), expression(expr)] => (name, expr) )); - rule!(union_type<ParsedSubExpr>; span; children!( + rule!(union_type<ParsedExpr>; span; children!( [empty_union_type(_)] => { spanned(span, UnionType(Default::default())) }, @@ -1050,12 +1050,12 @@ make_parser! { rule!(empty_union_type<()>); - rule!(union_type_entry<(Label, Option<ParsedSubExpr>)>; children!( + rule!(union_type_entry<(Label, Option<ParsedExpr>)>; children!( [label(name), expression(expr)] => (name, Some(expr)), [label(name)] => (name, None), )); - rule!(non_empty_list_literal<ParsedSubExpr>; span; + rule!(non_empty_list_literal<ParsedExpr>; span; children!( [expression(items)..] => spanned( span, @@ -1063,12 +1063,12 @@ make_parser! { ) )); - rule!(final_expression<ParsedSubExpr>; children!( + rule!(final_expression<ParsedExpr>; children!( [expression(e), EOI(_)] => e )); } -pub fn parse_expr(s: &str) -> ParseResult<ParsedSubExpr> { +pub fn parse_expr(s: &str) -> ParseResult<ParsedExpr> { let mut pairs = DhallParser::parse(Rule::final_expression, s)?; let rc_input = s.to_string().into(); let expr = EntryPoint::final_expression(rc_input, pairs.next().unwrap())?; diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index 256ea65..276590e 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -112,7 +112,7 @@ enum PrintPhase { // Wraps an Expr with a phase, so that phase selsction can be done // separate from the actual printing #[derive(Clone)] -struct PhasedExpr<'a, A>(&'a SubExpr<A>, PrintPhase); +struct PhasedExpr<'a, A>(&'a Expr<A>, PrintPhase); impl<'a, A: Display + Clone> Display for PhasedExpr<'a, A> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { @@ -126,7 +126,7 @@ impl<'a, A: Display + Clone> PhasedExpr<'a, A> { } } -impl<A: Display + Clone> Expr<A> { +impl<A: Display + Clone> RawExpr<A> { fn fmt_phase( &self, f: &mut fmt::Formatter, @@ -202,7 +202,7 @@ impl<A: Display + Clone> Expr<A> { } } -impl<A: Display + Clone> Display for SubExpr<A> { +impl<A: Display + Clone> Display for Expr<A> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.as_ref().fmt_phase(f, PrintPhase::Base) } diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index ce3468f..9fce42d 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -124,7 +124,7 @@ pub use value::Value; // A Dhall value. pub mod value { - use dhall::phase::{NormalizedSubExpr, Parsed, Typed}; + use dhall::phase::{NormalizedExpr, Parsed, Typed}; use dhall_syntax::Builtin; use super::de::{Error, Result}; @@ -148,7 +148,7 @@ pub mod value { }; Ok(Value(typed)) } - pub(crate) fn to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr(&self) -> NormalizedExpr { self.0.to_expr() } pub(crate) fn as_typed(&self) -> &Typed { diff --git a/serde_dhall/src/serde.rs b/serde_dhall/src/serde.rs index 94b7e6c..26708c1 100644 --- a/serde_dhall/src/serde.rs +++ b/serde_dhall/src/serde.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use dhall::phase::NormalizedSubExpr; +use dhall::phase::NormalizedExpr; use dhall_syntax::ExprF; use crate::de::{Deserialize, Error, Result}; @@ -15,7 +15,7 @@ where } } -struct Deserializer<'a>(Cow<'a, NormalizedSubExpr>); +struct Deserializer<'a>(Cow<'a, NormalizedExpr>); impl<'de: 'a, 'a> serde::de::IntoDeserializer<'de, Error> for Deserializer<'a> { type Deserializer = Deserializer<'a>; |