use nom::branch::alt; use nom::error::VerboseError; use nom::IResult; use std::cell::RefCell; use std::rc::Rc; #[derive(Clone)] pub struct NomContext where F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>, { pub fail_matcher: F, /// You can't have nested bolds in org-mode pub can_match_bold: bool, pub can_match_link: bool, } impl NomContext where F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>, F: Clone, { pub fn new(fail_matcher: F) -> Self { NomContext { fail_matcher: fail_matcher, can_match_bold: true, can_match_link: true, } } pub fn without_bold(&self) -> Self { NomContext { fail_matcher: self.fail_matcher.clone(), can_match_bold: true, can_match_link: true, } } pub fn with_additional_fail_matcher( self, additional_fail_matcher: G, ) -> NomContext FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>)> where G: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>, G: Clone, // O: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>, // O: Clone, { NomContext { fail_matcher: alt((additional_fail_matcher, self.fail_matcher)), can_match_bold: self.can_match_bold, can_match_link: self.can_match_link, } } }