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::peek;
use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many0;
use nom::multi::many_till;
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>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Option<OrgSource<'s>>> {
if exit_matcher_parser(context, input).is_err() {
opt(space0)(input)
} else {
Ok((input, None))
}
// We have to check exit matcher after each character because description list tags need to end with a space unconsumed (" ::").
let (remaining, _) = many_till(
verify(anychar, |c| *c == ' '),
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"))]