summary refs log tree commit diff stats
path: root/abdl/_vm.py
diff options
context:
space:
mode:
Diffstat (limited to 'abdl/_vm.py')
-rw-r--r--abdl/_vm.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/abdl/_vm.py b/abdl/_vm.py
index 5ab7efb..2f76586 100644
--- a/abdl/_vm.py
+++ b/abdl/_vm.py
@@ -255,7 +255,15 @@ class ApplyPredicate(PatternElement):
 
     def on_end(self, frame, path, defs, in_key):
         assert not in_key
-        raise NotImplementedError
+        res = {}
+        for holder in path:
+            if holder.subtree:
+                for name, pair in holder.match.items():
+                    res[name] = pair
+            elif holder.name is not None:
+                res[holder.name] = (holder.match, holder.value)
+        path.clear()
+        return (False, res)
 
 class End(PatternElement):
     """Pseudo-token, used to advance iteration."""
@@ -282,7 +290,8 @@ class End(PatternElement):
             elif holder.name is not None:
                 res[holder.name] = (holder.match, holder.value)
         if not frame.prev():
-            return (None, res)
+            # this should never happen
+            assert False
         return (True, res)
 
     @classmethod
@@ -382,6 +391,7 @@ def match_helper(ops, defs, tree):
 
     frame = _Frame(ops)
     if not len(frame.ops): # no ops?
+        yield {}
         return # do nothing
 
     path = [Holder(value=tree, parent=None, iterator=iter(()))]
@@ -390,8 +400,6 @@ def match_helper(ops, defs, tree):
         if not frame.next():
             in_key, res = frame.current_op.on_end(frame, path, defs, in_key)
             yield res
-            if in_key is None:
-                return
         else:
             if in_key:
                 in_key = frame.current_op.on_in_key(frame, path, defs)