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