summaryrefslogtreecommitdiff
path: root/dhall_syntax/src
diff options
context:
space:
mode:
authorNadrieril Feneanar2019-10-12 19:22:14 +0100
committerGitHub2019-10-12 19:22:14 +0100
commit8a8eeeac3b4f7761fd0916ee69d182597090039d (patch)
tree5613752829163cbdbcdb9ecec3b6889cfe827425 /dhall_syntax/src
parentd022cd7e807104ffed60a76058c4ccd478ac187a (diff)
parent88eadcfe795181a3fda138e92d7f787793248e5f (diff)
Merge pull request #99 from FintanH/fintan/canonicalize
Introduce Canonicalize
Diffstat (limited to '')
-rw-r--r--dhall_syntax/src/core/import.rs9
-rw-r--r--dhall_syntax/src/parser.rs12
-rw-r--r--dhall_syntax/src/printer.rs4
3 files changed, 15 insertions, 10 deletions
diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs
index 43597df..da3e99b 100644
--- a/dhall_syntax/src/core/import.rs
+++ b/dhall_syntax/src/core/import.rs
@@ -11,10 +11,15 @@ pub enum FilePrefix {
Home,
}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct FilePath {
+ pub file_path: Vec<String>,
+}
+
/// The location of import (i.e. local vs. remote vs. environment)
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ImportLocation<SubExpr> {
- Local(FilePrefix, Vec<String>),
+ Local(FilePrefix, FilePath),
Remote(URL<SubExpr>),
Env(String),
Missing,
@@ -24,7 +29,7 @@ pub enum ImportLocation<SubExpr> {
pub struct URL<SubExpr> {
pub scheme: Scheme,
pub authority: String,
- pub path: Vec<String>,
+ pub path: FilePath,
pub query: Option<String>,
pub headers: Option<SubExpr>,
}
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 71fab0f..f2dea53 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -429,10 +429,10 @@ impl DhallParser {
})
.collect())
}
- fn path(input: ParseInput) -> ParseResult<Vec<String>> {
+ fn path(input: ParseInput) -> ParseResult<FilePath> {
Ok(match_nodes!(input.into_children();
[path_component(components)..] => {
- components.collect()
+ FilePath { file_path: components.collect() }
}
))
}
@@ -449,19 +449,19 @@ impl DhallParser {
#[alias(local_path)]
fn parent_path(
input: ParseInput,
- ) -> ParseResult<(FilePrefix, Vec<String>)> {
+ ) -> ParseResult<(FilePrefix, FilePath)> {
Ok(match_nodes!(input.into_children();
[path(p)] => (FilePrefix::Parent, p)
))
}
#[alias(local_path)]
- fn here_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec<String>)> {
+ fn here_path(input: ParseInput) -> ParseResult<(FilePrefix, FilePath)> {
Ok(match_nodes!(input.into_children();
[path(p)] => (FilePrefix::Here, p)
))
}
#[alias(local_path)]
- fn home_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec<String>)> {
+ fn home_path(input: ParseInput) -> ParseResult<(FilePrefix, FilePath)> {
Ok(match_nodes!(input.into_children();
[path(p)] => (FilePrefix::Home, p)
))
@@ -469,7 +469,7 @@ impl DhallParser {
#[alias(local_path)]
fn absolute_path(
input: ParseInput,
- ) -> ParseResult<(FilePrefix, Vec<String>)> {
+ ) -> ParseResult<(FilePrefix, FilePath)> {
Ok(match_nodes!(input.into_children();
[path(p)] => (FilePrefix::Absolute, p)
))
diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs
index f3dc648..1e3b7f2 100644
--- a/dhall_syntax/src/printer.rs
+++ b/dhall_syntax/src/printer.rs
@@ -378,12 +378,12 @@ impl<SubExpr: Display> Display for Import<SubExpr> {
};
write!(f, "{}/", prefix)?;
let path: String =
- path.iter().map(|c| quote_if_needed(&*c)).join("/");
+ path.file_path.iter().map(|c| quote_if_needed(&*c)).join("/");
f.write_str(&path)?;
}
Remote(url) => {
write!(f, "{}://{}/", url.scheme, url.authority,)?;
- let path: String = url.path.iter().join("/");
+ let path: String = url.path.file_path.iter().join("/");
f.write_str(&path)?;
if let Some(q) = &url.query {
write!(f, "?{}", q)?