diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index ac984a2e..2e20a563 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -48,6 +48,8 @@ pub enum ChainBehavior<'r> { pub trait OrgModeContextTree<'r> { fn with_additional_fail_matcher(&'r self, fail_matcher: &'r Matcher) -> OrgModeContext<'r>; + + fn match_fail<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; } impl<'r> OrgModeContextTree<'r> for OrgModeContext<'r> { @@ -59,4 +61,24 @@ impl<'r> OrgModeContextTree<'r> for OrgModeContext<'r> { fail_matcher: ChainBehavior::AndParent(Some(fail_matcher)), }) } + + fn match_fail<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>> { + let mut current_node = self.head.as_ref(); + while current_node.is_some() { + let current_node_unwrapped = current_node.as_ref().expect("while loop asserts current_node is some."); + match current_node_unwrapped.elem.fail_matcher { + ChainBehavior::AndParent(Some(matcher)) => { + let local_result = matcher(i); + if local_result.is_ok() { + return local_result; + } + }, + ChainBehavior::AndParent(None) => {}, + ChainBehavior::IgnoreParent(Some(matcher)) => todo!(), + ChainBehavior::IgnoreParent(None) => todo!(), + }; + current_node = current_node.map(|current_head| current_head.next).flatten(); + } + todo!() + } } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index ccb5a3b6..0e1004d6 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -6,6 +6,7 @@ use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; use super::nom_context::OrgModeContext; +use super::nom_context::OrgModeContextTree; use super::text::bold_end; use super::text::bold_start; use super::text::line_break; @@ -28,7 +29,7 @@ fn flat_text_element<'s, 'r>( i: &'s str, context: &'r OrgModeContext<'r>, ) -> Res<&'s str, TextElement<'s>> { - // context.not_matching_fail(i)?; + not(|i| context.match_fail(i))(i)?; alt(( map(span, TextElement::Span),