|
1 | 1 | package org.perlonjava.regex;
|
2 | 2 |
|
3 | 3 | import org.perlonjava.runtime.PerlCompilerException;
|
| 4 | +import org.perlonjava.runtime.PerlJavaUnimplementedException; |
4 | 5 |
|
5 | 6 | import java.util.regex.Matcher;
|
6 | 7 | import java.util.regex.Pattern;
|
@@ -604,6 +605,26 @@ static void regexErrorSimple(String s, String errMsg) {
|
604 | 605 | throw new PerlCompilerException(errMsg + " in regex m/" + s + "/");
|
605 | 606 | }
|
606 | 607 |
|
| 608 | + /** |
| 609 | + * Throws PerlJavaUnimplementedException with proper error formatting including marker and context. |
| 610 | + * Used for regex features that are valid Perl but not yet implemented in PerlOnJava. |
| 611 | + */ |
| 612 | + static void regexUnimplemented(String s, int offset, String errMsg) { |
| 613 | + if (offset > s.length()) { |
| 614 | + offset = s.length(); |
| 615 | + } |
| 616 | + |
| 617 | + // "Error message in regex; marked by <-- HERE in m/regex <-- HERE remaining/" |
| 618 | + String before = s.substring(0, offset); |
| 619 | + String after = s.substring(offset); |
| 620 | + |
| 621 | + // When marker is at the end, no space before <-- HERE |
| 622 | + String marker = after.isEmpty() ? " <-- HERE" : " <-- HERE "; |
| 623 | + |
| 624 | + throw new PerlJavaUnimplementedException(errMsg + " in regex; marked by <-- HERE in m/" + |
| 625 | + before + marker + after + "/"); |
| 626 | + } |
| 627 | + |
607 | 628 | /**
|
608 | 629 | * Calculates the maximum length a pattern can match.
|
609 | 630 | * Returns -1 if the pattern can match unlimited length.
|
@@ -783,21 +804,21 @@ private static int handleConditionalPattern(String s, int offset, int length, St
|
783 | 804 | // Check for specific invalid patterns
|
784 | 805 | if (condition.equals("??{}") || condition.equals("?[")) {
|
785 | 806 | // Marker should be after the first ?
|
786 |
| - regexError(s, condStart + 1, "Unknown switch condition (?(...))"); |
| 807 | + regexUnimplemented(s, condStart + 1, "Unknown switch condition (?(...))"); |
787 | 808 | }
|
788 | 809 |
|
789 | 810 | if (condition.startsWith("?")) {
|
790 | 811 | // Marker should be after the first ?
|
791 |
| - regexError(s, condStart + 1, "Unknown switch condition (?(...))"); |
| 812 | + regexUnimplemented(s, condStart + 1, "Unknown switch condition (?(...))"); |
792 | 813 | }
|
793 | 814 |
|
794 | 815 | // Check for non-numeric conditions that aren't valid
|
795 | 816 | if (!condition.matches("\\d+") && !condition.matches("<[^>]+>") && !condition.matches("'[^']+'")) {
|
796 | 817 | // For single character conditions like "x", marker should be after the character
|
797 | 818 | if (condition.length() == 1) {
|
798 |
| - regexError(s, condStart + 1, "Unknown switch condition (?(...))"); |
| 819 | + regexUnimplemented(s, condStart + 1, "Unknown switch condition (?(...))"); |
799 | 820 | } else {
|
800 |
| - regexError(s, condStart, "Unknown switch condition (?(...))"); |
| 821 | + regexUnimplemented(s, condStart, "Unknown switch condition (?(...))"); |
801 | 822 | }
|
802 | 823 | }
|
803 | 824 |
|
|
0 commit comments