Added boxes.

This commit is contained in:
Tom Alexander 2022-10-14 20:52:49 -04:00
parent 9e3ea29634
commit 8a6868f299
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 13 additions and 13 deletions

View File

@ -2,16 +2,16 @@ use nom::branch::alt;
use nom::error::VerboseError;
use nom::IResult;
pub struct NomContext<'a> {
pub fail_matcher: &'a mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>,
pub struct NomContext {
pub fail_matcher: Box<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>,
/// You can't have nested bolds or links in org-mode
pub can_match_bold: bool,
pub can_match_link: bool,
}
impl<'a> NomContext<'a> {
impl NomContext {
pub fn new(
fail_matcher: &'a mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>,
fail_matcher: Box<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>,
) -> Self {
NomContext {
fail_matcher,
@ -20,13 +20,13 @@ impl<'a> NomContext<'a> {
}
}
pub fn with_additional_fail_matcher<'o, 'c: 'a + 'o>(&self, other: &'o mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>) -> NomContext<'c> {
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
}
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
// }
todo!()
}
}

View File

@ -133,7 +133,7 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> {
}
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
let initial_context = NomContext::new(&mut paragraph_end);
let initial_context = NomContext::new(Box::new(paragraph_end));
todo!()
// many1(parser_with_context!(paragraph)(initial_context))(input)
}

View File

@ -25,6 +25,6 @@ fn flat_text_element<'s, 'r>(
i: &'s str,
context: &'r mut NomContext,
) -> Res<&'s str, TextElement<'s>> {
not(&mut context.fail_matcher)(i)?;
// not(&mut context.fail_matcher)(i)?;
todo!()
}