From 8659a1083e5deaeffb7392d501c5f262466b5ea1 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 26 Nov 2022 22:35:53 -0500 Subject: [PATCH] Revert "I may need to switch to boxes." This reverts commit bdc61c075716e1752eb1332ce8e2682f69b2e435. --- src/parser/nom_context.rs | 19 ++++++++++--------- src/parser/text_element_parser.rs | 10 +++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index a271a716..f68d010e 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -18,7 +18,7 @@ pub trait OrgModeContext<'r> { fn get_fail_matcher(&'r self) -> Cow>; } -pub struct FailMatcherNode<'r> { +struct FailMatcherNode<'r> { fail_matcher: ChainBehavior<'r>, } @@ -98,6 +98,15 @@ impl<'r> ContextTree<'r, dyn OrgModeContext<'r>> { ErrorKind::ManyTill, ))); } + + pub fn with_additional_fail_matcher( + &'r self, + fail_matcher: &'r Matcher, + ) -> OrgModeContextTree<'r> { + self.with_additional_node(FailMatcherNode { + fail_matcher: ChainBehavior::AndParent(Some(fail_matcher)), + }) + } } impl<'r> OrgModeContext<'r> for FailMatcherNode<'r> { @@ -112,14 +121,6 @@ impl<'r> OrgModeContext<'r> for PreviousElementNode<'r> { } } -impl<'r> FailMatcherNode<'r> { - pub fn additional(fail_matcher: &'r Matcher) -> Self { - FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(fail_matcher)), - } - } -} - fn recognize_bold_end(input: &str) -> Res<&str, &str> { recognize(bold_end)(input) } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index dab89049..88f6d4c7 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -6,7 +6,6 @@ use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; use super::nom_context::ContextTree; -use super::nom_context::FailMatcherNode; use super::nom_context::OrgModeContextTree; use super::text::bold_end; use super::text::bold_start; @@ -93,8 +92,7 @@ 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 fail_matcher_node = FailMatcherNode::additional(¶graph_end); - let paragraph_context = context.with_additional_node(&fail_matcher_node); + let paragraph_context = context.with_additional_fail_matcher(¶graph_end); let text_element_parser = parser_with_context!(flat_text_element)(¶graph_context); let ret = context_many_till(¶graph_context, text_element_parser, paragraph_end)(i); // let ret = many_till(text_element_parser, paragraph_end)(i); @@ -127,8 +125,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> { } fn flat_bold<'s, 'r>(context: &'r OrgModeContextTree<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> { - let fail_matcher_node = FailMatcherNode::additional(&recognize_bold_end); - let new_context = context.with_additional_node(&fail_matcher_node); + let new_context = context.with_additional_fail_matcher(&recognize_bold_end); let text_element_parser = parser_with_context!(flat_text_element)(&new_context); let (remaining, captured) = recognize(tuple(( bold_start, @@ -143,8 +140,7 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> { } fn flat_link<'s, 'r>(context: &'r OrgModeContextTree<'r>, i: &'s str) -> Res<&'s str, Link<'s>> { - let fail_matcher_node = FailMatcherNode::additional(&recognize_link_end); - let new_context = context.with_additional_node(&fail_matcher_node); + let new_context = context.with_additional_fail_matcher(&recognize_link_end); let text_element_parser = parser_with_context!(flat_text_element)(&new_context); let (remaining, captured) = recognize(tuple(( link_start,