Switch to passing in the exit matcher from a higher context to reduce the permutations of functions.
This commit is contained in:
parent
529418a9d1
commit
c5f81298ba
@ -82,8 +82,13 @@ fn active_timestamp<'r, 's>(
|
||||
) -> Res<&'s str, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("<")(input)?;
|
||||
let (remaining, _date) = date(context, remaining)?;
|
||||
let time_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &active_time_rest_end,
|
||||
}));
|
||||
let (remaining, _time) =
|
||||
opt(tuple((space1, parser_with_context!(active_time)(context))))(remaining)?;
|
||||
opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?;
|
||||
let (remaining, _repeater) =
|
||||
opt(tuple((space1, parser_with_context!(repeater)(context))))(remaining)?;
|
||||
let (remaining, _warning_delay) = opt(tuple((
|
||||
@ -184,29 +189,20 @@ fn dayname_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn active_time<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn time<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let (remaining, _hour) =
|
||||
verify(digit1, |hour: &str| hour.len() >= 1 && hour.len() <= 2)(input)?;
|
||||
let (remaining, _) = tag(":")(remaining)?;
|
||||
let (remaining, _minute) = verify(digit1, |minute: &str| minute.len() == 2)(remaining)?;
|
||||
let (remaining, _time_rest) = opt(parser_with_context!(active_time_rest)(context))(remaining)?;
|
||||
let (remaining, _time_rest) = opt(parser_with_context!(time_rest)(context))(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, source))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn active_time_rest<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &active_time_rest_end,
|
||||
}));
|
||||
|
||||
fn time_rest<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let (remaining, body) = recognize(verify(
|
||||
many_till(
|
||||
anychar,
|
||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
||||
),
|
||||
many_till(anychar, parser_with_context!(exit_matcher_parser)(context)),
|
||||
|(body, _end_contents)| !body.is_empty(),
|
||||
))(input)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user