diff --git a/src/parser/new_context.rs b/src/parser/new_context.rs index 02ab955c..3e566bf8 100644 --- a/src/parser/new_context.rs +++ b/src/parser/new_context.rs @@ -22,23 +22,44 @@ impl<'r> ContextTree<'r> { ContextTree { tree: new_list } } - pub fn check_fail_matcher<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>> { - let mut current_node = &self.tree; + pub fn check_fail_matcher<'s>( + &'r self, + i: &'s str, + ) -> IResult<&'s str, &'s str, VerboseError<&'s str>> { + // TODO: Can I do this without incrementing reference counters? Perhaps via implementing an iterator over the list? + let mut current_node = self.tree.clone(); while !current_node.is_empty() { - let context_element = current_node.get_data().expect("While looop proves its Some()"); + let context_element = current_node + .get_data() + .expect("While looop proves its Some()"); match context_element { ContextElement::FailMatcherNode(fail_matcher) => { match fail_matcher.fail_matcher { - ChainBehavior::AndParent(Some(matcher)) => todo!(), - ChainBehavior::AndParent(None) => todo!(), - ChainBehavior::IgnoreParent(_) => todo!(), - ChainBehavior::IgnoreParent(None) => todo!(), + ChainBehavior::AndParent(Some(matcher)) => { + let local_result = matcher(i); + if local_result.is_ok() { + return local_result; + } + } + ChainBehavior::AndParent(None) => {} + ChainBehavior::IgnoreParent(Some(matcher)) => { + let local_result = matcher(i); + if local_result.is_ok() { + return local_result; + } + // TODO: Make this a custom error + not(take(0usize))(i)?; + } + ChainBehavior::IgnoreParent(None) => { + // TODO: Make this a custom error + not(take(0usize))(i)?; + } }; - }, + } ContextElement::PreviousElementNode(_) => todo!(), }; - current_node = ¤t_node.without_front(); + current_node = current_node.without_front(); } // TODO: Make this a custom error