I'm currently struggling to implement error recovery in a grammar for a language based on S-expressions. A subset of the grammar is below as an example:
tokens = [
LPAREN = '('
RPAREN = ')'
IDENTIFIER = 'regexp:\.?[a-zA-Z][a-zA-Z\d\._]*'
SPACE = 'regexp:[\s\n]'
Statement ::= BlockDeclStatement |
BlockDeclStatement ::= '(' 'block' Identifier Statement* ')'
TypeDeclStatement ::= '(' 'type' Identifier ')'
TypeAttributeDeclStatement ::= '(' 'typeattribute' Identifier ')'
Identifier ::= IDENTIFIER
My problem comes from getting an invalid statement within a block like so:
^ expected one of block, type, typeattribute, found bar
When "bar" is encountered I'd like to skip input until the matching closing parenthesis is found and then resume with the "Statement*" rule in BlockDeclStatement. I'm not sure what the best way to go about this is. I'd assume the best place to start would be recoverWhile on "Statement" but I'm not quite sure where to proceed from there.
Any input would be appreciated.