How do I do parent? Maybe Rc Instead of Box.

This commit is contained in:
Tom Alexander 2022-10-30 04:50:09 -04:00
parent 13c83d9d85
commit ce4b4a27f9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -7,6 +7,45 @@ use nom::error::VerboseError;
use nom::IResult;
use nom::Parser;
pub struct TestContext<T> {
head: ContextReference<T>,
}
type ContextReference<T> = Option<Box<ContextLayer<T>>>;
struct ContextLayer<T> {
data: T,
parent: ContextReference<T>,
}
struct ContextData {
fail_matcher: ChainBehavior,
}
impl TestContext<ContextData> {
pub fn new() -> Self {
TestContext { head: None }
}
pub fn with_additional_fail_matcher(
&self,
new_matcher: MatcherRef,
) -> TestContext<ContextData> {
TestContext {
head: Some(Box::new(ContextLayer {
data: ContextData {
fail_matcher: ChainBehavior::AndParent(Some(new_matcher)),
},
parent: self.head, // TODO FIX THIS
})),
}
}
}
/////
///// OLD
/////
type MatcherRef = Rc<RefCell<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>>;
struct FailChecker<'r>(&'r NomContext<'r>);