[pypy-svn] r75789 - in pypy/branch/rsre2/pypy/rlib/rsre: . test

arigo at codespeak.net arigo at codespeak.net
Fri Jul 2 19:57:33 CEST 2010


Author: arigo
Date: Fri Jul  2 19:57:31 2010
New Revision: 75789

Modified:
   pypy/branch/rsre2/pypy/rlib/rsre/rsre.py
   pypy/branch/rsre2/pypy/rlib/rsre/test/test_match.py
Log:
NOT_LITERAL.


Modified: pypy/branch/rsre2/pypy/rlib/rsre/rsre.py
==============================================================================
--- pypy/branch/rsre2/pypy/rlib/rsre/rsre.py	(original)
+++ pypy/branch/rsre2/pypy/rlib/rsre/rsre.py	Fri Jul  2 19:57:31 2010
@@ -25,6 +25,8 @@
 OPCODE_MARK               = 21
 OPCODE_MAX_UNTIL          = 22
 OPCODE_MIN_UNTIL          = 23
+OPCODE_NOT_LITERAL        = 24
+OPCODE_NOT_LITERAL_IGNORE = 25
 OPCODE_REPEAT             = 28
 OPCODE_REPEAT_ONE         = 29
 OPCODE_MIN_REPEAT_ONE     = 31
@@ -225,6 +227,14 @@
             marks = Mark(gid, ptr, marks)
             ppos += 1
 
+        elif op == OPCODE_NOT_LITERAL:
+            # match if it's not a literal string
+            # <NOT_LITERAL> <code>
+            if ptr >= ctx.end or ctx.lowstr(ptr) == ctx.pat(ppos):
+                return False
+            ppos += 1
+            ptr += 1
+
         elif op == OPCODE_REPEAT:
             # general repeat.  in this version of the re module, all the work
             # is done here, and not on the later UNTIL operator.
@@ -395,6 +405,11 @@
         while ptr < end and ctx.lowstr(ptr) == chr:
             ptr += 1
 
+    elif op == OPCODE_NOT_LITERAL:
+        chr = ctx.pat(ppos+1)
+        while ptr < end and ctx.str(ptr) != chr:
+            ptr += 1
+
     else:
         assert 0, "XXX %d" % op
 

Modified: pypy/branch/rsre2/pypy/rlib/rsre/test/test_match.py
==============================================================================
--- pypy/branch/rsre2/pypy/rlib/rsre/test/test_match.py	(original)
+++ pypy/branch/rsre2/pypy/rlib/rsre/test/test_match.py	Fri Jul  2 19:57:31 2010
@@ -133,3 +133,11 @@
         assert rsre.match(r, "bCdEf")
         assert not rsre.match(r, "g")
         assert not rsre.match(r, "aaagaaa")
+
+    def test_not_literal(self):
+        r, _ = get_code(r"[^a-f]")
+        assert rsre.match(r, "B")
+        assert not rsre.match(r, "b")
+        r, _ = get_code(r"[^a-f]+$")
+        assert rsre.match(r, "Bx123")
+        assert not rsre.match(r, "--f--")



More information about the Pypy-commit mailing list