Skip to content

Commit

Permalink
Repeated expr should consume some input, otherwise AdvanceError. (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
soasme committed Feb 15, 2021
1 parent 5365b93 commit 7474a2b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions peppapeg.c
Expand Up @@ -732,13 +732,19 @@ 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);

if (max != -1 && repeated == max) { // enough attempts
P4_RescueError(s);
break;
}

}

// there should be no error when repetition is successful.
Expand Down

0 comments on commit 7474a2b

Please sign in to comment.