1
0
mirror of https://github.com/janet-lang/janet synced 2025-04-14 06:43:11 +00:00

Get rid of early termination rule in all finite loops.

This commit is contained in:
Calvin Rose 2025-02-03 07:36:00 -06:00
parent d30fd27575
commit 6da44bdb6a
2 changed files with 9 additions and 6 deletions

@ -342,8 +342,8 @@ tail:
while (captured < hi) {
CapState cs2 = cap_save(s);
next_text = peg_rule(s, rule_a, text);
if (!next_text || next_text == text) {
if (!next_text || captured > 0) cap_load(s, cs2);
if (!next_text || ((next_text == text) && (hi == UINT32_MAX))) {
cap_load(s, cs2);
break;
}
captured++;

@ -789,13 +789,16 @@
"abc123"
@["abc123"])
# Issue 1554
(test "issue 1554 case 1" '(any (> '1)) "abc" @["a"])
(test "issue 1554 case 2" '(any (? (> '1))) "abc" @["a"])
(test "issue 1554 case 3" '(any (> (? '1))) "abc" @["a"])
# Issue 1554 - 0-width match termination behavior
(test "issue 1554 case 1" '(any (> '1)) "abc" @[])
(test "issue 1554 case 2" '(any (? (> '1))) "abc" @[])
(test "issue 1554 case 3" '(any (> (? '1))) "abc" @[])
(test "issue 1554 case 4" '(* "a" (> '1)) "abc" @["b"])
(test "issue 1554 case 5" '(* "a" (? (> '1))) "abc" @["b"])
(test "issue 1554 case 6" '(* "a" (> (? '1))) "abc" @["b"])
(test "issue 1554 case 7" '(between 0 2 (> '1)) "abc" @["a" "a"])
(test "issue 1554 case 8" '(between 2 3 (? (> '1))) "abc" @["a" "a" "a"])
(test "issue 1554 case 9" '(between 0 0 (> (? '1))) "abc" @[])
(end-suite)