From 2a595e2b6c41a579082f8e836d856a3a290de6e7 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 10 Dec 2022 22:04:39 -0500 Subject: [PATCH] Implement ptr_eq on the context types. --- src/parser/list.rs | 8 ++++++++ src/parser/nom_context.rs | 4 ++++ src/parser/text_element_parser.rs | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/src/parser/list.rs b/src/parser/list.rs index b2df6de6..bd891b1e 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -64,4 +64,12 @@ impl List { pub fn is_empty(&self) -> bool { self.head.is_none() } + + pub fn ptr_eq(&self, other: &List) -> bool { + match (self.head.as_ref(), other.head.as_ref()) { + (None, None) => true, + (None, Some(_)) | (Some(_), None) => false, + (Some(me), Some(them)) => Rc::ptr_eq(me, them), + } + } } diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 3d72600a..64e3422e 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -18,6 +18,10 @@ impl<'r> ContextTree<'r> { ContextTree { tree: List::new() } } + pub fn ptr_eq<'x>(&self, other: &ContextTree<'x>) -> bool { + self.tree.ptr_eq(&other.tree) + } + pub fn with_additional_node(&self, data: ContextElement<'r>) -> ContextTree<'r> { let new_list = self.tree.push_front(data); ContextTree { tree: new_list } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index c6215337..f30ead29 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -62,6 +62,11 @@ where match till_matcher(¤t_context, i.clone()) { Ok((remaining, finish)) => { let mut ret = Vec::new(); + while !current_context.ptr_eq(context) { + // todo + todo!() + } + // while current_context.tr // TODO build a vec of the elements by popping off the newest elements of the context return Ok((remaining, (ret, finish))); }