Error recovery with pin and recoverWhile
Hi,
What I understood is pin and recoveryWhile is used for not stopping the parser to create AST when it found the first error. So we can get all the compilation error in the beginning and NOT one by one at a time (Can you please verify if I am correct ?)
With trial and error what I got is with pin the parser would create the parse tree if it found a bad character outside the pinned element.
Please refer to the below image. Here without the pin in line #11, parser would not create the ASTWrapperPsiElement(PAREN_EXPR) sub tree(highlighted in the Psi viewer). With pin it creates the PAREN_EXPR node and put leaf node inside it.
I put the recoverWhile=!(';'), so by definition, the parser will skip all the tokens until it gets a ';'. That is what it is doing and we are getting two errors. The second error is at the ';' in line #1 in live preview and for line #2 no PAREN_EXPR tree is getting created. So i assume the parser is stopping at ';' in line #1 and not even interpreting the line #2 with the above bnf grammar.
Can you please suggest how can I let the parser go to the next line and create the similar parse tree it created for the first line ?

Thanks,
Subhojit
Please sign in to leave a comment.
Could you please provide the BNF as gist/file somewhere? Thanks.
The BNF file:
{
tokens = [
string="regexp:('([^'\\]|\\.)*'|\"([^\"\\]|\\\"|\\\'|\\)*\")"
id="regexp:\w+"
]
}
testFile ::= item_*
private item_ ::= (paren_expr)
paren_expr ::= id '=' '(' expr ')' ';' {pin=2 recoverWhile=expr_recover}
expr ::= string
private expr_recover ::= !(';')
Let me know if you need anything else.
Thanks
AFAIU this more likely what you want:
{
tokens = [
string="regexp:('([^'\\]|\\.)*'|\"([^\"\\]|\\\"|\\\'|\\)*\")"
eq='='
semicolon=';'
open='('
close=')'
id="regexp:\w+"
]
}
testFile ::= item_* {recoverWhile=expr_recover}
private item_ ::= paren_expr
paren_expr ::= id '=' '(' expr ')' ';' {pin=2 }
expr ::= string
private expr_recover ::= !(id)