For some reason it does not work with FnMut for additional fail matchers.

This commit is contained in:
Tom Alexander 2022-10-30 05:43:26 -04:00
parent 661ccfb30c
commit d1460fed95
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 25 additions and 8 deletions

View File

@ -7,17 +7,33 @@ use nom::error::VerboseError;
use nom::IResult;
use nom::Parser;
pub struct TestContext<T> {
head: ContextReference<T>,
pub struct ContextLayer<T> {
data: T,
parent: Option<Rc<ContextLayer<T>>>,
}
impl<T> ContextLayer<T> {
pub fn with_new_layer(self: Rc<Self>, new_layer: T) -> ContextLayer<T> {
ContextLayer {
data: new_layer,
parent: Some(self),
}
}
}
type ContextReference<T> = Option<Rc<ContextLayer<T>>>;
struct ContextLayer<T> {
data: T,
parent: ContextReference<T>,
pub struct TestContext<T> {
head: ContextReference<T>,
}
// type ContextReference<T> = Option<Rc<ContextLayer<T>>>;
// struct ContextLayer<T> {
// data: T,
// parent: ContextReference<T>,
// }
pub struct ContextData {
fail_matcher: ChainBehavior,
}
@ -46,7 +62,8 @@ impl TestContext<ContextData> {
///// OLD
/////
type MatcherRef = Rc<RefCell<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>>;
type MatcherRef =
Rc<RefCell<dyn for<'s> FnMut(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>>>;
struct FailChecker<'r>(&'r NomContext<'r>);

View File

@ -46,8 +46,8 @@ fn flat_bold<'s, 'r>(
i: &'s str,
context: &'r TestContext<ContextData>,
) -> Res<&'s str, TextElement<'s>> {
let new_context =
context.with_additional_fail_matcher(Rc::new(RefCell::new(recognize(bold_end))));
let fail_matcher = recognize(bold_end);
let new_context = context.with_additional_fail_matcher(Rc::new(RefCell::new(paragraph_end)));
// let new_context = context.without_bold(Rc::new(RefCell::new(recognize(bold_end))));
todo!()
}