Revert "I may need to switch to boxes."
This reverts commit bdc61c075716e1752eb1332ce8e2682f69b2e435.
This commit is contained in:
parent
c2bd6e23c6
commit
8659a1083e
@ -18,7 +18,7 @@ pub trait OrgModeContext<'r> {
|
|||||||
fn get_fail_matcher(&'r self) -> Cow<ChainBehavior<'r>>;
|
fn get_fail_matcher(&'r self) -> Cow<ChainBehavior<'r>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FailMatcherNode<'r> {
|
struct FailMatcherNode<'r> {
|
||||||
fail_matcher: ChainBehavior<'r>,
|
fail_matcher: ChainBehavior<'r>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +98,15 @@ impl<'r> ContextTree<'r, dyn OrgModeContext<'r>> {
|
|||||||
ErrorKind::ManyTill,
|
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> {
|
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> {
|
fn recognize_bold_end(input: &str) -> Res<&str, &str> {
|
||||||
recognize(bold_end)(input)
|
recognize(bold_end)(input)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ use crate::parser::parser_with_context::parser_with_context;
|
|||||||
use crate::parser::text::paragraph_end;
|
use crate::parser::text::paragraph_end;
|
||||||
|
|
||||||
use super::nom_context::ContextTree;
|
use super::nom_context::ContextTree;
|
||||||
use super::nom_context::FailMatcherNode;
|
|
||||||
use super::nom_context::OrgModeContextTree;
|
use super::nom_context::OrgModeContextTree;
|
||||||
use super::text::bold_end;
|
use super::text::bold_end;
|
||||||
use super::text::bold_start;
|
use super::text::bold_start;
|
||||||
@ -93,8 +92,7 @@ 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 fail_matcher_node = FailMatcherNode::additional(¶graph_end);
|
let paragraph_context = context.with_additional_fail_matcher(¶graph_end);
|
||||||
let paragraph_context = context.with_additional_node(&fail_matcher_node);
|
|
||||||
let text_element_parser = parser_with_context!(flat_text_element)(¶graph_context);
|
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 = context_many_till(¶graph_context, text_element_parser, paragraph_end)(i);
|
||||||
// let ret = many_till(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>> {
|
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_fail_matcher(&recognize_bold_end);
|
||||||
let new_context = context.with_additional_node(&fail_matcher_node);
|
|
||||||
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,
|
||||||
@ -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>> {
|
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_fail_matcher(&recognize_link_end);
|
||||||
let new_context = context.with_additional_node(&fail_matcher_node);
|
|
||||||
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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user