Revert "I may need to switch to boxes."

This reverts commit bdc61c075716e1752eb1332ce8e2682f69b2e435.
This commit is contained in:
Tom Alexander 2022-11-26 22:35:53 -05:00
parent c2bd6e23c6
commit 8659a1083e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 13 additions and 16 deletions

View File

@ -18,7 +18,7 @@ pub trait OrgModeContext<'r> {
fn get_fail_matcher(&'r self) -> Cow<ChainBehavior<'r>>;
}
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)
}

View File

@ -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<TextElement<'s>>, &'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(&paragraph_end);
let paragraph_context = context.with_additional_node(&fail_matcher_node);
let paragraph_context = context.with_additional_fail_matcher(&paragraph_end);
let text_element_parser = parser_with_context!(flat_text_element)(&paragraph_context);
let ret = context_many_till(&paragraph_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,