Switch to passing in the exit matcher from a higher context to reduce the permutations of functions.

This commit is contained in:
Tom Alexander 2023-07-27 19:52:35 -04:00
parent 529418a9d1
commit c5f81298ba
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -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)?;