2022-10-15 00:01:37 -04:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
2022-07-16 17:27:08 -04:00
|
|
|
use nom::branch::alt;
|
2022-10-15 14:04:24 -04:00
|
|
|
use nom::combinator::not;
|
2022-07-15 23:26:49 -04:00
|
|
|
use nom::error::VerboseError;
|
2022-07-16 16:31:00 -04:00
|
|
|
use nom::IResult;
|
2022-10-15 00:01:37 -04:00
|
|
|
use nom::Parser;
|
|
|
|
|
2022-11-24 14:30:54 -05:00
|
|
|
type ContextReference<'r, T> = Option<&'r ContextLayer<'r, T>>;
|
|
|
|
type MatcherRef = dyn for<'s> FnMut(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
|
2022-10-30 05:48:43 -04:00
|
|
|
|
2022-11-24 14:30:54 -05:00
|
|
|
pub struct ContextLayer<'r, T> {
|
2022-10-30 05:43:26 -04:00
|
|
|
data: T,
|
2022-11-24 14:30:54 -05:00
|
|
|
parent: ContextReference<'r, T>,
|
2022-10-30 05:43:26 -04:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:30:54 -05:00
|
|
|
pub struct TestContext<'r, T> {
|
|
|
|
head: ContextReference<'r, T>,
|
2022-10-30 04:50:09 -04:00
|
|
|
}
|
|
|
|
|
2022-10-30 05:53:18 -04:00
|
|
|
pub struct ContextData<'r> {
|
|
|
|
fail_matcher: ChainBehavior<'r>,
|
2022-10-30 04:50:09 -04:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:30:54 -05:00
|
|
|
impl<'r> TestContext<'r, ContextData<'r>> {
|
2022-10-30 04:50:09 -04:00
|
|
|
pub fn new() -> Self {
|
|
|
|
TestContext { head: None }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-30 05:53:18 -04:00
|
|
|
enum ChainBehavior<'r> {
|
2022-11-24 14:30:54 -05:00
|
|
|
AndParent(Option<&'r MatcherRef>),
|
|
|
|
IgnoreParent(Option<&'r MatcherRef>),
|
2022-07-15 23:26:49 -04:00
|
|
|
}
|