2022-07-16 17:27:08 -04:00
|
|
|
use nom::branch::alt;
|
2022-07-15 23:26:49 -04:00
|
|
|
use nom::error::VerboseError;
|
2022-07-16 16:31:00 -04:00
|
|
|
use nom::IResult;
|
2022-07-15 23:26:49 -04:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
2022-07-16 17:52:04 -04:00
|
|
|
#[derive(Clone)]
|
2022-07-16 21:16:34 -04:00
|
|
|
pub struct NomContext<F>
|
|
|
|
where
|
|
|
|
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
|
|
|
{
|
|
|
|
pub fail_matcher: F,
|
2022-07-15 23:26:49 -04:00
|
|
|
|
|
|
|
/// You can't have nested bolds in org-mode
|
|
|
|
pub can_match_bold: bool,
|
|
|
|
pub can_match_link: bool,
|
|
|
|
}
|
|
|
|
|
2022-07-16 21:16:34 -04:00
|
|
|
// impl<'a, I, O, E> NomContext<'a, I, O, E> {
|
|
|
|
// pub fn new(fail_matcher: &'a dyn FnMut(I) -> IResult<I, O, E>) -> Self {
|
|
|
|
// NomContext {
|
|
|
|
// fail_matcher: fail_matcher,
|
|
|
|
// can_match_bold: true,
|
|
|
|
// can_match_link: true,
|
|
|
|
// }
|
|
|
|
// }
|
2022-07-15 23:26:49 -04:00
|
|
|
|
2022-07-16 21:16:34 -04:00
|
|
|
// pub fn with_no_bold(&self) -> NomContext<I, O, E> {
|
|
|
|
// NomContext {
|
|
|
|
// fail_matcher: self.fail_matcher.clone(),
|
|
|
|
// can_match_bold: false,
|
|
|
|
// can_match_link: self.can_match_link,
|
|
|
|
// }
|
|
|
|
// }
|
2022-07-16 17:27:08 -04:00
|
|
|
|
2022-07-16 21:16:34 -04:00
|
|
|
// // pub fn with_additional_fail_matcher(&self, additional_matcher: G) -> NomContext<G, I, O, E>
|
|
|
|
// // where
|
|
|
|
// // G: for<'a> FnMut(I) -> IResult<I, O, E>,
|
|
|
|
// // {
|
|
|
|
// // let new_fail_matcher = alt((self.fail_matcher, additional_matcher));
|
|
|
|
// // NomContext {
|
|
|
|
// // fail_matcher: Rc::new(RefCell::new(new_fail_matcher)),
|
|
|
|
// // can_match_bold: self.can_match_bold,
|
|
|
|
// // can_match_link: self.can_match_link,
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// }
|