Grammar Kit "recoverWhile"

I need some help understanding how recoverWhile (from the Grammar Kit plugin) works.

In my language, function are defined like:

function namespace::name::othername() {
}


I'm trying to add recovery when you specify a wrong identifier as a name (for example, when using a reserved keyword). The relevant piece of grammar is as follows

funcname ::= id (!'(' '::' id)* { recoverWhile=funcname_recovery }
private funcname_recovery ::= !('::' | '(')
funcbody ::= '(' funcargs? ')' statement { pin=1 }
functionDecl ::= 'function' funcname funcbody { pin=1 } 


From what I understand, that means "after matching funcname, ignore everything until you match an open parenthesis". This works correctly when there is no error (and my PSI tree still looks correct), but when I add an error (like

function name::function() ...
), the funcname psi element contains all the psi elements until the end of the file.

I've also tried with

private funcname_recovery ::= !'('


...but I get the same or a similar result. I thought the recovery rule was consuming the
'('
token, so
 funcbody
cannot match it, but as I said, when there are no errors everything works (and the recovery rule is fired in this case as well). Also, the recovery rule doesn't stop when it finds other functions that has a ().

What am I doing wrong?

Please sign in to leave a comment.