Impleemnt the behavior for check_fail_matcher.

This commit is contained in:
Tom Alexander 2022-12-03 22:15:16 -05:00
parent 1a7bfd23f1
commit 84fa1c3aae
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -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 = &current_node.without_front();
current_node = current_node.without_front();
}
// TODO: Make this a custom error