Clean up paragraph eof detection.

This commit is contained in:
Tom Alexander 2022-11-26 18:25:53 -05:00
parent 65c51f79d6
commit 99f9450eda
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 3 additions and 9 deletions

View File

@ -20,6 +20,7 @@ use super::text::Link;
use super::text::Res;
use super::text::TextElement;
use nom::branch::alt;
use nom::combinator::eof;
use nom::combinator::map;
use nom::combinator::not;
use nom::combinator::recognize;
@ -87,18 +88,11 @@ pub fn paragraph<'s, 'r>(
i: &'s str,
context: &'r OrgModeContext<'r>,
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
// not(eof)(i)?;
// Add a not(eof) check because many_till cannot match a zero-length string
not(eof)(i)?;
let paragraph_context = context.with_additional_fail_matcher(&paragraph_end);
let text_element_parser = parser_with_context!(flat_text_element)(&paragraph_context);
let ret = many_till(text_element_parser, paragraph_end)(i);
trace!("Returning from paragraph with {:#?}", ret);
if let Ok((remaining, (text_elements, end_of_paragraph))) = &ret {
if text_elements.len() == 0 {
return Err(nom::Err::Error(nom::error::VerboseError::from_error_kind(
remaining,
ErrorKind::ManyTill,
)));
}
}
ret
}