From a3286b254260ca8f991dad3b9dd180e0485145db Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 3 Dec 2022 21:11:39 -0500 Subject: [PATCH] Running into a FnOnce vs FnMut error. --- src/parser/text_element_parser.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 6988f009..2c6f23b1 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -6,6 +6,7 @@ use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; use super::new_context::ChainBehavior; +use super::new_context::ContextElement; use super::new_context::ContextTree; use super::new_context::FailMatcherNode; use super::text::bold_end; @@ -93,11 +94,12 @@ pub fn paragraph<'s, 'r>( ) -> Res<&'s str, (Vec>, &'s str)> { // Add a not(eof) check because many_till cannot match a zero-length string not(eof)(i)?; - let paragraph_context = context.with_additional_node(FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(¶graph_end)), - }); + let paragraph_context = + context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { + fail_matcher: ChainBehavior::AndParent(Some(¶graph_end)), + })); let ret = { - let text_element_parser = parser_with_context!(flat_text_element)(¶graph_context); + let text_element_parser = parser_with_context!(flat_text_element)(paragraph_context); many_till(text_element_parser, paragraph_end)(i) }; // let paragraph_context = context.with_additional_fail_matcher(¶graph_end); @@ -133,11 +135,12 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> { } fn flat_bold<'s, 'r>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> { - let new_context = context.with_additional_node(FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)), - }); + let new_context = + context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { + fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)), + })); // let new_context = context.with_additional_fail_matcher(&recognize_bold_end); - let text_element_parser = parser_with_context!(flat_text_element)(&new_context); + let text_element_parser = parser_with_context!(flat_text_element)(new_context); let (remaining, captured) = recognize(tuple(( bold_start, many_till(text_element_parser, bold_end), @@ -151,11 +154,12 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> { } fn flat_link<'s, 'r, C>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Link<'s>> { - let new_context = context.with_additional_node(FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)), - }); + let new_context = + context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { + fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)), + })); // let new_context = context.with_additional_fail_matcher(&recognize_link_end); - let text_element_parser = parser_with_context!(flat_text_element)(&new_context); + let text_element_parser = parser_with_context!(flat_text_element)(new_context); let (remaining, captured) = recognize(tuple(( link_start, many_till(text_element_parser, link_end),