I have an identifierAndArguments non-terminal that can appear zero or more times at the end of a prefixExpression non-terminal. However, it's being matched too early as an optional middle of a different production which doesn't end up being correct, so the parsing halts. How can I add handling so that the parser recovers from the incorrect match, moves up a level, and reuses the identifierAndArguments in the correct way?
My Lua grammar includes these five productions (reproduced here in simplified form):
prefixExpression.Production = variableOrExpression + identifierAndArguments.ZeroOrMore(); variableOrExpression.Production = @identifier + variableSuffix.ZeroOrMore(); variableSuffix.Production = identifierAndArguments.ZeroOrMore() + (@openBracket + expression + @closeBracket | @dotOperator + @identifier); identifierAndArguments.Production = (@colon + @identifier).Optional() + arguments; arguments.Production = literalString
The code snippet foo"hello" is causing the Language Designer's Parser Debugger to silently fail when it encounters them. The snippet should come back as a prefixExpression.
First foo matches as an @identifier token in the variableOrExpression production. Then it tries to find zero or more variableSuffix's. "hello" is a literalString, which fulfills the condition of zero or more identifierAndArguments as the start of a variableSuffix. However, there's no expression in brackets or dot-identifier afterwards, so everything stops.
What should be happening is that "hello" is an identifierAndArguments that goes at the end of the prefixExpression, not as a variableSuffix in the variableOrExpression match.
I suspect I need some sort of callback to help the parser discard the failed variableSuffix match, terminate the variableOrExpression match, and try again at the prefixExpression level. How do I do that?