From b7120a34de0224b0810caaf26d74db21b0c89778 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 7 Apr 2020 20:21:26 -0400 Subject: [PATCH] Forking the partial code for reuse as helper code --- src/parser/parser.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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("|"),