Parser error recovery grammar kit

Hi there!

I am trying to leverage Grammar kit to build up a parser for language plugin. However I have some troubles understanding recoveryWhile along with pin. There are some post dedivated to this point but they have been left unanswered.

To my understanding, these modifiers for rules allow to built an AST without Dummy blocks inserting error nodes where possible.

So pin just makes up a node once pinned element has been reached, while recoveryWhile builds a node if some extra was added, taking all tokens until some condition is met.  And this is useful when e.g. one have list of imports and declarations:

 

```
{
tokens=[
space='regexp:\s+'
number='regexp:\d+(\.\d*)?'
id='regexp:\p{Alpha}\w*'
]
}

Root ::= Module

Module ::= ImportList TopDeclList

//private generic_recover ::= !';'

private ImportList ::= ImportClause*
private recover_import ::= !(';'|Import|Declaration)
private ImportClause ::= Import ';' {pin=1 recoverWhile=recover_import}
Import ::= 'import' id {pin =1}
private TopDeclList ::= TopDecl*
private TopDecl ::= !<<eof>> Declaration ';'{pin=1 recoverWhile=recover_delc}
private Declaration ::= ValueDecl | TypeDecl
private recover_delc ::= !(';'|Declaration)

ValueDecl ::= id '=' Expression {pin=2}
TypeDecl ::= 'type' id '=' id {pin=2}

Expression ::= id | number
```
And it works as expected in sence that it reports about all malformed statemets. But if I remove `!<<eof>>` modifier it got stuck at the first malformed declaration.
 
furthermore in current configuration it breaks if something extra added to import statement as well if pin is not reached
while still works if something was added to declarations:
So the question generally consists of three parts:
  1. What `!<<eof>>` modifier actually does so the parser got stuck if the modifier is absent and how to handle above situation.
  2. Why can't I just specify recoverWhile with ';' instead of `!(';'|Import|Declaration)`
  3. Whether my intuition about what recoverWhile and pin do is right.

0

Please sign in to leave a comment.