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;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct NomContext<F> {
|
|
|
|
pub fail_matcher: Rc<RefCell<F>>,
|
|
|
|
|
|
|
|
/// You can't have nested bolds in org-mode
|
|
|
|
pub can_match_bold: bool,
|
|
|
|
pub can_match_link: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<F> NomContext<F>
|
|
|
|
where
|
2022-07-16 16:31:00 -04:00
|
|
|
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
2022-07-15 23:26:49 -04:00
|
|
|
{
|
|
|
|
pub fn new(fail_matcher: F) -> Self {
|
|
|
|
NomContext {
|
|
|
|
fail_matcher: Rc::new(RefCell::new(fail_matcher)),
|
|
|
|
can_match_bold: true,
|
|
|
|
can_match_link: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_no_bold(&self) -> NomContext<F> {
|
|
|
|
NomContext {
|
|
|
|
fail_matcher: self.fail_matcher.clone(),
|
|
|
|
can_match_bold: false,
|
|
|
|
can_match_link: self.can_match_link,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|