diff --git a/src/parser/failable_sequence.rs b/src/parser/failable_sequence.rs index 16f4637..ff7057a 100644 --- a/src/parser/failable_sequence.rs +++ b/src/parser/failable_sequence.rs @@ -1,30 +1,25 @@ macro_rules! failable_sequence { ($name:ident,$inp:ident,$context:ident,$begin_matcher:expr,$element_matcher:expr,$success_matcher:expr) => { - pub fn $name<'b, F>( - $context: &'b NomContext, + pub fn $name( + $context: &NomContext, ) -> impl for<'a> FnMut( &'a str, ) -> nom::IResult< &'a str, crate::parser::text::Sequence<'a>, VerboseError<&'a str>, - > + 'b + > + '_ where - F: for<'a> nom::Parser<&'a str, &'a str, VerboseError<&'a str>>, + F: for<'a> FnMut(&'a str) -> nom::IResult<&'a str, &'a str, VerboseError<&'a str>>, { - let fail_matcher = $context.fail_matcher.clone(); - let new_fail_matcher = alt(( - |i| fail_matcher.borrow_mut().parse(i), - recognize($success_matcher), - )); - move |$inp: &str| { let new_context = $context.with_no_bold(); // let other_new_context = NomContext::with_additional_fail_matcher( // |i: &str| recognize($success_matcher)(i), // $context, // ); - let other_new_context = super::nom_context::NomContext::new(new_fail_matcher); + // let other_new_context = + // super::nom_context::NomContext::new($context.fail_matcher.clone()); let element_matcher = recognize($element_matcher(&new_context)); let local_fail_matcher = $context.fail_matcher.clone(); let ret = map( @@ -32,11 +27,11 @@ macro_rules! failable_sequence { $begin_matcher, nom::multi::many_till( nom::sequence::preceded( - not(|i| local_fail_matcher.borrow_mut().parse(i)), + not(|i| local_fail_matcher.borrow_mut()(i)), element_matcher, ), nom::sequence::preceded( - not(|i| local_fail_matcher.borrow_mut().parse(i)), + not(|i| local_fail_matcher.borrow_mut()(i)), $success_matcher, ), ), diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index fb39478..e83f361 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -1,5 +1,5 @@ use nom::error::VerboseError; -use nom::Parser; +use nom::IResult; use std::cell::RefCell; use std::rc::Rc; @@ -14,7 +14,7 @@ pub struct NomContext { impl NomContext where - F: for<'a> Parser<&'a str, &'a str, VerboseError<&'a str>>, + F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>, { pub fn new(fail_matcher: F) -> Self { NomContext {