summaryrefslogtreecommitdiff
path: root/dhall_core/src/core.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dhall_core/src/core.rs')
-rw-r--r--dhall_core/src/core.rs57
1 files changed, 20 insertions, 37 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs
index 481e949..9c96b2a 100644
--- a/dhall_core/src/core.rs
+++ b/dhall_core/src/core.rs
@@ -405,6 +405,7 @@ impl<S, A: Display> Display for Expr<S, A> {
}
}
+// WARNING: this may cause stack overflows when adding new variants
impl<S, A: Display> Expr<S, A> {
fn fmt_b(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use crate::Expr::*;
@@ -495,44 +496,26 @@ impl<S, A: Display> Expr<S, A> {
use crate::Expr::*;
match self {
// FIXME precedence
- &BinOp(BoolOr, ref a, ref b) => {
+ &BinOp(op, ref a, ref b) => {
a.fmt_d(f)?;
- f.write_str(" || ")?;
- b.fmt_c(f)
- }
- &BinOp(TextAppend, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" ++ ")?;
- b.fmt_c(f)
- }
- &BinOp(NaturalPlus, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" + ")?;
- b.fmt_c(f)
- }
- &BinOp(BoolAnd, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" && ")?;
- b.fmt_c(f)
- }
- &BinOp(Combine, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" ^ ")?;
- b.fmt_c(f)
- }
- &BinOp(NaturalTimes, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" * ")?;
- b.fmt_c(f)
- }
- &BinOp(BoolEQ, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" == ")?;
- b.fmt_c(f)
- }
- &BinOp(BoolNE, ref a, ref b) => {
- a.fmt_d(f)?;
- f.write_str(" != ")?;
+ write!(
+ f,
+ " {} ",
+ match op {
+ BoolOr => "||",
+ TextAppend => "++",
+ NaturalPlus => "+",
+ BoolAnd => "&&",
+ Combine => "^",
+ NaturalTimes => "*",
+ BoolEQ => "==",
+ BoolNE => "!=",
+ CombineTypes => "//\\",
+ ImportAlt => "?",
+ Prefer => "//",
+ ListAppend => "#",
+ }
+ )?;
b.fmt_c(f)
}
&Note(_, ref b) => b.fmt_c(f),