From 1a7bfd23f1aff3ae4aa94d61ca36666483dee540 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 3 Dec 2022 22:12:13 -0500 Subject: [PATCH] Implement the structure to the check_fail_matcher function. --- src/parser/list.rs | 10 ++++++++++ src/parser/new_context.rs | 25 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/parser/list.rs b/src/parser/list.rs index d8d5d8e..aec0af8 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -25,7 +25,17 @@ impl List { } } + pub fn without_front(&self) -> List { + List { + head: self.head.as_ref().map(|node| node.parent.clone()).flatten() + } + } + pub fn get_data(&self) -> Option<&T> { self.head.as_ref().map(|rc_node| &rc_node.data) } + + pub fn is_empty(&self) -> bool { + self.head.is_none() + } } diff --git a/src/parser/new_context.rs b/src/parser/new_context.rs index b4019cb..02ab955 100644 --- a/src/parser/new_context.rs +++ b/src/parser/new_context.rs @@ -1,3 +1,5 @@ +use nom::bytes::complete::take; +use nom::combinator::not; use nom::error::VerboseError; use nom::IResult; @@ -21,8 +23,27 @@ impl<'r> ContextTree<'r> { } pub fn check_fail_matcher<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>> { - // todo - todo!() + let mut current_node = &self.tree; + while !current_node.is_empty() { + 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!(), + }; + }, + ContextElement::PreviousElementNode(_) => todo!(), + }; + + current_node = ¤t_node.without_front(); + } + + // TODO: Make this a custom error + not(take(0usize))(i)?; + unreachable!() } }