Skip to content

Commit 9d4b9ce

Browse files
committed
[GR-14876] Move access to property 'groupCount' from regex result to pattern.
PullRequest: graalpython/469
2 parents 45d5096 + b4bbcf4 commit 9d4b9ce

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

graalpython/lib-graalpython/_sre.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def group(self, *args):
173173

174174
def groups(self, default=None):
175175
lst = []
176-
for arg in range(1, self.result.groupCount):
176+
for arg in range(1, self.compiled_regex.groupCount):
177177
lst.append(self.__group__(arg))
178178
return tuple(lst)
179179

@@ -214,7 +214,7 @@ def string(self):
214214

215215
@property
216216
def lastgroup(self):
217-
return self.result.groupCount
217+
return self.compiled_regex.groupCount
218218

219219
@property
220220
def lastindex(self):
@@ -357,9 +357,9 @@ def findall(self, string, pos=0, endpos=-1):
357357
result = tregex_call_exec(compiled_regex.exec, string, pos)
358358
if not result.isMatch:
359359
break
360-
elif result.groupCount == 1:
360+
elif compiled_regex.groupCount == 1:
361361
matchlist.append(self.__sanitize_out_type(string[result.getStart(0):result.getEnd(0)]))
362-
elif result.groupCount == 2:
362+
elif compiled_regex.groupCount == 2:
363363
matchlist.append(self.__sanitize_out_type(string[result.getStart(1):result.getEnd(1)]))
364364
else:
365365
matchlist.append(tuple(map(self.__sanitize_out_type, SRE_Match(self, pos, endpos, result, string, compiled_regex).groups())))
@@ -368,8 +368,8 @@ def findall(self, string, pos=0, endpos=-1):
368368
return matchlist
369369

370370
def __replace_groups(self, repl, string, match_result, pattern):
371-
def group(match_result, group_nr, string):
372-
if group_nr >= match_result.groupCount:
371+
def group(pattern, match_result, group_nr, string):
372+
if group_nr >= pattern.groupCount:
373373
return None
374374
group_start = match_result.getStart(group_nr)
375375
group_end = match_result.getEnd(group_nr)
@@ -382,18 +382,18 @@ def group(match_result, group_nr, string):
382382
pos = repl.find(backslash, start)
383383
while pos != -1 and start < n:
384384
if pos+1 < n:
385-
if repl[pos + 1].isdigit() and match_result.groupCount > 0:
385+
if repl[pos + 1].isdigit() and pattern.groupCount > 0:
386386
# TODO: Should handle backreferences longer than 1 digit and fall back to octal escapes.
387387
group_nr = int(repl[pos+1].decode('ascii')) if self.__binary else int(repl[pos+1])
388-
group_str = group(match_result, group_nr, string)
388+
group_str = group(pattern, match_result, group_nr, string)
389389
if group_str is None:
390390
raise error("invalid group reference %s at position %s" % (group_nr, pos))
391391
result += repl[start:pos] + group_str
392392
start = pos + 2
393393
elif repl[pos + 1] == (b'g' if self.__binary else 'g'):
394394
group_ref, group_ref_end, digits_only = self.__extract_groupname(repl, pos + 2)
395395
if group_ref:
396-
group_str = group(match_result, int(group_ref) if digits_only else pattern.groups[group_ref], string)
396+
group_str = group(pattern, match_result, int(group_ref) if digits_only else pattern.groups[group_ref], string)
397397
if group_str is None:
398398
raise error("invalid group reference %s at position %s" % (group_ref, pos))
399399
result += repl[start:pos] + group_str
@@ -477,7 +477,7 @@ def split(self, string, maxsplit=0):
477477
end = match_result.getEnd(0)
478478
result.append(self.__sanitize_out_type(string[collect_pos:start]))
479479
# add all group strings
480-
for i in range(1, match_result.groupCount):
480+
for i in range(1, pattern.groupCount):
481481
groupStart = match_result.getStart(i)
482482
if groupStart >= 0:
483483
result.append(self.__sanitize_out_type(string[groupStart:match_result.getEnd(i)]))

mx.graalpython/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
},
4545
{
4646
"name": "sulong",
47-
"version": "48408a3a99130928a114cc881ad6badfb9d2210d",
47+
"version": "8312de35e6d63e8be21634a3ffc177bdbc3092e2",
4848
"subdir": True,
4949
"urls": [
5050
{"url": "https://github.com/oracle/graal", "kind": "git"},
5151
]
5252
},
5353
{
5454
"name": "regex",
55-
"version": "48408a3a99130928a114cc881ad6badfb9d2210d",
55+
"version": "8312de35e6d63e8be21634a3ffc177bdbc3092e2",
5656
"subdir": True,
5757
"urls": [
5858
{"url": "https://github.com/oracle/graal", "kind": "git"},

0 commit comments

Comments
 (0)