organic/src/parser/nom_context.rs

48 lines
1.4 KiB
Rust
Raw Normal View History

2022-07-16 17:27:08 -04:00
use nom::branch::alt;
2022-07-15 23:26:49 -04:00
use nom::error::VerboseError;
use nom::IResult;
2022-07-15 23:26:49 -04:00
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Clone)]
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,
}
// 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
// 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
// // 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,
// // }
// // }
// }