[pypy-svn] r75799 - in pypy/branch/rsre2/pypy/rlib/rsre: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Jul 2 22:38:10 CEST 2010
Author: arigo
Date: Fri Jul 2 22:38:08 2010
New Revision: 75799
Modified:
pypy/branch/rsre2/pypy/rlib/rsre/rsre.py
pypy/branch/rsre2/pypy/rlib/rsre/test/test_match.py
Log:
Add a convenient method.
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 22:38:08 2010
@@ -37,8 +37,10 @@
class MatchContext(object):
+ match_start = 0
match_end = 0
match_marks = None
+ match_marks_flat = None
def __init__(self, pattern, string, flags):
self.pattern = pattern
@@ -59,9 +61,23 @@
return rsre_char.getlower(c, self.flags)
def get_mark(self, gid):
- """Use this for testing."""
return find_mark(self.match_marks, gid)
+ def flatten_marks(self):
+ # for testing
+ if self.match_marks_flat is None:
+ self.match_marks_flat = [self.match_start, self.match_end]
+ mark = self.match_marks
+ while mark is not None:
+ index = mark.gid + 2
+ while index >= len(self.match_marks_flat):
+ self.match_marks_flat.append(-1)
+ if self.match_marks_flat[index] == -1:
+ self.match_marks_flat[index] = mark.position
+ mark = mark.prev
+ self.match_marks = None # clear
+ return self.match_marks_flat
+
class Mark(object):
_immutable_ = True
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 22:38:08 2010
@@ -150,3 +150,13 @@
r, _ = get_code(r"(?i)[^a]+$")
assert rsre.match(r, "Gx123")
assert not rsre.match(r, "--A--")
+
+ def test_repeated_single_character_pattern(self):
+ r, _ = get_code(r"foo(?:(?<=foo)x)+$")
+ assert rsre.match(r, "foox")
+
+ def test_flatten_marks(self):
+ r, _ = get_code(r"a(b)c((d)(e))+$")
+ res = rsre.match(r, "abcdedede")
+ assert res.flatten_marks() == [0, 9, 1, 2, 7, 9, 7, 8, 8, 9]
+ assert res.flatten_marks() == [0, 9, 1, 2, 7, 9, 7, 8, 8, 9]
More information about the Pypy-commit
mailing list