|
23 | 23 | import org.joni.Option;
|
24 | 24 | import org.joni.Regex;
|
25 | 25 | import org.joni.Region;
|
26 |
| -import org.joni.Syntax; |
27 |
| -import org.joni.exception.SyntaxException; |
28 |
| -import org.joni.exception.ValueException; |
29 | 26 | import org.truffleruby.RubyContext;
|
30 | 27 | import org.truffleruby.builtins.CoreMethod;
|
31 | 28 | import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
|
|
50 | 47 | import org.truffleruby.core.string.StringNodes.StringAppendPrimitiveNode;
|
51 | 48 | import org.truffleruby.core.string.StringOperations;
|
52 | 49 | import org.truffleruby.language.RubyContextNode;
|
53 |
| -import org.truffleruby.language.control.RaiseException; |
54 | 50 | import org.truffleruby.language.dispatch.DispatchNode;
|
55 | 51 |
|
56 | 52 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
@@ -101,17 +97,7 @@ private static Regex makeRegexpForEncoding(RubyContext context, RubyRegexp regex
|
101 | 97 | final RopeBuilder preprocessed = ClassicRegexp
|
102 | 98 | .preprocess(context, sourceRope, enc, fixedEnc, RegexpSupport.ErrorMode.RAISE);
|
103 | 99 | final RegexpOptions options = regexp.options;
|
104 |
| - try { |
105 |
| - return new Regex( |
106 |
| - preprocessed.getUnsafeBytes(), |
107 |
| - 0, |
108 |
| - preprocessed.getLength(), |
109 |
| - options.toJoniOptions(), |
110 |
| - enc, |
111 |
| - new RegexWarnCallback(context)); |
112 |
| - } catch (SyntaxException e) { |
113 |
| - throw new RaiseException(context, context.getCoreExceptions().regexpError(e.getMessage(), currentNode)); |
114 |
| - } |
| 100 | + return ClassicRegexp.makeRegexp(context, preprocessed, options, enc, sourceRope, currentNode); |
115 | 101 | }
|
116 | 102 |
|
117 | 103 | @CoreMethod(names = "union", onSingleton = true, required = 2, rest = true)
|
@@ -433,45 +419,28 @@ public String toString() {
|
433 | 419 | /** WARNING: computeRegexpEncoding() mutates options, so the caller should make sure it's a copy */
|
434 | 420 | @TruffleBoundary
|
435 | 421 | public static Regex compile(RubyContext context, Rope bytes, RegexpOptions options, Node currentNode) {
|
436 |
| - try { |
437 |
| - if (options.isEncodingNone()) { |
438 |
| - bytes = RopeOperations.withEncoding(bytes, ASCIIEncoding.INSTANCE); |
439 |
| - } |
440 |
| - Encoding enc = bytes.getEncoding(); |
441 |
| - Encoding[] fixedEnc = new Encoding[]{ null }; |
442 |
| - RopeBuilder unescaped = ClassicRegexp |
443 |
| - .preprocess(context, bytes, enc, fixedEnc, RegexpSupport.ErrorMode.RAISE); |
444 |
| - enc = ClassicRegexp.computeRegexpEncoding(options, enc, fixedEnc, context); |
445 |
| - |
446 |
| - Regex regexp = new Regex( |
447 |
| - unescaped.getUnsafeBytes(), |
448 |
| - 0, |
449 |
| - unescaped.getLength(), |
450 |
| - options.toJoniOptions(), |
| 422 | + if (options.isEncodingNone()) { |
| 423 | + bytes = RopeOperations.withEncoding(bytes, ASCIIEncoding.INSTANCE); |
| 424 | + } |
| 425 | + Encoding enc = bytes.getEncoding(); |
| 426 | + Encoding[] fixedEnc = new Encoding[]{ null }; |
| 427 | + RopeBuilder unescaped = ClassicRegexp |
| 428 | + .preprocess(context, bytes, enc, fixedEnc, RegexpSupport.ErrorMode.RAISE); |
| 429 | + enc = ClassicRegexp.computeRegexpEncoding(options, enc, fixedEnc, context); |
| 430 | + |
| 431 | + Regex regexp = ClassicRegexp.makeRegexp(context, unescaped, options, enc, bytes, currentNode); |
| 432 | + regexp.setUserObject(RopeOperations.withEncoding(bytes, enc)); |
| 433 | + |
| 434 | + if (context.getOptions().REGEXP_INSTRUMENT_CREATION) { |
| 435 | + final RegexpCacheKey key = new RegexpCacheKey( |
| 436 | + bytes, |
451 | 437 | enc,
|
452 |
| - Syntax.RUBY, |
453 |
| - new RegexWarnCallback(context)); |
454 |
| - regexp.setUserObject(RopeOperations.withEncoding(bytes, enc)); |
455 |
| - |
456 |
| - if (context.getOptions().REGEXP_INSTRUMENT_CREATION) { |
457 |
| - final RegexpCacheKey key = new RegexpCacheKey( |
458 |
| - bytes, |
459 |
| - enc, |
460 |
| - options.toJoniOptions(), |
461 |
| - context.getHashing(REHASH_COMPILED_REGEXPS)); |
462 |
| - ConcurrentOperations.getOrCompute(compiledRegexps, key, x -> new AtomicInteger()).incrementAndGet(); |
463 |
| - } |
464 |
| - |
465 |
| - return regexp; |
466 |
| - } catch (ValueException e) { |
467 |
| - throw new RaiseException( |
468 |
| - context, |
469 |
| - context.getCoreExceptions().regexpError( |
470 |
| - e.getMessage() + ": " + '/' + RopeOperations.decodeRope(bytes) + '/', |
471 |
| - currentNode)); |
472 |
| - } catch (SyntaxException e) { |
473 |
| - throw new RaiseException(context, context.getCoreExceptions().regexpError(e.getMessage(), currentNode)); |
| 438 | + options.toJoniOptions(), |
| 439 | + context.getHashing(REHASH_COMPILED_REGEXPS)); |
| 440 | + ConcurrentOperations.getOrCompute(compiledRegexps, key, x -> new AtomicInteger()).incrementAndGet(); |
474 | 441 | }
|
| 442 | + |
| 443 | + return regexp; |
475 | 444 | }
|
476 | 445 |
|
477 | 446 | }
|
0 commit comments