2022-07-16 17:27:08 -04:00
|
|
|
use nom::branch::alt;
|
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;
|
|
|
|
|
2022-07-16 17:52:04 -04:00
|
|
|
#[derive(Clone)]
|
2022-07-16 21:16:34 -04:00
|
|
|
pub struct NomContext<F>
|
|
|
|
where
|
|
|
|
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
2022-07-17 18:06:14 -04:00
|
|
|
F: Clone,
|
2022-07-16 21:16:34 -04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-07-17 18:06:14 -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
|
|
|
}
|