Skip to content

Commit 622bf5d

Browse files
committed
[GR-60873] TRegex: fix corner cases in NFATraversalRegexASTVisitor.
PullRequest: graal/19742
2 parents 3bb5455 + 100ca82 commit 622bf5d

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

regex/src/com.oracle.truffle.regex.test/src/com/oracle/truffle/regex/tregex/test/JsTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ public void generatedTests() {
542542
expectSyntaxError("[--a]", "v", "", getTRegexEncoding(), "empty", 0, ErrorCode.InvalidCharacterClass);
543543
test("(?:^\\1|$){10,11}bc", "", "aaaaaabc", 0, false);
544544
test("a(?:|[0-9]+?a|[0-9a]){11,13}?[ab]", "", "a372a466a109585878b", 0, true, 0, 5);
545+
test("(?<=ab(?:c|$){8,8})", "", "abccccc", 0, true, 7, 7);
546+
test("(?:^a|$){1,72}a", "", "aaaaaaaa", 0, true, 0, 2);
545547

546548
/* GENERATED CODE END - KEEP THIS MARKER FOR AUTOMATIC UPDATES */
547549
}

regex/src/com.oracle.truffle.regex.test/src/com/oracle/truffle/regex/tregex/test/PythonTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ public void generatedTests() {
846846
test("[\\W]", "i", "\u0399", 0, false);
847847
test("(\\Aa)+?|(?<=ab\\1)", "", "empty", 0, false);
848848
test("^([c-l])\\1|(\\A\\1)+", "", "kk", 0, true, 0, 2, 0, 1, -1, -1, 1);
849+
test("(?:\\Z|\\Aa){1,44}a", "", "aaaa", 0, true, 0, 2, -1);
849850

850851
/* GENERATED CODE END - KEEP THIS MARKER FOR AUTOMATIC UPDATES */
851852
}

regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/parser/ast/visitors/NFATraversalRegexASTVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ private boolean advanceTerm(Term term) {
573573
if (!getFlavor().emptyChecksOnMandatoryLoopIterations() &&
574574
curGroup.isMandatoryQuantifier() &&
575575
!curGroup.isExpandedQuantifier() &&
576-
(!ast.getOptions().isBooleanMatch() || ast.getProperties().hasBackReferences() || caretsOnPath())) {
576+
(!ast.getOptions().isBooleanMatch() || ast.getProperties().hasBackReferences() || caretsOnPath() || isReverse() && dollarsOnPath())) {
577577
// the existence of a mandatory copy of the quantifier loop implies a minimum
578578
// greater than zero
579579
assert !curGroup.isMandatoryQuantifier() || quantifier.getMin() > 0;
@@ -1076,7 +1076,7 @@ private void calculateTransitionGuards() {
10761076
Quantifier quantifier = quantifierGroup.getQuantifier();
10771077
if (!quantifierGroup.isExpandedQuantifier()) {
10781078
if (quantifierGroup.isDead()) {
1079-
if (quantifier.getMin() > 0) {
1079+
if (quantifier.getMin() > 0 && !quantifierGroup.isOptionalQuantifier()) {
10801080
setShouldRetreat();
10811081
}
10821082
} else if (quantifier.hasIndex()) {

0 commit comments

Comments
 (0)