diff --git a/src/core/peg.c b/src/core/peg.c index b3445521..93d43d0e 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -286,7 +286,7 @@ tail: const uint8_t *next_text; CapState cs = cap_save(s); down1(s); - while (text < s->text_end) { + while (text <= s->text_end) { CapState cs2 = cap_save(s); next_text = peg_rule(s, rule_a, text); if (next_text) { @@ -296,7 +296,7 @@ tail: text++; } up1(s); - if (text >= s->text_end) { + if (text > s->text_end) { cap_load(s, cs); return NULL; } diff --git a/test/suite0003.janet b/test/suite0003.janet index 2f6c2995..02e15913 100644 --- a/test/suite0003.janet +++ b/test/suite0003.janet @@ -473,4 +473,12 @@ (check-deep '(* (int 2) -1) "123" nil) +# to/thru bug +(check-deep '(to -1) "aaaa" @[]) +(check-deep '(thru -1) "aaaa" @[]) +(check-deep ''(to -1) "aaaa" @["aaaa"]) +(check-deep ''(thru -1) "aaaa" @["aaaa"]) +(check-deep '(to "b") "aaaa" nil) +(check-deep '(thru "b") "aaaa" nil) + (end-suite)