From 8110651ccf498bcf3f0cd55f3b1730d9972cf254 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 22 Mar 2019 18:12:13 +0100 Subject: Handle quoted labels --- dhall_core/src/printer.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'dhall_core/src/printer.rs') diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index 7b108d5..508c1c8 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -285,6 +285,21 @@ impl Display for Const { } } +impl Display for Label { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + let s = String::from(self.clone()); + let is_keyword = |s| match s { + "let" | "in" | "if" | "then" | "else" => true, + _ => false, + }; + if s.chars().all(|c| c.is_ascii_alphanumeric()) && !is_keyword(&s) { + write!(f, "{}", s) + } else { + write!(f, "`{}`", s) + } + } +} + impl Display for Import { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { use std::path::PathBuf; -- cgit v1.2.3