organic/src/parser/nom_context.rs

35 lines
814 B
Rust
Raw Normal View History

2022-07-15 23:26:49 -04:00
use nom::error::VerboseError;
use nom::Parser;
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
F: for<'a> Parser<&'a str, &'a str, VerboseError<&'a str>>,
{
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,
}
}
}