From 4b99a3fb46191a83fa8551f21b98cff689bbb338 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Mar 2019 22:08:23 +0100 Subject: Improve import handling in parser --- dhall_core/src/parser.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'dhall_core/src/parser.rs') diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 7de75d2..865e791 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -12,7 +12,6 @@ use crate::*; // their own crate because they are quite general and useful. For now they // are here and hopefully you can figure out how they work. -type ParsedExpr = crate::ParsedExpr; type ParsedText = InterpolatedText; type ParsedTextContents<'a> = InterpolatedTextContents<'a, X, Import>; @@ -370,9 +369,21 @@ make_parser! { } ); - rule!(path; - captured_str!(s) => (".".to_owned() + s).into() - ); + rule!(unquoted_path_component<&'a str>; captured_str!(s) => s); + rule!(quoted_path_component<&'a str>; captured_str!(s) => s); + rule!(path_component<&'a str>; children!( + [unquoted_path_component(s)] => s, + [quoted_path_component(s)] => s, + )); + rule!(path; children!( + [path_component(components..)] => { + let mut path = PathBuf::new(); + for s in components { + path.push(s); + } + path + } + )); rule_group!(local_raw<(FilePrefix, PathBuf)>); @@ -728,7 +739,7 @@ make_parser! { )); } -pub fn parse_expr(s: &str) -> ParseResult> { +pub fn parse_expr(s: &str) -> ParseResult { let mut pairs = DhallParser::parse(Rule::final_expression, s)?; let expr = parse_any(pairs.next().unwrap())?; assert_eq!(pairs.next(), None); -- cgit v1.2.3