From f5d2151d35942b957230c3081a928af3619d9400 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 31 Mar 2019 18:47:34 +0200 Subject: Make SubExpr a newtype --- dhall_core/src/printer.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'dhall_core/src/printer.rs') diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index 1d1b063..b153d1b 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -8,6 +8,12 @@ impl Display for Expr { } } +impl Display for SubExpr { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.as_ref().fmt(f) + } +} + // There is a one-to-one correspondence between the formatter and the grammar. Each phase is // named after a corresponding grammar group, and the structure of the formatter reflects // the relationship between the corresponding grammar rules. This leads to the nice property -- cgit v1.2.3 From 7374d0524ccd53b256107667b213597c05720d2d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 31 Mar 2019 19:08:08 +0200 Subject: Move recursion out of Expr --- dhall_core/src/printer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dhall_core/src/printer.rs') diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index b153d1b..b7d7506 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -35,7 +35,7 @@ impl Expr { f: &mut fmt::Formatter, phase: PrintPhase, ) -> Result<(), fmt::Error> { - use crate::Expr::*; + use crate::ExprF::*; use PrintPhase::*; match self { _ if phase == Paren => { @@ -143,7 +143,7 @@ impl Expr { write!(f, " : ")?; b.fmt(f)?; } - Expr::BinOp(op, a, b) => { + ExprF::BinOp(op, a, b) => { // Precedence is magically handled by the ordering of BinOps. if phase > PrintPhase::BinOp(*op) { return self.fmt_phase(f, Paren); @@ -152,7 +152,7 @@ impl Expr { write!(f, " {} ", op)?; b.fmt_phase(f, PrintPhase::BinOp(*op))?; } - Expr::App(a, args) => { + ExprF::App(a, args) => { if phase > PrintPhase::App { return self.fmt_phase(f, Paren); } @@ -239,7 +239,7 @@ where f.write_str(close) } -impl Display for InterpolatedText { +impl Display for InterpolatedText { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { f.write_str("\"")?; for x in self.iter() { -- cgit v1.2.3 From 737472abf9c0ca2030ab8c2bb0b1d4af41167183 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 31 Mar 2019 19:37:29 +0200 Subject: Remove evil Deref impl --- dhall_core/src/printer.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'dhall_core/src/printer.rs') diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index b7d7506..fb3b8e8 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -217,6 +217,16 @@ impl Expr { } } +impl SubExpr { + fn fmt_phase( + &self, + f: &mut fmt::Formatter, + phase: PrintPhase, + ) -> Result<(), fmt::Error> { + self.0.as_ref().fmt_phase(f, phase) + } +} + fn fmt_list( open: &str, sep: &str, -- cgit v1.2.3 From 62970fd2010b01260cf45a1f2a6a582c6a8c0c12 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 31 Mar 2019 21:04:10 +0200 Subject: Make Expr generic in Label --- dhall_core/src/printer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall_core/src/printer.rs') diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index fb3b8e8..746b863 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -462,7 +462,7 @@ impl Display for Scheme { } } -impl Display for V { +impl Display for V