Pull the calls for the DustTag constructor up out of parameterized_block.
This commit is contained in:
parent
0ca17e0885
commit
2527baeff4
@ -224,12 +224,21 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
||||
named_block("{+", DustTag::DTBlock),
|
||||
named_block("{<", DustTag::DTInlinePartial),
|
||||
partial("{>", DustTag::DTPartial),
|
||||
parameterized_block("{@", "gte", DustTag::DTHelperGreaterThanOrEquals),
|
||||
parameterized_block("{@", "lte", DustTag::DTHelperLessThanOrEquals),
|
||||
parameterized_block("{@", "eq", DustTag::DTHelperEquals),
|
||||
parameterized_block("{@", "ne", DustTag::DTHelperNotEquals),
|
||||
parameterized_block("{@", "gt", DustTag::DTHelperGreaterThan),
|
||||
parameterized_block("{@", "lt", DustTag::DTHelperLessThan),
|
||||
map(
|
||||
parameterized_block("{@", "gte"),
|
||||
DustTag::DTHelperGreaterThanOrEquals,
|
||||
),
|
||||
map(
|
||||
parameterized_block("{@", "lte"),
|
||||
DustTag::DTHelperLessThanOrEquals,
|
||||
),
|
||||
map(parameterized_block("{@", "eq"), DustTag::DTHelperEquals),
|
||||
map(parameterized_block("{@", "ne"), DustTag::DTHelperNotEquals),
|
||||
map(
|
||||
parameterized_block("{@", "gt"),
|
||||
DustTag::DTHelperGreaterThan,
|
||||
),
|
||||
map(parameterized_block("{@", "lt"), DustTag::DTHelperLessThan),
|
||||
))(i)
|
||||
}
|
||||
|
||||
@ -460,28 +469,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn parameterized_block<'a, F>(
|
||||
fn parameterized_block<'a>(
|
||||
open_matcher: &'static str,
|
||||
tag_name: &'static str,
|
||||
constructor: F,
|
||||
) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||
where
|
||||
F: Copy + Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||
{
|
||||
) -> impl FnMut(&'a str) -> IResult<&'a str, ParameterizedBlock<'a>> {
|
||||
alt((
|
||||
parameterized_block_with_body(open_matcher, tag_name, constructor),
|
||||
parameterized_self_closing_block(open_matcher, tag_name, constructor),
|
||||
parameterized_block_with_body(open_matcher, tag_name),
|
||||
parameterized_self_closing_block(open_matcher, tag_name),
|
||||
))
|
||||
}
|
||||
|
||||
fn parameterized_block_with_body<'a, F>(
|
||||
fn parameterized_block_with_body<'a>(
|
||||
open_matcher: &'static str,
|
||||
tag_name: &'static str,
|
||||
constructor: F,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||
where
|
||||
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||
{
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, ParameterizedBlock<'a>> {
|
||||
move |i: &'a str| {
|
||||
let (i, (name, maybe_explicit_context, params, inner, maybe_else, _closing_name)) =
|
||||
tuple((
|
||||
@ -502,25 +503,21 @@ where
|
||||
|
||||
Ok((
|
||||
i,
|
||||
constructor(ParameterizedBlock {
|
||||
ParameterizedBlock {
|
||||
name: name,
|
||||
explicit_context: maybe_explicit_context,
|
||||
params: params.unwrap_or(Vec::new()),
|
||||
contents: inner,
|
||||
else_contents: maybe_else.flatten(),
|
||||
}),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn parameterized_self_closing_block<'a, F>(
|
||||
fn parameterized_self_closing_block<'a>(
|
||||
open_matcher: &'static str,
|
||||
tag_name: &'static str,
|
||||
constructor: F,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||
where
|
||||
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||
{
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, ParameterizedBlock<'a>> {
|
||||
move |i: &'a str| {
|
||||
let (i, (name, maybe_explicit_context, params)) = delimited(
|
||||
tag(open_matcher),
|
||||
@ -538,13 +535,13 @@ where
|
||||
|
||||
Ok((
|
||||
i,
|
||||
constructor(ParameterizedBlock {
|
||||
ParameterizedBlock {
|
||||
name: name,
|
||||
explicit_context: maybe_explicit_context,
|
||||
params: params.unwrap_or(Vec::new()),
|
||||
contents: None,
|
||||
else_contents: None,
|
||||
}),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user