From f84fa0987157839ae4b7896f750bbc159038e674 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 24 Nov 2022 16:24:49 -0500 Subject: [PATCH] Match fail logic implemented. --- src/parser/nom_context.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 2e20a56..78a1806 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -2,7 +2,11 @@ use std::cell::RefCell; use std::rc::Rc; use nom::branch::alt; +use nom::bytes::complete::take; use nom::combinator::not; +use nom::error::ContextError; +use nom::error::ErrorKind; +use nom::error::ParseError; use nom::error::VerboseError; use nom::IResult; use nom::Parser; @@ -65,20 +69,34 @@ impl<'r> OrgModeContextTree<'r> for OrgModeContext<'r> { 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."); + 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!(), + } + 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)?; + } }; current_node = current_node.map(|current_head| current_head.next).flatten(); } - todo!() + // TODO: Make this a custom error + not(take(0usize))(i)?; + unreachable!() } }