Starting to implement the match_fail function to walk up the matcher chain.
This commit is contained in:
parent
d277a033c9
commit
109a013057
@ -48,6 +48,8 @@ pub enum ChainBehavior<'r> {
|
|||||||
|
|
||||||
pub trait OrgModeContextTree<'r> {
|
pub trait OrgModeContextTree<'r> {
|
||||||
fn with_additional_fail_matcher(&'r self, fail_matcher: &'r Matcher) -> OrgModeContext<'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> {
|
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)),
|
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!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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::OrgModeContext;
|
use super::nom_context::OrgModeContext;
|
||||||
|
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;
|
||||||
use super::text::line_break;
|
use super::text::line_break;
|
||||||
@ -28,7 +29,7 @@ fn flat_text_element<'s, 'r>(
|
|||||||
i: &'s str,
|
i: &'s str,
|
||||||
context: &'r OrgModeContext<'r>,
|
context: &'r OrgModeContext<'r>,
|
||||||
) -> Res<&'s str, TextElement<'s>> {
|
) -> Res<&'s str, TextElement<'s>> {
|
||||||
// context.not_matching_fail(i)?;
|
not(|i| context.match_fail(i))(i)?;
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
map(span, TextElement::Span),
|
map(span, TextElement::Span),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user