organic/src/parser/nom_context.rs

55 lines
1.5 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>>,
F: Clone,
{
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:32:23 -04:00
impl<F> NomContext<F>
where
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
2022-07-16 21:55:33 -04:00
F: Clone,
2022-07-16 21:32:23 -04:00
{
pub fn new(fail_matcher: F) -> Self {
NomContext {
fail_matcher: fail_matcher,
can_match_bold: true,
can_match_link: true,
}
}
2022-07-16 21:55:33 -04:00
pub fn without_bold(&self) -> Self {
NomContext {
fail_matcher: self.fail_matcher.clone(),
can_match_bold: true,
can_match_link: true,
}
}
2022-07-17 17:29:24 -04:00
// pub fn with_additional_fail_matcher<G, O>(self, additional_fail_matcher: G) -> NomContext<O>
// where
// G: for<'g> FnMut(&'g str) -> IResult<&'g str, &'g str, VerboseError<&'g str>>,
// G: Clone,
// O: for<'o> FnMut(&'o str) -> IResult<&'o str, &'o str, VerboseError<&'o str>>,
// O: Clone,
// {
// NomContext {
// fail_matcher: move |i| alt((additional_fail_matcher, self.fail_matcher))(i),
// can_match_bold: self.can_match_bold,
// can_match_link: self.can_match_link,
// }
// }
2022-07-16 21:32:23 -04:00
}