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 From e73f822b6972e8fa2e72b56ff5378b91bea1a5e6 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 2 Sep 2019 21:17:00 +0100 Subject: Remove the notion of Directory and have File be the vector of components --- dhall_syntax/src/parser.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'dhall_syntax/src/parser.rs') diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index a2495ee..71d0936 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -147,14 +147,6 @@ 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); @@ -638,22 +630,20 @@ make_parser! { }); rule!(http_raw; children!( - [scheme(sch), authority(auth), path(p)] => { - let file = to_file(p)?; + [scheme(sch), authority(auth), path(file_path)] => { URL { scheme: sch, authority: auth, - path: file, + path: File { file_path }, query: None, headers: None, } }, - [scheme(sch), authority(auth), path(p), query(q)] => { - let file = to_file(p)?; + [scheme(sch), authority(auth), path(file_path), query(q)] => { URL { scheme: sch, authority: auth, - path: file, + path: File { file_path }, query: Some(q), headers: None, } @@ -709,9 +699,8 @@ make_parser! { [http(url)] => { ImportLocation::Remote(url) }, - [local((prefix, p))] => { - let file = to_file(p)?; - ImportLocation::Local(prefix, file) + [local((prefix, file_path))] => { + ImportLocation::Local(prefix, File { file_path }) }, )); -- cgit v1.2.3 From 4edaf0814868e604eed5cfd594ea3f448ca90678 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 3 Sep 2019 14:42:30 +0100 Subject: Move Canonicalize into resolve. Rename File to FilePath and have more consistent naming. --- dhall_syntax/src/parser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dhall_syntax/src/parser.rs') diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index b70a236..52b3760 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -729,7 +729,7 @@ make_parser! { [scheme(sch), authority(auth), path(file_path)] => URL { scheme: sch, authority: auth, - path: File { file_path }, + path: FilePath { file_path }, query: None, headers: None, }, @@ -737,7 +737,7 @@ make_parser! { URL { scheme: sch, authority: auth, - path: File { file_path }, + path: FilePath { file_path }, query: Some(q), headers: None, } @@ -794,7 +794,7 @@ make_parser! { ImportLocation::Remote(url) }, [local((prefix, file_path))] => { - ImportLocation::Local(prefix, File { file_path }) + ImportLocation::Local(prefix, FilePath { file_path }) }, )); -- cgit v1.2.3