From 405bc3d80c0e169ea74dd12422b9504b7383dab3 Mon Sep 17 00:00:00 2001 From: FintanH Date: Mon, 12 Aug 2019 22:22:24 +0100 Subject: 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. --- dhall_syntax/src/parser.rs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'dhall_syntax/src/parser.rs') 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) -> String { s } +fn to_file(path: Vec) -> Result { + let mut path = path; + let file_name: Option = 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; 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) }, )); -- cgit v1.2.3