From 137815dbaf7f27bd03fa06800f17e0992a4f746c Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 10 Apr 2023 10:49:28 -0400 Subject: [PATCH] Only use a local context when checking exit matchers. This prevents context tree from deeper in the parse impacting exit checks for earlier in the parse. This is needed due to the trailing whitespace context element. --- src/parser/list.rs | 6 ++++++ src/parser/parser_context.rs | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/parser/list.rs b/src/parser/list.rs index 6a91cb7..95abb3d 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -31,6 +31,12 @@ impl List { List { head: None } } + pub fn branch_from(trunk: &Rc>) -> Self { + List { + head: Some(trunk.clone()), + } + } + pub fn push_front(&self, data: T) -> List { List { head: Some(Rc::new(Node { diff --git a/src/parser/parser_context.rs b/src/parser/parser_context.rs index 9c2a411..121e616 100644 --- a/src/parser/parser_context.rs +++ b/src/parser/parser_context.rs @@ -22,6 +22,12 @@ impl<'r, 's> ContextTree<'r, 's> { ContextTree { tree: List::new() } } + pub fn branch_from(trunk: &Rc>>) -> Self { + ContextTree { + tree: List::branch_from(trunk) + } + } + pub fn ptr_eq<'x, 'y>(&self, other: &ContextTree<'x, 'y>) -> bool { self.tree.ptr_eq(&other.tree) } @@ -76,14 +82,16 @@ impl<'r, 's> ContextTree<'r, 's> { ContextElement::ExitMatcherNode(exit_matcher) => { match exit_matcher.exit_matcher { ChainBehavior::AndParent(Some(matcher)) => { - let local_result = matcher(self, i); + let local_context = ContextTree::branch_from(current_node); + let local_result = matcher(&local_context, i); if local_result.is_ok() { return local_result; } } ChainBehavior::AndParent(None) => {} ChainBehavior::IgnoreParent(Some(matcher)) => { - let local_result = matcher(self, i); + let local_context = ContextTree::branch_from(current_node); + let local_result = matcher(&local_context, i); if local_result.is_ok() { return local_result; }