Integrated the partial parser into the rest of the grammar

This commit is contained in:
Tom Alexander 2020-04-07 19:51:06 -04:00
parent 8bfa622c4c
commit e2f03de297
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 19 additions and 43 deletions

View File

@ -92,8 +92,7 @@ struct NamedBlock<'a> {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
struct ParameterizedBlock<'a> { struct ParameterizedBlock<'a> {
name: String, name: String,
contents: Option<Body<'a>>, params: Vec<KVPair<'a>>,
params: Vec<&'a str>,
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
@ -342,8 +341,8 @@ where
let (i, (name, params)) = delimited( let (i, (name, params)) = delimited(
tag(open_matcher), tag(open_matcher),
tuple(( tuple((
key, alt((map(key, String::from), quoted_string)),
opt(preceded(space1, separated_list(space1, is_not(" ")))), opt(preceded(space1, separated_list(space1, key_value_pair))),
)), )),
tag("/}"), tag("/}"),
)(i)?; )(i)?;
@ -351,8 +350,7 @@ where
Ok(( Ok((
i, i,
constructor(ParameterizedBlock { constructor(ParameterizedBlock {
name: name.to_owned(), name: name,
contents: None,
params: params.unwrap_or(Vec::new()), params: params.unwrap_or(Vec::new()),
}), }),
)) ))
@ -691,46 +689,24 @@ mod tests {
} }
#[test] #[test]
fn test_self_closing_unquoted_partial() { fn test_unquoted_partial() {
assert_eq!( assert_eq!(
delimited( dust_tag(r#"{>foo bar=baz animal="cat"/}"#),
tag("{>"),
tuple((
key,
opt(preceded(space1, separated_list(space1, key_value_pair))),
)),
tag("/}"),
)("{>foo bar=baz/}"),
Ok(( Ok((
"", "",
( DustTag::DTPartial(ParameterizedBlock {
"foo", name: "foo".to_owned(),
Some(vec![KVPair { params: vec![
key: "bar", KVPair {
value: RValue::RVPath(Path { keys: vec!["baz"] }) key: "bar",
}]) value: RValue::RVPath(Path { keys: vec!["baz"] })
) },
)) KVPair {
); key: "animal",
value: RValue::RVString("cat".to_owned())
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())
}])
)
)) ))
); );
} }