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.
This commit is contained in:
Tom Alexander 2023-04-10 10:49:28 -04:00
parent 9a0172e1a4
commit 137815dbaf
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 16 additions and 2 deletions

View File

@ -31,6 +31,12 @@ impl<T> List<T> {
List { head: None }
}
pub fn branch_from(trunk: &Rc<Node<T>>) -> Self {
List {
head: Some(trunk.clone()),
}
}
pub fn push_front(&self, data: T) -> List<T> {
List {
head: Some(Rc::new(Node {

View File

@ -22,6 +22,12 @@ impl<'r, 's> ContextTree<'r, 's> {
ContextTree { tree: List::new() }
}
pub fn branch_from(trunk: &Rc<Node<ContextElement<'r, 's>>>) -> 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;
}