Skip to content

Commit 673445e

Browse files
committed
Add Match.scanner
1 parent c18dbd8 commit 673445e

File tree

2 files changed

+31
-0
lines changed
  • graalpython

2 files changed

+31
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_re.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_448951
2929
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_449000
3030
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_449964
31+
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_581080
3132
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_612074
3233
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_6509
3334
*graalpython.lib-python.3.test.test_re.ReTests.test_bug_6561
@@ -58,6 +59,7 @@
5859
*graalpython.lib-python.3.test.test_re.ReTests.test_ignore_case_set
5960
*graalpython.lib-python.3.test.test_re.ReTests.test_issue17998
6061
*graalpython.lib-python.3.test.test_re.ReTests.test_keep_buffer
62+
*graalpython.lib-python.3.test.test_re.ReTests.test_keyword_parameters
6163
*graalpython.lib-python.3.test.test_re.ReTests.test_large_search
6264
*graalpython.lib-python.3.test.test_re.ReTests.test_large_subn
6365
*graalpython.lib-python.3.test.test_re.ReTests.test_lookahead

graalpython/lib-graalpython/_sre.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,35 @@ def split(self, string, maxsplit=0):
529529
result.append(self.__sanitize_out_type(string[collect_pos:]))
530530
return result
531531

532+
def scanner(self, string, pos=0, endpos=None):
533+
return SREScanner(self, string, pos, endpos)
534+
535+
536+
class SREScanner(object):
537+
def __init__(self, pattern, string, start, end):
538+
self.pattern = pattern
539+
self._string = string
540+
self._start = start
541+
self._end = end
542+
543+
def _match_search(self, matcher):
544+
if self._start > len(self._string):
545+
return None
546+
match = matcher(self._string, self._start, self._end)
547+
if match is None:
548+
self._start += 1
549+
else:
550+
self._start = match.end()
551+
if match.start() == self._start:
552+
self._start += 1
553+
return match
554+
555+
def match(self):
556+
return self._match_search(self.pattern.match)
557+
558+
def search(self):
559+
return self._match_search(self.pattern.search)
560+
532561

533562
_t_compile = Pattern
534563

0 commit comments

Comments
 (0)