organic/src/parser/nom_context.rs

33 lines
977 B
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-10-14 20:52:49 -04:00
pub struct NomContext {
pub fail_matcher: Box<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>,
2022-10-14 20:09:09 -04:00
/// You can't have nested bolds or links in org-mode
2022-07-15 23:26:49 -04:00
pub can_match_bold: bool,
pub can_match_link: bool,
}
2022-10-14 20:52:49 -04:00
impl NomContext {
2022-10-14 20:17:48 -04:00
pub fn new(
2022-10-14 20:52:49 -04:00
fail_matcher: Box<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>,
2022-10-14 20:17:48 -04:00
) -> Self {
2022-07-16 21:32:23 -04:00
NomContext {
2022-10-14 20:09:09 -04:00
fail_matcher,
2022-07-16 21:55:33 -04:00
can_match_bold: true,
can_match_link: true,
}
}
2022-10-14 20:50:00 -04:00
2022-10-14 20:52:49 -04:00
pub fn with_additional_fail_matcher<>(&self, other: Box<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>) -> NomContext {
// let new_matcher = alt((&self.fail_matcher, other));
// NomContext {
// fail_matcher: new_matcher,
// can_match_bold: self.can_match_bold,
// can_match_link: self.can_match_link
// }
2022-10-14 20:50:00 -04:00
todo!()
}
2022-07-16 21:32:23 -04:00
}