summaryrefslogtreecommitdiff
path: root/dhall_core/src/printer.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-22 00:01:30 +0100
committerNadrieril2019-03-22 00:01:30 +0100
commitfe38fd6a8859447a154a5698a3e21d9203262be2 (patch)
tree814b0db038315f4b193374a9f5f9e672941bb0c3 /dhall_core/src/printer.rs
parent66e7c7750844bc976f23616c4a0103e778bdf4bd (diff)
Parse a lot more of the import types
Diffstat (limited to '')
-rw-r--r--dhall_core/src/printer.rs49
1 files changed, 48 insertions, 1 deletions
diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs
index bd38863..7b108d5 100644
--- a/dhall_core/src/printer.rs
+++ b/dhall_core/src/printer.rs
@@ -1,4 +1,5 @@
use crate::*;
+use itertools::Itertools;
use std::fmt::{self, Display};
// There used to be a one-to-one correspondence between the formatters in this section
@@ -286,8 +287,25 @@ impl Display for Const {
impl Display for Import {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ use std::path::PathBuf;
use FilePrefix::*;
use ImportLocation::*;
+ use ImportMode::*;
+ let quoted = |s: &str| -> String {
+ if s.chars().all(|c| c.is_ascii_alphanumeric()) {
+ s.to_owned()
+ } else {
+ format!("\"{}\"", s)
+ }
+ };
+ let fmt_path = |f: &mut fmt::Formatter, p: &PathBuf| {
+ let res: String = p
+ .iter()
+ .map(|c| quoted(c.to_string_lossy().as_ref()))
+ .join("/");
+ f.write_str(&res)
+ };
+
match &self.location {
Local(prefix, path) => {
let prefix = match prefix {
@@ -296,9 +314,28 @@ impl Display for Import {
Home => "~",
Absolute => "",
};
- write!(f, "{}/{}", prefix, path.to_str().unwrap())
+ write!(f, "{}/", prefix)?;
+ fmt_path(f, path)?;
+ }
+ Remote(url) => {
+ write!(f, "{}://{}/", url.scheme, url.authority,)?;
+ fmt_path(f, &url.path)?;
+ if let Some(q) = &url.query {
+ write!(f, "?{}", q)?
+ }
}
+ Env(e) => {
+ write!(f, "env:{}", quoted(e))?;
+ }
+ Missing => {
+ write!(f, "missing")?;
+ }
+ }
+ match self.mode {
+ Code => {}
+ RawText => write!(f, " as Text")?,
}
+ Ok(())
}
}
@@ -339,6 +376,16 @@ impl Display for Builtin {
}
}
+impl Display for Scheme {
+ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ use crate::Scheme::*;
+ f.write_str(match *self {
+ HTTP => "http",
+ HTTPS => "https",
+ })
+ }
+}
+
impl Display for V {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let V(ref x, ref n) = *self;