From ce4b4a27f9bf5e958635ce540c58f39998fb1e3a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 30 Oct 2022 04:50:09 -0400 Subject: [PATCH] How do I do parent? Maybe Rc Instead of Box. --- src/parser/nom_context.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 91a374bf..67e55a48 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -7,6 +7,45 @@ use nom::error::VerboseError; use nom::IResult; use nom::Parser; +pub struct TestContext { + head: ContextReference, +} + +type ContextReference = Option>>; + +struct ContextLayer { + data: T, + parent: ContextReference, +} + +struct ContextData { + fail_matcher: ChainBehavior, +} + +impl TestContext { + pub fn new() -> Self { + TestContext { head: None } + } + + pub fn with_additional_fail_matcher( + &self, + new_matcher: MatcherRef, + ) -> TestContext { + 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 IResult<&str, &str, VerboseError<&str>>>>; struct FailChecker<'r>(&'r NomContext<'r>);