Running into a FnOnce vs FnMut error.

This commit is contained in:
Tom Alexander 2022-12-03 21:11:39 -05:00
parent bc91775880
commit a3286b2542
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 16 additions and 12 deletions

View File

@ -6,6 +6,7 @@ use crate::parser::parser_with_context::parser_with_context;
use crate::parser::text::paragraph_end; use crate::parser::text::paragraph_end;
use super::new_context::ChainBehavior; use super::new_context::ChainBehavior;
use super::new_context::ContextElement;
use super::new_context::ContextTree; use super::new_context::ContextTree;
use super::new_context::FailMatcherNode; use super::new_context::FailMatcherNode;
use super::text::bold_end; use super::text::bold_end;
@ -93,11 +94,12 @@ pub fn paragraph<'s, 'r>(
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> { ) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
// Add a not(eof) check because many_till cannot match a zero-length string // Add a not(eof) check because many_till cannot match a zero-length string
not(eof)(i)?; not(eof)(i)?;
let paragraph_context = context.with_additional_node(FailMatcherNode { let paragraph_context =
fail_matcher: ChainBehavior::AndParent(Some(&paragraph_end)), context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
}); fail_matcher: ChainBehavior::AndParent(Some(&paragraph_end)),
}));
let ret = { let ret = {
let text_element_parser = parser_with_context!(flat_text_element)(&paragraph_context); let text_element_parser = parser_with_context!(flat_text_element)(paragraph_context);
many_till(text_element_parser, paragraph_end)(i) many_till(text_element_parser, paragraph_end)(i)
}; };
// let paragraph_context = context.with_additional_fail_matcher(&paragraph_end); // let paragraph_context = context.with_additional_fail_matcher(&paragraph_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>> { fn flat_bold<'s, 'r>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> {
let new_context = context.with_additional_node(FailMatcherNode { let new_context =
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)), 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 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(( let (remaining, captured) = recognize(tuple((
bold_start, bold_start,
many_till(text_element_parser, bold_end), 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>> { 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 { let new_context =
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)), 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 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(( let (remaining, captured) = recognize(tuple((
link_start, link_start,
many_till(text_element_parser, link_end), many_till(text_element_parser, link_end),