Fix post blank for timestamp date ranges.

This commit is contained in:
Tom Alexander 2023-12-15 11:38:52 -05:00
parent 28f12a04f7
commit 252be3e001
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 39 additions and 13 deletions

View File

@ -82,7 +82,7 @@ fn clock_timestamp<'b, 'g, 'r, 's>(
|(timestamp, duration)| (timestamp, duration.map(Into::<&str>::into)),
),
map(
parser_with_context!(inactive_timestamp)(context),
parser_with_context!(inactive_timestamp(true))(context),
|timestamp| (timestamp, None),
),
))(input)

View File

@ -53,8 +53,8 @@ pub(crate) fn timestamp<'b, 'g, 'r, 's>(
parser_with_context!(inactive_time_range_timestamp)(context),
parser_with_context!(active_date_range_timestamp)(context),
parser_with_context!(inactive_date_range_timestamp)(context),
parser_with_context!(active_timestamp)(context),
parser_with_context!(inactive_timestamp)(context),
parser_with_context!(active_timestamp(true))(context),
parser_with_context!(inactive_timestamp(true))(context),
))(input)
}
@ -126,13 +126,23 @@ fn sexp_end<'b, 'g, 'r, 's>(
alt((tag(")>"), recognize(one_of(">\n"))))(input)
}
const fn active_timestamp(
allow_post_blank: bool,
) -> impl for<'b, 'g, 'r, 's> Fn(
RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>,
) -> Res<OrgSource<'s>, Timestamp<'s>> {
move |context, input| impl_active_timestamp(context, input, allow_post_blank)
}
#[cfg_attr(
feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context))
)]
fn active_timestamp<'b, 'g, 'r, 's>(
fn impl_active_timestamp<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
allow_post_blank: bool,
) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, _) = tag("<")(input)?;
let (remaining, start) = date(context, remaining)?;
@ -160,8 +170,11 @@ fn active_timestamp<'b, 'g, 'r, 's>(
)))(remaining)?;
let (remaining, _) = tag(">")(remaining)?;
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let (remaining, post_blank) = if allow_post_blank {
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?
} else {
(remaining, None)
};
let source = get_consumed(input, remaining);
Ok((
@ -181,13 +194,23 @@ fn active_timestamp<'b, 'g, 'r, 's>(
))
}
pub(crate) const fn inactive_timestamp(
allow_post_blank: bool,
) -> impl for<'b, 'g, 'r, 's> Fn(
RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>,
) -> Res<OrgSource<'s>, Timestamp<'s>> {
move |context, input| impl_inactive_timestamp(context, input, allow_post_blank)
}
#[cfg_attr(
feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context))
)]
pub(crate) fn inactive_timestamp<'b, 'g, 'r, 's>(
fn impl_inactive_timestamp<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
allow_post_blank: bool,
) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, _) = tag("[")(input)?;
let (remaining, start) = date(context, remaining)?;
@ -215,8 +238,11 @@ pub(crate) fn inactive_timestamp<'b, 'g, 'r, 's>(
)))(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let (remaining, post_blank) = if allow_post_blank {
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?
} else {
(remaining, None)
};
let source = get_consumed(input, remaining);
Ok((
@ -244,10 +270,10 @@ fn active_date_range_timestamp<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, first_timestamp) = active_timestamp(context, input)?;
let (remaining, first_timestamp) = impl_active_timestamp(context, input, false)?;
// TODO: Does the space0 at the end of the active/inactive timestamp parsers cause this to be incorrect? I could use a look-behind to make sure the preceding character is not whitespace
let (remaining, _separator) = tag("--")(remaining)?;
let (remaining, second_timestamp) = active_timestamp(context, remaining)?;
let (remaining, second_timestamp) = impl_active_timestamp(context, remaining, false)?;
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
@ -335,10 +361,10 @@ pub(crate) fn inactive_date_range_timestamp<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, first_timestamp) = inactive_timestamp(context, input)?;
let (remaining, first_timestamp) = impl_inactive_timestamp(context, input, false)?;
// TODO: Does the space0 at the end of the active/inactive timestamp parsers cause this to be incorrect? I could use a look-behind to make sure the preceding character is not whitespace
let (remaining, _separator) = tag("--")(remaining)?;
let (remaining, second_timestamp) = inactive_timestamp(context, remaining)?;
let (remaining, second_timestamp) = impl_inactive_timestamp(context, remaining, false)?;
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;