From 7474a2b6f45a36513657cdd61be24338124067ed Mon Sep 17 00:00:00 2001 From: Ju Date: Mon, 15 Feb 2021 18:12:38 +1300 Subject: [PATCH] Repeated expr should consume some input, otherwise AdvanceError. (#11) --- peppapeg.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/peppapeg.c b/peppapeg.c index b4564374..5b5a1f53 100644 --- a/peppapeg.c +++ b/peppapeg.c @@ -732,6 +732,11 @@ P4_MatchRepeat(P4_Source* s, P4_Expression* e) { if (!NO_ERROR(s)) goto finalize; + if (P4_GetPosition(s) == before_implicit) { + P4_RaiseError(s, P4_AdvanceError, "Repeated expression consumes no input"); + goto finalize; + } + repeated++; P4_AdoptToken(head, tail, tok); @@ -739,6 +744,7 @@ P4_MatchRepeat(P4_Source* s, P4_Expression* e) { P4_RescueError(s); break; } + } // there should be no error when repetition is successful.