From af90ea6dfd4c32d6d9ce0e95e405f8aab9cb28e2 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 22 Apr 2023 01:34:34 -0400 Subject: [PATCH] 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. --- src/parser/element_parser.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 03a26d3..3ddc1f5 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -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) + } } }?;