From 3268e1fb66e2c9eab22572da034a0ac9b3087867 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 2 May 2019 22:15:47 +0200 Subject: Update dhall-lang submodule --- dhall_core/src/parser.rs | 23 ++++++++++++++++++++++- dhall_core/src/printer.rs | 28 ++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index fcf85bd..12383d4 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -2,6 +2,7 @@ use itertools::Itertools; use pest::iterators::Pair; use pest::Parser; pub use pest::Span; +use std::borrow::Cow; use std::collections::BTreeMap; use std::path::PathBuf; @@ -567,7 +568,27 @@ make_parser! { [posix_environment_variable(s)] => s, )); rule!(bash_environment_variable; captured_str!(s) => s.to_owned()); - rule!(posix_environment_variable; captured_str!(s) => s.to_owned()); + rule!(posix_environment_variable; children!( + [posix_environment_variable_character(chars)..] => { + chars.collect() + }, + )); + rule!(posix_environment_variable_character>; + captured_str!(s) => { + match s { + "\\\"" => Cow::Owned("\"".to_owned()), + "\\\\" => Cow::Owned("\\".to_owned()), + "\\a" => Cow::Owned("\u{0007}".to_owned()), + "\\b" => Cow::Owned("\u{0008}".to_owned()), + "\\f" => Cow::Owned("\u{000C}".to_owned()), + "\\n" => Cow::Owned("\n".to_owned()), + "\\r" => Cow::Owned("\r".to_owned()), + "\\t" => Cow::Owned("\t".to_owned()), + "\\v" => Cow::Owned("\u{000B}".to_owned()), + _ => Cow::Borrowed(s) + } + } + ); token_rule!(missing<()>); diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index 8b37b0f..704000a 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -351,7 +351,7 @@ impl Display for ImportHashed { use std::path::PathBuf; use FilePrefix::*; use ImportLocation::*; - let quoted = |s: &str| -> String { + let quoted_path_component = |s: &str| -> String { if s.chars().all(|c| c.is_ascii_alphanumeric()) { s.to_owned() } else { @@ -361,7 +361,7 @@ impl Display for ImportHashed { let fmt_path = |f: &mut fmt::Formatter, p: &PathBuf| { let res: String = p .iter() - .map(|c| quoted(c.to_string_lossy().as_ref())) + .map(|c| quoted_path_component(c.to_string_lossy().as_ref())) .join("/"); f.write_str(&res) }; @@ -387,8 +387,28 @@ impl Display for ImportHashed { write!(f, " using ({})", h)? } } - Env(e) => { - write!(f, "env:{}", quoted(e))?; + Env(s) => { + write!(f, "env:")?; + if s.chars().all(|c| c.is_ascii_alphanumeric()) { + write!(f, "{}", s)?; + } else { + write!(f, "\"")?; + for c in s.chars() { + match c { + '"' => f.write_str("\\\"")?, + '\\' => f.write_str("\\\\")?, + '\u{0007}' => f.write_str("\\a")?, + '\u{0008}' => f.write_str("\\b")?, + '\u{000C}' => f.write_str("\\f")?, + '\n' => f.write_str("\\n")?, + '\r' => f.write_str("\\r")?, + '\t' => f.write_str("\\t")?, + '\u{000B}' => f.write_str("\\v")?, + _ => write!(f, "{}", c)?, + } + } + write!(f, "\"")?; + } } Missing => { write!(f, "missing")?; -- cgit v1.2.3