Check exit matcher after each space consumed for object trailing whitespace.

Since description list tags need to end with a space unconsumed for " ::", we need to check the exit matcher after each space consumed.
This commit is contained in:
Tom Alexander 2023-09-08 19:29:31 -04:00
parent b04341882c
commit ceb722e476
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -8,6 +8,7 @@ use nom::combinator::not;
use nom::combinator::opt; use nom::combinator::opt;
use nom::combinator::peek; use nom::combinator::peek;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many0; use nom::multi::many0;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
@ -91,11 +92,15 @@ pub fn maybe_consume_object_trailing_whitespace_if_not_exiting<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Option<OrgSource<'s>>> { ) -> Res<OrgSource<'s>, Option<OrgSource<'s>>> {
if exit_matcher_parser(context, input).is_err() { // We have to check exit matcher after each character because description list tags need to end with a space unconsumed (" ::").
opt(space0)(input) let (remaining, _) = many_till(
} else { verify(anychar, |c| *c == ' '),
Ok((input, None)) alt((
} peek(recognize(verify(anychar, |c| *c != ' '))),
parser_with_context!(exit_matcher_parser)(context),
)),
)(input)?;
Ok((remaining, None))
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]