How do I do parent? Maybe Rc Instead of Box.
This commit is contained in:
parent
13c83d9d85
commit
ce4b4a27f9
@ -7,6 +7,45 @@ use nom::error::VerboseError;
|
|||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
use nom::Parser;
|
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>>>>;
|
type MatcherRef = Rc<RefCell<dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>>>;
|
||||||
|
|
||||||
struct FailChecker<'r>(&'r NomContext<'r>);
|
struct FailChecker<'r>(&'r NomContext<'r>);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user