diff --git a/src/parser/parser.rs b/src/parser/parser.rs index e9e2683..3233178 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -136,7 +136,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> { conditional("{^", DustTag::DTNotExists), named_block("{+", DustTag::DTBlock), named_block("{<", DustTag::DTInlinePartial), - parameterized_self_closing_block("{>", DustTag::DTPartial), + partial("{>", DustTag::DTPartial), ))(i) } @@ -357,6 +357,33 @@ where } } +fn partial<'a, F>( + open_matcher: &'static str, + constructor: F, +) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> +where + F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>, +{ + move |i: &'a str| { + let (i, (name, params)) = delimited( + tag(open_matcher), + tuple(( + alt((map(key, String::from), quoted_string)), + opt(preceded(space1, separated_list(space1, key_value_pair))), + )), + tag("/}"), + )(i)?; + + Ok(( + i, + constructor(ParameterizedBlock { + name: name, + params: params.unwrap_or(Vec::new()), + }), + )) + } +} + fn filter(i: &str) -> IResult<&str, Filter> { preceded( tag("|"),