From f2ddf6451ca91586d62b0a1740d9194f77eb3589 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 24 Nov 2022 14:59:37 -0500 Subject: [PATCH] Mutable push. --- src/parser/nom_context.rs | 59 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 9254f27f..0cfa096e 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -7,41 +7,38 @@ use nom::error::VerboseError; use nom::IResult; use nom::Parser; -// type ContextReference<'r, T> = Option>; -// type MatcherRef = dyn for<'s> FnMut(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; +type Link = Option>>; +type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; -// pub struct ContextLayer<'r, T> { -// data: T, -// parent: ContextReference<'r, T>, -// } +struct Node { + elem: T, + next: Link, +} -// pub struct TestContext<'r, T> { -// head: ContextReference<'r, T>, -// } +pub struct List { + head: Link, +} -// pub struct ContextData<'r> { -// fail_matcher: ChainBehavior<'r>, -// } +impl List { + pub fn new() -> Self { + List { head: None } + } -// impl<'r> TestContext<'r, ContextData<'r>> { -// pub fn new() -> Self { -// TestContext { head: None } -// } + pub fn push(&mut self, element: T) { + let new_node = Box::new(Node { + elem: element, + next: self.head.take(), + }); -// pub fn with_additional_fail_matcher<'subr>( -// &self, -// additional_fail_matcher: &'subr MatcherRef, -// ) -> TestContext<'subr, ContextData<'subr>> { -// // TestContext { -// // head: Some( + self.head = Some(new_node); + } +} -// // ) -// // } -// todo!() -// } -// } +struct ContextElement<'r> { + fail_matcher: ChainBehavior<'r>, +} -// enum ChainBehavior<'r> { -// AndParent(Option<&'r MatcherRef>), -// IgnoreParent(Option<&'r MatcherRef>), -// } +enum ChainBehavior<'r> { + AndParent(Option<&'r Matcher>), + IgnoreParent(Option<&'r Matcher>), +}