Skip to content

Commit e82c94d

Browse files
committed
[GR-14734] Remove deprecated TRegex API usages.
PullRequest: graalpython/455
2 parents 4eb7a17 + 26379ed commit e82c94d

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128

129129
local labsjdk8Mixin = {
130130
downloads +: {
131-
JAVA_HOME: utils.download("labsjdk", "8u202-jvmci-0.55"),
131+
JAVA_HOME: utils.download("labsjdk", "8u202-jvmci-0.57"),
132132
EXTRA_JAVA_HOMES : { pathlist: [utils.download("oraclejdk", "11+20")] },
133133
},
134134
environment +: {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@
5757
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
5858
import com.oracle.graal.python.builtins.objects.str.PString;
5959
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
60-
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
60+
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6161
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6262
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
6363
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6464
import com.oracle.truffle.api.CompilerAsserts;
6565
import com.oracle.truffle.api.CompilerDirectives;
6666
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
67+
import com.oracle.truffle.api.TruffleException;
6768
import com.oracle.truffle.api.dsl.Cached;
6869
import com.oracle.truffle.api.dsl.Fallback;
6970
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -78,7 +79,6 @@
7879
import com.oracle.truffle.api.library.CachedLibrary;
7980
import com.oracle.truffle.api.profiles.BranchProfile;
8081
import com.oracle.truffle.api.source.Source;
81-
import com.oracle.truffle.regex.RegexSyntaxException;
8282

8383
@CoreFunctions(defineModule = "_sre")
8484
public class SREModuleBuiltins extends PythonBuiltins {
@@ -186,25 +186,25 @@ private BytesNodes.ToBytesNode getToBytesNode() {
186186
@Builtin(name = "tregex_call_compile", minNumOfPositionalArgs = 3)
187187
@TypeSystemReference(PythonArithmeticTypes.class)
188188
@GenerateNodeFactory
189-
abstract static class TRegexCallCompile extends PythonBuiltinNode {
189+
abstract static class TRegexCallCompile extends PythonTernaryBuiltinNode {
190190

191-
@Specialization(guards = "isForeignObject(callable)")
191+
@Specialization(guards = "isForeignObject(callable)", limit = "1")
192192
Object call(TruffleObject callable, Object arg1, Object arg2,
193193
@Cached("create()") BranchProfile syntaxError,
194194
@Cached("create()") BranchProfile typeError,
195-
@CachedLibrary(limit = "1") InteropLibrary interop) {
195+
@CachedLibrary("callable") InteropLibrary interop) {
196196
try {
197197
return interop.execute(callable, arg1, arg2);
198198
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
199199
typeError.enter();
200200
throw raise(TypeError, "%s", e);
201-
} catch (RegexSyntaxException e) {
202-
syntaxError.enter();
203-
if (e.getPosition() == -1) {
204-
throw raise(ValueError, "%s", e.getReason());
205-
} else {
206-
throw raise(ValueError, "%s at position %d", e.getReason(), e.getPosition());
201+
} catch (RuntimeException e) {
202+
if (e instanceof TruffleException && ((TruffleException) e).isSyntaxError()) {
203+
syntaxError.enter();
204+
throw raise(ValueError, "%s", e);
207205
}
206+
// just re-throw
207+
throw e;
208208
}
209209
}
210210

@@ -218,12 +218,12 @@ Object call(Object callable, Object arg1, Object arg2) {
218218
@Builtin(name = "tregex_call_exec", minNumOfPositionalArgs = 3)
219219
@TypeSystemReference(PythonArithmeticTypes.class)
220220
@GenerateNodeFactory
221-
abstract static class TRegexCallExec extends PythonBuiltinNode {
221+
abstract static class TRegexCallExec extends PythonTernaryBuiltinNode {
222222

223-
@Specialization(guards = "isForeignObject(callable)")
223+
@Specialization(guards = "isForeignObject(callable)", limit = "1")
224224
Object call(TruffleObject callable, Object arg1, Number arg2,
225225
@Cached("create()") BranchProfile typeError,
226-
@CachedLibrary(limit = "1") InteropLibrary interop) {
226+
@CachedLibrary("callable") InteropLibrary interop) {
227227
try {
228228
return interop.execute(callable, arg1, arg2);
229229
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {

graalpython/lib-graalpython/_sre.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def __init__(self, pattern_input, isMatch, groupCount, start, end):
5454
self.input = pattern_input
5555
self.isMatch = isMatch
5656
self.groupCount = groupCount
57-
self.start = start
58-
self.end = end
57+
self._start = start
58+
self._end = end
5959

6060
def getStart(self, grpidx):
61-
return self.start[grpidx]
61+
return self._start[grpidx]
6262

6363
def getEnd(self, grpidx):
64-
return self.end[grpidx]
64+
return self._end[grpidx]
6565

6666

6767
def _str_to_bytes(arg):
@@ -158,7 +158,7 @@ def __init__(self, pattern, pos, endpos, result, input_str, compiled_regex):
158158
self.input_str = input_str
159159

160160
def end(self, groupnum=0):
161-
return self.result.end[groupnum]
161+
return self.result.getEnd(groupnum)
162162

163163
def group(self, *args):
164164
if not args:
@@ -185,11 +185,11 @@ def __groupidx__(self, idx):
185185

186186
def __group__(self, idx):
187187
idxarg = self.__groupidx__(idx)
188-
start = self.result.start[idxarg]
188+
start = self.result.getStart(idxarg)
189189
if start < 0:
190190
return None
191191
else:
192-
return self.input_str[start:self.result.end[idxarg]]
192+
return self.input_str[start:self.result.getEnd(idxarg)]
193193

194194
def groupdict(self, default=None):
195195
d = {}
@@ -202,11 +202,11 @@ def groupdict(self, default=None):
202202

203203
def span(self, groupnum=0):
204204
idxarg = self.__groupidx__(groupnum)
205-
return (self.result.start[idxarg], self.result.end[idxarg])
205+
return (self.result.getStart(idxarg), self.result.getEnd(idxarg))
206206

207207
def start(self, groupnum=0):
208208
idxarg = self.__groupidx__(groupnum)
209-
return self.result.start[idxarg]
209+
return self.result.getStart(idxarg)
210210

211211
@property
212212
def string(self):
@@ -218,7 +218,7 @@ def lastgroup(self):
218218

219219
@property
220220
def lastindex(self):
221-
return self.result.end[0]
221+
return self.result.getEnd(0)
222222

223223
def __repr__(self):
224224
return "<re.Match object; span=%r, match=%r>" % (self.span(), self.group())
@@ -341,8 +341,8 @@ def finditer(self, string, pos=0, endpos=-1):
341341
break
342342
else:
343343
yield SRE_Match(self, pos, endpos, result, string, compiled_regex)
344-
no_progress = (result.start[0] == result.end[0])
345-
pos = result.end[0] + no_progress
344+
no_progress = (result.getStart(0) == result.getEnd(0))
345+
pos = result.getEnd(0) + no_progress
346346
return
347347

348348
def findall(self, string, pos=0, endpos=-1):
@@ -358,21 +358,21 @@ def findall(self, string, pos=0, endpos=-1):
358358
if not result.isMatch:
359359
break
360360
elif result.groupCount == 1:
361-
matchlist.append(self.__sanitize_out_type(string[result.start[0]:result.end[0]]))
361+
matchlist.append(self.__sanitize_out_type(string[result.getStart(0):result.getEnd(0)]))
362362
elif result.groupCount == 2:
363-
matchlist.append(self.__sanitize_out_type(string[result.start[1]:result.end[1]]))
363+
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())))
366-
no_progress = (result.start[0] == result.end[0])
367-
pos = result.end[0] + no_progress
366+
no_progress = (result.getStart(0) == result.getEnd(0))
367+
pos = result.getEnd(0) + no_progress
368368
return matchlist
369369

370370
def __replace_groups(self, repl, string, match_result, pattern):
371371
def group(match_result, group_nr, string):
372372
if group_nr >= match_result.groupCount:
373373
return None
374-
group_start = match_result.start[group_nr]
375-
group_end = match_result.end[group_nr]
374+
group_start = match_result.getStart(group_nr)
375+
group_end = match_result.getEnd(group_nr)
376376
return string[group_start:group_end]
377377

378378
n = len(repl)
@@ -442,8 +442,8 @@ def sub(self, repl, string, count=0):
442442
if not match_result.isMatch:
443443
break
444444
n += 1
445-
start = match_result.start[0]
446-
end = match_result.end[0]
445+
start = match_result.getStart(0)
446+
end = match_result.getEnd(0)
447447
result.append(string[pos:start])
448448
if is_string_rep:
449449
result.append(self.__replace_groups(repl, string, match_result, pattern))
@@ -473,14 +473,14 @@ def split(self, string, maxsplit=0):
473473
if not match_result.isMatch:
474474
break
475475
n += 1
476-
start = match_result.start[0]
477-
end = match_result.end[0]
476+
start = match_result.getStart(0)
477+
end = match_result.getEnd(0)
478478
result.append(self.__sanitize_out_type(string[collect_pos:start]))
479479
# add all group strings
480480
for i in range(1, match_result.groupCount):
481-
groupStart = match_result.start[i]
481+
groupStart = match_result.getStart(i)
482482
if groupStart >= 0:
483-
result.append(self.__sanitize_out_type(string[groupStart:match_result.end[i]]))
483+
result.append(self.__sanitize_out_type(string[groupStart:match_result.getEnd(i)]))
484484
else:
485485
result.append(None)
486486
collect_pos = end

mx.graalpython/suite.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
},
4545
{
4646
"name": "sulong",
47-
"version": "364b9c253ef58a82ce3601b8588f13b9777ca50f",
47+
"version": "f7f14f5d4d9ac7c2537932810082fc9f54cb635e",
4848
"subdir": True,
4949
"urls": [
5050
{"url": "https://github.com/oracle/graal", "kind": "git"},
5151
]
5252
},
5353
{
5454
"name": "regex",
55-
"version": "364b9c253ef58a82ce3601b8588f13b9777ca50f",
55+
"version": "f7f14f5d4d9ac7c2537932810082fc9f54cb635e",
5656
"subdir": True,
5757
"urls": [
5858
{"url": "https://github.com/oracle/graal", "kind": "git"},
@@ -190,7 +190,6 @@
190190
"truffle:TRUFFLE_API",
191191
"sdk:GRAAL_SDK",
192192
"truffle:ANTLR4",
193-
"regex:TREGEX",
194193
"sulong:SULONG",
195194
],
196195
"buildDependencies": ["com.oracle.graal.python.parser.antlr"],

0 commit comments

Comments
 (0)