From e2f03de2975346fc8af990e2a4d8e3d129c6465e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 7 Apr 2020 19:51:06 -0400 Subject: [PATCH] Integrated the partial parser into the rest of the grammar --- src/parser/parser.rs | 62 ++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index d724ead..828991f 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -92,8 +92,7 @@ struct NamedBlock<'a> { #[derive(Clone, Debug, PartialEq)] struct ParameterizedBlock<'a> { name: String, - contents: Option>, - params: Vec<&'a str>, + params: Vec>, } #[derive(Clone, Debug, PartialEq)] @@ -342,8 +341,8 @@ where let (i, (name, params)) = delimited( tag(open_matcher), tuple(( - key, - opt(preceded(space1, separated_list(space1, is_not(" ")))), + alt((map(key, String::from), quoted_string)), + opt(preceded(space1, separated_list(space1, key_value_pair))), )), tag("/}"), )(i)?; @@ -351,8 +350,7 @@ where Ok(( i, constructor(ParameterizedBlock { - name: name.to_owned(), - contents: None, + name: name, params: params.unwrap_or(Vec::new()), }), )) @@ -691,46 +689,24 @@ mod tests { } #[test] - fn test_self_closing_unquoted_partial() { + fn test_unquoted_partial() { assert_eq!( - delimited( - tag("{>"), - tuple(( - key, - opt(preceded(space1, separated_list(space1, key_value_pair))), - )), - tag("/}"), - )("{>foo bar=baz/}"), + dust_tag(r#"{>foo bar=baz animal="cat"/}"#), Ok(( "", - ( - "foo", - Some(vec![KVPair { - key: "bar", - value: RValue::RVPath(Path { keys: vec!["baz"] }) - }]) - ) - )) - ); - - assert_eq!( - delimited( - tag("{>"), - tuple(( - key, - opt(preceded(space1, separated_list(space1, key_value_pair))), - )), - tag("/}"), - )(r#"{>foo bar="ba\"z"/}"#), - Ok(( - "", - ( - "foo", - Some(vec![KVPair { - key: "bar", - value: RValue::RVString("ba\"z".to_owned()) - }]) - ) + DustTag::DTPartial(ParameterizedBlock { + name: "foo".to_owned(), + params: vec![ + KVPair { + key: "bar", + value: RValue::RVPath(Path { keys: vec!["baz"] }) + }, + KVPair { + key: "animal", + value: RValue::RVString("cat".to_owned()) + } + ] + }) )) ); }