Fix infinite loop by only checking paragraph matcher when boolean is true.

Before I was checking afterwards with a verify, which was causing an infinite loop.
This commit is contained in:
Tom Alexander 2023-04-22 01:34:34 -04:00
parent 7855020927
commit af90ea6dfd
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -69,16 +69,22 @@ pub fn element(
map(diary_sexp_matcher, Element::DiarySexp),
map(fixed_width_area_matcher, Element::FixedWidthArea),
map(horizontal_rule_matcher, Element::HorizontalRule),
map(
verify(paragraph_matcher, |_p| can_be_paragraph),
Element::Paragraph,
),
))(remaining)
{
the_ok @ Ok(_) => the_ok,
Err(_) => {
affiliated_keywords.clear();
map(keyword_matcher, Element::Keyword)(input)
if can_be_paragraph {
match map(paragraph_matcher, Element::Paragraph)(remaining) {
the_ok @ Ok(_) => the_ok,
Err(_) => {
affiliated_keywords.clear();
map(keyword_matcher, Element::Keyword)(input)
}
}
} else {
affiliated_keywords.clear();
map(keyword_matcher, Element::Keyword)(input)
}
}
}?;