From 8dcb1318d6e61fcf55dcc1617e5e0562109a91e9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 24 Nov 2022 15:06:07 -0500 Subject: [PATCH] Working by exposing the node type. --- src/parser/nom_context.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 0cfa096e..60ba9def 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -7,30 +7,30 @@ use nom::error::VerboseError; use nom::IResult; use nom::Parser; -type Link = Option>>; +type Link<'r, T> = Option<&'r Node<'r, T>>; type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; -struct Node { +pub struct Node<'r, T> { elem: T, - next: Link, + next: Link<'r, T>, } -pub struct List { - head: Link, +pub struct List<'r, T> { + head: Link<'r, T>, } -impl List { +impl<'r, T> List<'r, T> { pub fn new() -> Self { List { head: None } } - pub fn push(&mut self, element: T) { - let new_node = Box::new(Node { + pub fn with_additional_node(&self, element: T) -> Node<'r, T> { + let new_node = Node { elem: element, - next: self.head.take(), - }); + next: self.head, + }; - self.head = Some(new_node); + new_node } }