W201 Repetition of an expression that can match nothingΒΆ
A repeated expression can match the empty string. A step that matches nothing would match nothing again, so the repetition ends with it, whatever its count asks for. That is seldom meant: where the expression matches nothing, the repetition stops and does not go on to what a later step could have matched.
start: (NAME? ","?)* ";"
NAME: [a-z]+
grammar.fpeg:1:8: warning[W201]: this repetition ends at the first step that matches nothing, which its expression can
Give every step something it must match, and move what is optional around the repetition.
start: (NAME ","?)* ";"
NAME: [a-z]+
The warning is given where the expression, or one alternative of it, is built of optional parts alone. A part that looks ahead or depends on flags, columns or captures may fail where the others match nothing, so an expression that needs such a part is not reported. Neither is an alternative behind one that may pass a cut or fail an error label, its own or one in a rule it calls, which can end the choice before it. Where the skip expression can fail an error label, it may do so before any token, so only the repetitions in terminals, which do not skip, are reported.