diff options
author | Nadrieril | 2019-05-04 17:59:05 +0200 |
---|---|---|
committer | Nadrieril | 2019-05-04 17:59:05 +0200 |
commit | 4c159640e5ee77ffa48b85a5bffa56350cf933ef (patch) | |
tree | c0ff9231ed28538f4f1dc13d8e6347e3c14a06b5 /dhall_syntax/src/printer.rs | |
parent | 0e5c93c398645d39fceb98d054f1a7e67025b4fd (diff) |
Make SubExpr generic in the variable labels type
Diffstat (limited to 'dhall_syntax/src/printer.rs')
-rw-r--r-- | dhall_syntax/src/printer.rs | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index e3b180b..9cc1b46 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -3,7 +3,9 @@ use itertools::Itertools; use std::fmt::{self, Display}; /// Generic instance that delegates to subexpressions -impl<SE: Display + Clone, E: Display> Display for ExprF<SE, Label, E> { +impl<SE: Display + Clone, L: Display + Clone, E: Display> Display + for ExprF<SE, L, E> +{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { use crate::ExprF::*; match self { @@ -13,9 +15,10 @@ impl<SE: Display + Clone, E: Display> Display for ExprF<SE, Label, E> { BoolIf(a, b, c) => { write!(f, "if {} then {} else {}", a, b, c)?; } - Pi(a, b, c) if &String::from(a) == "_" => { - write!(f, "{} → {}", b, c)?; - } + // TODO: arrow type + // Pi(a, b, c) if &String::from(a) == "_" => { + // write!(f, "{} → {}", b, c)?; + // } Pi(a, b, c) => { write!(f, "∀({} : {}) → {}", a, b, c)?; } @@ -124,21 +127,25 @@ 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, S, A>(&'a SubExpr<S, A>, PrintPhase); +struct PhasedExpr<'a, L, S, A>(&'a SubExpr<L, S, A>, PrintPhase); -impl<'a, S: Clone, A: Display + Clone> Display for PhasedExpr<'a, S, A> { +impl<'a, L: Display + Clone, S: Clone, A: Display + Clone> Display + for PhasedExpr<'a, L, S, A> +{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.0.as_ref().fmt_phase(f, self.1) } } -impl<'a, S: Clone, A: Display + Clone> PhasedExpr<'a, S, A> { - fn phase(self, phase: PrintPhase) -> PhasedExpr<'a, S, A> { +impl<'a, L: Display + Clone, S: Clone, A: Display + Clone> + PhasedExpr<'a, L, S, A> +{ + fn phase(self, phase: PrintPhase) -> PhasedExpr<'a, L, S, A> { PhasedExpr(self.0, phase) } } -impl<S: Clone, A: Display + Clone> Expr<S, A> { +impl<L: Display + Clone, S: Clone, A: Display + Clone> Expr<L, S, A> { fn fmt_phase( &self, f: &mut fmt::Formatter, @@ -172,11 +179,12 @@ impl<S: Clone, A: Display + Clone> Expr<S, A> { // Annotate subexpressions with the appropriate phase, defaulting to Base let phased_self = match self.map_ref_simple(|e| PhasedExpr(e, Base)) { Pi(a, b, c) => { - if &String::from(&a) == "_" { - Pi(a, b.phase(Operator), c) - } else { - Pi(a, b, c) - } + // TODO: arrow type + // if &String::from(&a) == "_" { + // Pi(a, b.phase(Operator), c) + // } else { + Pi(a, b, c) + // } } Merge(a, b, c) => Merge( a.phase(Import), @@ -212,7 +220,9 @@ impl<S: Clone, A: Display + Clone> Expr<S, A> { } } -impl<S: Clone, A: Display + Clone> Display for SubExpr<S, A> { +impl<L: Display + Clone, S: Clone, A: Display + Clone> Display + for SubExpr<L, S, A> +{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.as_ref().fmt_phase(f, PrintPhase::Base) } @@ -474,9 +484,9 @@ impl Display for Scheme { } } -impl<Label: Display> Display for V<Label> { +impl<Label: Display> Display for Var<Label> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - let V(x, n) = self; + let Var(x, n) = self; x.fmt(f)?; if *n != 0 { write!(f, "@{}", n)?; |