summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-05-02 22:15:47 +0200
committerNadrieril2019-05-02 22:15:47 +0200
commit3268e1fb66e2c9eab22572da034a0ac9b3087867 (patch)
tree0f8dd6097f7e4e11ba69934dbedba4e6de320ce2 /dhall_core
parent69d310da1e4c4563ce41424f776879102b62d9a0 (diff)
Update dhall-lang submodule
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/parser.rs23
-rw-r--r--dhall_core/src/printer.rs28
2 files changed, 46 insertions, 5 deletions
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<String>; captured_str!(s) => s.to_owned());
- rule!(posix_environment_variable<String>; captured_str!(s) => s.to_owned());
+ rule!(posix_environment_variable<String>; children!(
+ [posix_environment_variable_character(chars)..] => {
+ chars.collect()
+ },
+ ));
+ rule!(posix_environment_variable_character<Cow<'a, str>>;
+ 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")?;