Forking the partial code for reuse as helper code

This commit is contained in:
Tom Alexander 2020-04-07 20:21:26 -04:00
parent ad33f98404
commit b7120a34de
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 28 additions and 1 deletions

View File

@ -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("|"),