mirror of
https://github.com/janet-lang/janet
synced 2025-02-21 18:50:02 +00:00
Address #1554 - capture first 0-width match in repeating rules and
optionals. This fixes some undesirable interplay between lookaheads and looping (repeating) rules where lookaheads caused the loop to immediately terminate _and_ discard any captures. This change adds an exception if there is a 0-width match at the first iteration of the loop, in which case captures will be kept, although the loop will still be terminated (any further iteration of the loop would possibly cause an infinite loop). This allows optionals to work as expected when combined with lookahead. There is also a question of whether or not optional should be implemented as separate rule rather than as `(between 0 1 subrule)`.
This commit is contained in:
parent
1b278fc657
commit
d30fd27575
@ -343,7 +343,7 @@ tail:
|
||||
CapState cs2 = cap_save(s);
|
||||
next_text = peg_rule(s, rule_a, text);
|
||||
if (!next_text || next_text == text) {
|
||||
cap_load(s, cs2);
|
||||
if (!next_text || captured > 0) cap_load(s, cs2);
|
||||
break;
|
||||
}
|
||||
captured++;
|
||||
|
@ -789,5 +789,13 @@
|
||||
"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"])
|
||||
(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"])
|
||||
|
||||
(end-suite)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user