[pypy-commit] pypy default: disable some features to make group RPython, a fair bit controversial, maybe I should make rgroup iface or so

fijal noreply at buildbot.pypy.org
Wed Apr 4 20:30:51 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r54175:52f2110eff80
Date: 2012-04-04 20:30 +0200
http://bitbucket.org/pypy/pypy/changeset/52f2110eff80/

Log:	disable some features to make group RPython, a fair bit
	controversial, maybe I should make rgroup iface or so

diff --git a/pypy/rlib/rsre/rsre_re.py b/pypy/rlib/rsre/rsre_re.py
--- a/pypy/rlib/rsre/rsre_re.py
+++ b/pypy/rlib/rsre/rsre_re.py
@@ -172,8 +172,9 @@
         self._ctx = ctx
 
     def span(self, groupnum=0):
-        if not isinstance(groupnum, (int, long)):
-            groupnum = self.re.groupindex[groupnum]
+#        if not isinstance(groupnum, (int, long)):
+#            groupnum = self.re.groupindex[groupnum]
+ 
         return self._ctx.span(groupnum)
 
     def start(self, groupnum=0):
@@ -182,19 +183,25 @@
     def end(self, groupnum=0):
         return self.span(groupnum)[1]
 
-    def group(self, *groups):
-        groups = groups or (0,)
-        result = []
-        for group in groups:
-            frm, to = self.span(group)
-            if 0 <= frm <= to:
-                result.append(self._ctx._string[frm:to])
-            else:
-                result.append(None)
-        if len(result) > 1:
-            return tuple(result)
+    def group(self, group=0):
+        frm, to = self.span(group)
+        if 0 <= frm <= to:
+            return self._ctx._string[frm:to]
         else:
-            return result[0]
+            return None
+
+#    def group(self, *groups):
+#        groups = groups or (0,)
+#        result = []
+#        for group in groups:
+#            frm, to = self.span(group)
+#            if 0 <= frm <= to:
+#                result.append(self._ctx._string[frm:to])
+#            else:
+#                result.append(None)
+#        if len(result) > 1:
+#            return tuple(result)
+
 
     def groups(self, default=None):
         fmarks = self._ctx.flatten_marks()
diff --git a/pypy/rlib/rsre/test/test_re.py b/pypy/rlib/rsre/test/test_re.py
--- a/pypy/rlib/rsre/test/test_re.py
+++ b/pypy/rlib/rsre/test/test_re.py
@@ -204,7 +204,7 @@
         assert re.match('(a)', 'a').groups() == ('a',)
         assert re.match(r'(a)', 'a').group(0) == 'a'
         assert re.match(r'(a)', 'a').group(1) == 'a'
-        assert re.match(r'(a)', 'a').group(1, 1) == ('a', 'a')
+        #assert re.match(r'(a)', 'a').group(1, 1) == ('a', 'a')
 
         pat = re.compile('((a)|(b))(c)?')
         assert pat.match('a').groups() == ('a', 'a', None, None)
@@ -218,13 +218,13 @@
         assert m.group(0) == 'a'
         assert m.group(0) == 'a'
         assert m.group(1) == 'a'
-        assert m.group(1, 1) == ('a', 'a')
+        #assert m.group(1, 1) == ('a', 'a')
 
         pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
-        assert pat.match('a').group(1, 2, 3) == ('a', None, None)
-        assert pat.match('b').group('a1', 'b2', 'c3') == (
-                         (None, 'b', None))
-        assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
+        #assert pat.match('a').group(1, 2, 3) == ('a', None, None)
+        #assert pat.match('b').group('a1', 'b2', 'c3') == (
+        #                 (None, 'b', None))
+        #assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
 
     def test_bug_923(self):
         # Issue923: grouping inside optional lookahead problem
diff --git a/pypy/rlib/rsre/test/test_zinterp.py b/pypy/rlib/rsre/test/test_zinterp.py
--- a/pypy/rlib/rsre/test/test_zinterp.py
+++ b/pypy/rlib/rsre/test/test_zinterp.py
@@ -1,7 +1,8 @@
 # minimal test: just checks that (parts of) rsre can be translated
 
-from pypy.rpython.test.test_llinterp import gengraph
+from pypy.rpython.test.test_llinterp import gengraph, interpret
 from pypy.rlib.rsre import rsre_core
+from pypy.rlib.rsre.rsre_re import compile
 
 def main(n):
     assert n >= 0
@@ -19,3 +20,18 @@
 
 def test_gengraph():
     t, typer, graph = gengraph(main, [int])
+
+m = compile("(a|b)aaaaa")
+
+def test_match():
+    def f(i):
+        if i:
+            s = "aaaaaa"
+        else:
+            s = "caaaaa"
+        g = m.match(s)
+        if g is None:
+            return 3
+        return int("aaaaaa" == g.group(0))
+    assert interpret(f, [3]) == 1
+    assert interpret(f, [0]) == 3


More information about the pypy-commit mailing list