[pypy-svn] r16601 - pypy/dist/pypy/module/_sre

nik at codespeak.net nik at codespeak.net
Fri Aug 26 13:18:03 CEST 2005


Author: nik
Date: Fri Aug 26 13:18:02 2005
New Revision: 16601

Modified:
   pypy/dist/pypy/module/_sre/app_sre.py
   pypy/dist/pypy/module/_sre/interp_sre.py
Log:
moved op_assert and op_assert_not to interp-level.


Modified: pypy/dist/pypy/module/_sre/app_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/app_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/app_sre.py	Fri Aug 26 13:18:02 2005
@@ -566,36 +566,6 @@
             repeat.count = count - 1
             ctx.state.string_position = ctx.string_position
         yield True
-
-    def op_assert(self, ctx):
-        # assert subpattern
-        # <ASSERT> <skip> <back> <pattern>
-        #self._log(ctx, "ASSERT", ctx.peek_code(2))
-        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
-        if ctx.state.string_position < 0:
-            ctx.has_matched = NOT_MATCHED
-            yield True
-        child_context = ctx.push_new_context(3)
-        yield False
-        if child_context.has_matched == MATCHED:
-            ctx.skip_code(ctx.peek_code(1) + 1)
-        else:
-            ctx.has_matched = NOT_MATCHED
-        yield True
-
-    def op_assert_not(self, ctx):
-        # assert not subpattern
-        # <ASSERT_NOT> <skip> <back> <pattern>
-        #self._log(ctx, "ASSERT_NOT", ctx.peek_code(2))
-        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
-        if ctx.state.string_position >= 0:
-            child_context = ctx.push_new_context(3)
-            yield False
-            if child_context.has_matched == MATCHED:
-                ctx.has_matched = NOT_MATCHED
-                yield True
-        ctx.skip_code(ctx.peek_code(1) + 1)
-        yield True
         
     def unknown(self, ctx):
         #self._log(ctx, "UNKNOWN", ctx.peek_code())

Modified: pypy/dist/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/interp_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/interp_sre.py	Fri Aug 26 13:18:02 2005
@@ -319,6 +319,7 @@
         if not has_finished:
             context.resume_at_opcode = opcode
             return context.UNDECIDED
+        context.resume_at_opcode = -1
     if context.has_matched == context.UNDECIDED:
         context.has_matched = context.NOT_MATCHED
     return context.has_matched
@@ -629,7 +630,7 @@
     # <GROUPREF_IGNORE> <zero-based group index>
     return general_op_groupref(space, ctx, ignore=True)
 
-def op_groupref_exists(self, ctx):
+def op_groupref_exists(space, ctx):
     # <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ...
     group_start, group_end = ctx.state.get_marks(ctx.peek_code(1))
     if group_start == -1 or group_end == -1 or group_end < group_start:
@@ -638,6 +639,38 @@
         ctx.skip_code(3)
     return True
 
+def op_assert(space, ctx):
+    # assert subpattern
+    # <ASSERT> <skip> <back> <pattern>
+    if not ctx.is_resumed():
+        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
+        if ctx.state.string_position < 0:
+            ctx.has_matched = ctx.NOT_MATCHED
+            return True
+        ctx.push_new_context(3)
+        return False
+    else:
+        if ctx.child_context.has_matched == ctx.MATCHED:
+            ctx.skip_code(ctx.peek_code(1) + 1)
+        else:
+            ctx.has_matched = ctx.NOT_MATCHED
+        return True
+
+def op_assert_not(space, ctx):
+    # assert not subpattern
+    # <ASSERT_NOT> <skip> <back> <pattern>
+    if not ctx.is_resumed():
+        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
+        if ctx.state.string_position >= 0:
+            ctx.push_new_context(3)
+            return False
+    else:
+        if ctx.child_context.has_matched == ctx.MATCHED:
+            ctx.has_matched = ctx.NOT_MATCHED
+            return True
+    ctx.skip_code(ctx.peek_code(1) + 1)
+    return True
+
 def count_repetitions(space, ctx, maxcount):
     """Returns the number of repetitions of a single item, starting from the
     current string position. The code pointer is expected to point to a
@@ -669,7 +702,7 @@
 opcode_dispatch_table = [
     op_failure, op_success,
     op_any, op_any_all,
-    None, None, #ASSERT, ASSERT_NOT,
+    op_assert, op_assert_not,
     op_at,
     op_branch,
     None, #CALL,



More information about the Pypy-commit mailing list