Grammar-Kit
Grammar-Kit copied to clipboard
wrong error ranges
GK reports wrong error ranges in the presence of pins. Sample grammar:
{
tokens=[
RECORD = 'record'
CURLY_LEFT = '{'
CURLY_RIGHT = '}'
space='regexp:\s+'
id = 'regexp:(\p{Alpha}\p{Alnum}*)'
]
}
root ::= recordTypeDef*
//recordTypeDef ::= 'record' id '{' (fieldDecl* '}' { pin=1 }
recordTypeDef ::= 'record' id '{' fieldDecl* '}' { pin=1 }
fieldDecl ::= id ':' id { pin=2 }
Run live preview, type record R { foo: 33bar }. Inspect PSI, see PsiErrorElement after foo:, specifically it's text range: (15, 15).
Remove pin on recordTypeDef, range becomes (16, 18), as expected.
As a result IDEA highlights space before bad token instead of the bad token itself.
GK suffers from the same problem: uncomment first recordTypeDef which has an unclosed parenthesis, see how it gets reported.
ErrorElement cannot be some TokenElement at the same time. So the error is placed before the next token allowing parser to proceed normally if there's no active recoverWhile . In your example with GK the next attribute group is parsed correctly because "{" is not consumed by error element.
I'm trying to reproduce the LivePreview example and it seems to work as expected with/without pin ("33" is highlighted). Check the version of GeneratedParserUtilBase you use and/or try LiverPreview from the latest GK.
GeneratedParserUtilBase is from 2016.2
Don't know if this helps, but here's a screenshot of what I see:

Without pin:
