summaryrefslogtreecommitdiff
path: root/dhall_syntax/src/parser.rs
diff options
context:
space:
mode:
authorFintanH2019-08-12 22:22:24 +0100
committerFintanH2019-08-12 22:22:24 +0100
commit405bc3d80c0e169ea74dd12422b9504b7383dab3 (patch)
treef1f71797b0470375b12717a4663c1ea2ca1f96fd /dhall_syntax/src/parser.rs
parent8ec422f2319360f986950fcb9aae4bcf65a9c1e2 (diff)
Refactor of File to be the combination of Directory and the file name,
where Directory is the Vector of component paths. The refactor meant changing some sections of the code where we were parsing and manipulating Files/Directories. This also includes a new trait Canonicalization which is needed for import logic.
Diffstat (limited to '')
-rw-r--r--dhall_syntax/src/parser.rs41
1 files changed, 28 insertions, 13 deletions
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 9d9a374..7675622 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -146,6 +146,14 @@ fn debug_pair(pair: Pair<Rule>) -> String {
s
}
+fn to_file(path: Vec<String>) -> Result<File, String> {
+ let mut path = path;
+ let file_name: Option<String> = path.pop();
+ let file = file_name.ok_or("Empty file path was provided")?;
+ let directory = Directory { components: path };
+ Ok(File { directory: directory, file: file })
+}
+
macro_rules! make_parser {
(@pattern, rule, $name:ident) => (Rule::$name);
(@pattern, token_rule, $name:ident) => (Rule::$name);
@@ -589,19 +597,25 @@ make_parser! {
});
rule!(http_raw<URL>; children!(
- [scheme(sch), authority(auth), path(p)] => URL {
- scheme: sch,
- authority: auth,
- path: p,
- query: None,
- headers: None,
+ [scheme(sch), authority(auth), path(p)] => {
+ let file = to_file(p)?;
+ URL {
+ scheme: sch,
+ authority: auth,
+ path: file,
+ query: None,
+ headers: None,
+ }
},
- [scheme(sch), authority(auth), path(p), query(q)] => URL {
- scheme: sch,
- authority: auth,
- path: p,
- query: Some(q),
- headers: None,
+ [scheme(sch), authority(auth), path(p), query(q)] => {
+ let file = to_file(p)?;
+ URL {
+ scheme: sch,
+ authority: auth,
+ path: file,
+ query: Some(q),
+ headers: None,
+ }
},
));
@@ -655,7 +669,8 @@ make_parser! {
ImportLocation::Remote(url)
},
[local((prefix, p))] => {
- ImportLocation::Local(prefix, p)
+ let file = to_file(p)?;
+ ImportLocation::Local(prefix, file)
},
));