From 7d30b044a2c8c2cef8143b9e0ac763024c50026c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 24 Mar 2019 01:06:40 +0100 Subject: Refactor printer Avoids stupid stack overflows when adding variants, gets precedences right, and updates to latest grammar changes --- dhall_core/src/core.rs | 32 ++-- dhall_core/src/label.rs | 4 +- dhall_core/src/parser.rs | 4 +- dhall_core/src/printer.rs | 435 +++++++++++++++++++++++---------------------- dhall_generator/src/lib.rs | 6 +- 5 files changed, 249 insertions(+), 232 deletions(-) diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 502a9bc..0ea8c83 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -102,32 +102,34 @@ pub enum Const { #[derive(Debug, Clone, PartialEq, Eq)] pub struct V(pub Label, pub usize); -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +// Definition order must match precedence order for +// pretty-printing to work correctly +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum BinOp { - /// x && y` - BoolAnd, + /// x ? y + ImportAlt, /// x || y` BoolOr, - /// x == y` - BoolEQ, - /// x != y` - BoolNE, /// x + y` NaturalPlus, - /// x * y` - NaturalTimes, /// x ++ y` TextAppend, + /// x # y + ListAppend, + /// x && y` + BoolAnd, /// x ∧ y` Combine, - /// x //\\ y - CombineTypes, - /// x ? y - ImportAlt, /// x // y Prefer, - /// x # y - ListAppend, + /// x //\\ y + CombineTypes, + /// x * y` + NaturalTimes, + /// x == y` + BoolEQ, + /// x != y` + BoolNE, } /// Built-ins diff --git a/dhall_core/src/label.rs b/dhall_core/src/label.rs index 8b371af..9dc2816 100644 --- a/dhall_core/src/label.rs +++ b/dhall_core/src/label.rs @@ -18,8 +18,8 @@ impl<'a> From<&'a str> for Label { } } -impl From