organic/src/parser/nom_context.rs

44 lines
1.3 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;
2022-07-16 17:27:08 -04:00
pub struct NomContext<I, O, E> {
pub fail_matcher: Box<dyn FnMut(I) -> IResult<I, O, E>>,
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 17:27:08 -04:00
impl<I, O, E> NomContext<I, O, E> {
pub fn new(fail_matcher: Box<dyn FnMut(I) -> IResult<I, O, E>>) -> Self {
2022-07-15 23:26:49 -04:00
NomContext {
2022-07-16 17:27:08 -04:00
fail_matcher: fail_matcher,
2022-07-15 23:26:49 -04:00
can_match_bold: true,
can_match_link: true,
}
}
2022-07-16 17:27:08 -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,
// }
// }
// 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,
// }
// }
2022-07-15 23:26:49 -04:00
}