From 5a2538d174fd36a8ed7f4fa344b9583fc48bd977 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 11 Feb 2020 13:12:13 +0000 Subject: Remove the Embed variant from ExprKind --- dhall/src/syntax/text/printer.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'dhall/src/syntax/text/printer.rs') diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 06dd70f..d1c9588 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -19,17 +19,17 @@ enum PrintPhase { // Wraps an Expr with a phase, so that phase selection can be done separate from the actual // printing. #[derive(Clone)] -struct PhasedExpr<'a, E>(&'a Expr, PrintPhase); +struct PhasedExpr<'a>(&'a Expr, PrintPhase); -impl<'a, E: Display + Clone> PhasedExpr<'a, E> { - fn phase(self, phase: PrintPhase) -> PhasedExpr<'a, E> { +impl<'a> PhasedExpr<'a> { + fn phase(self, phase: PrintPhase) -> PhasedExpr<'a> { PhasedExpr(self.0, phase) } } -impl UnspannedExpr { +impl UnspannedExpr { // Annotate subexpressions with the appropriate phase, defaulting to Base - fn annotate_with_phases<'a>(&'a self) -> ExprKind, E> { + fn annotate_with_phases<'a>(&'a self) -> ExprKind> { use crate::syntax::ExprKind::*; use PrintPhase::*; let with_base = self.map_ref(|e| PhasedExpr(e, Base)); @@ -134,7 +134,7 @@ where } /// Generic instance that delegates to subexpressions -impl Display for ExprKind { +impl Display for ExprKind { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { use crate::syntax::ExprKind::*; match self { @@ -232,19 +232,18 @@ impl Display for ExprKind { write!(f, "{}::{}", a, b)?; } Import(a) => a.fmt(f)?, - Embed(a) => a.fmt(f)?, } Ok(()) } } -impl Display for Expr { +impl Display for Expr { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.as_ref().fmt_phase(f, PrintPhase::Base) } } -impl<'a, E: Display + Clone> Display for PhasedExpr<'a, E> { +impl<'a> Display for PhasedExpr<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.0.as_ref().fmt_phase(f, self.1) } -- cgit v1.2.3 From 40bee3cdcb9ac0c76996feeceb6ca160a6bd8b42 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 11 Feb 2020 19:04:44 +0000 Subject: Introduce LitKind to factor out common enum nodes --- dhall/src/syntax/text/printer.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'dhall/src/syntax/text/printer.rs') diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index d1c9588..8891d41 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -196,15 +196,7 @@ impl Display for ExprKind { Var(a) => a.fmt(f)?, Const(k) => k.fmt(f)?, Builtin(v) => v.fmt(f)?, - BoolLit(true) => f.write_str("True")?, - BoolLit(false) => f.write_str("False")?, - NaturalLit(a) => a.fmt(f)?, - IntegerLit(a) if *a >= 0 => { - f.write_str("+")?; - a.fmt(f)?; - } - IntegerLit(a) => a.fmt(f)?, - DoubleLit(a) => a.fmt(f)?, + Lit(a) => a.fmt(f)?, TextLit(a) => a.fmt(f)?, RecordType(a) if a.is_empty() => f.write_str("{}")?, RecordType(a) => fmt_list("{ ", ", ", " }", a, f, |(k, t), f| { @@ -239,7 +231,25 @@ impl Display for ExprKind { impl Display for Expr { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - self.as_ref().fmt_phase(f, PrintPhase::Base) + self.kind().fmt_phase(f, PrintPhase::Base) + } +} + +impl Display for LitKind { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + use LitKind::*; + match self { + Bool(true) => f.write_str("True")?, + Bool(false) => f.write_str("False")?, + Natural(a) => a.fmt(f)?, + Integer(a) if *a >= 0 => { + f.write_str("+")?; + a.fmt(f)?; + } + Integer(a) => a.fmt(f)?, + Double(a) => a.fmt(f)?, + } + Ok(()) } } -- cgit v1.2.3