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; }