diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index ebc9442..529b8c9 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -5,6 +5,9 @@ use std::rc::Rc; use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; +use super::new_context::ChainBehavior; +use super::new_context::ContextTree; +use super::new_context::FailMatcherNode; use super::text::bold_end; use super::text::bold_start; use super::text::line_break; @@ -35,7 +38,7 @@ use tracing::instrument; use tracing::trace; fn context_many_till<'r, I, O, E, F, M, T>( - context: &'r ContextTree<'r>, + context: ContextTree<'r>, mut many_matcher: M, mut till_matcher: T, ) -> impl FnMut(I) -> IResult, F), E> @@ -78,19 +81,16 @@ where } pub fn document(input: &str) -> Res<&str, Vec<(Vec, &str)>> { - let initial_context: ContextTree<'_, FailMatcherNode> = ContextTree::new(); + let initial_context: ContextTree<'_> = ContextTree::new(); let paragraph_parser = parser_with_context!(paragraph); let ret = many1(paragraph_parser(&initial_context))(input); ret } -pub fn paragraph<'s, 'x: 'r, 'r, C>( - context: &'x ContextTree<'r, C>, +pub fn paragraph<'s, 'r>( + context: ContextTree<'r>, i: &'s str, -) -> Res<&'s str, (Vec>, &'s str)> -where - C: ContextElement, -{ +) -> 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 { @@ -107,13 +107,10 @@ where ret } -fn flat_text_element<'s, 'x: 'r, 'r, C>( - context: &'x ContextTree<'r, C>, +fn flat_text_element<'s, 'r>( + context: ContextTree<'r>, i: &'s str, -) -> Res<&'s str, TextElement<'s>> -where - C: ContextElement, -{ +) -> Res<&'s str, TextElement<'s>> { not(|i| context.check_fail_matcher(i))(i)?; let bold_matcher = parser_with_context!(flat_bold)(context); @@ -135,13 +132,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> { recognize(bold_end)(input) } -fn flat_bold<'s, 'x: 'r, 'r, C>( - context: &'x ContextTree<'r, C>, - i: &'s str, -) -> Res<&'s str, Bold<'s>> -where - C: ContextElement, -{ +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)), }); @@ -159,13 +150,7 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> { recognize(link_end)(input) } -fn flat_link<'s, 'x: 'r, 'r, C>( - context: &'x ContextTree<'r, C>, - i: &'s str, -) -> Res<&'s str, Link<'s>> -where - C: ContextElement, -{ +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)), });