I may need to switch to boxes.
This commit is contained in:
parent
0b2acd7e54
commit
c2bd6e23c6
@ -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>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FailMatcherNode<'r> {
|
pub struct FailMatcherNode<'r> {
|
||||||
fail_matcher: ChainBehavior<'r>,
|
fail_matcher: ChainBehavior<'r>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,15 +98,6 @@ 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> {
|
||||||
@ -121,6 +112,14 @@ 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,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::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;
|
||||||
@ -92,7 +93,8 @@ 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_fail_matcher(¶graph_end);
|
let fail_matcher_node = FailMatcherNode::additional(¶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);
|
||||||
@ -125,7 +127,8 @@ 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 new_context = context.with_additional_fail_matcher(&recognize_bold_end);
|
let fail_matcher_node = FailMatcherNode::additional(&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,
|
||||||
@ -140,7 +143,8 @@ 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 new_context = context.with_additional_fail_matcher(&recognize_link_end);
|
let fail_matcher_node = FailMatcherNode::additional(&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