kotlin-spec
kotlin-spec copied to clipboard
Purpose of modes stack size checking in lexer
Could you explain the purpose of modes stack size checking before popMode()
? https://github.com/Kotlin/kotlin-spec/blob/091d4216cf2c015143e49978d1c43a204e26d967/grammar/src/main/antlr/KotlinLexer.g4#L44
Is this a workaround for more reliable error handling if the first open LCURL
is missed?
Is this related to https://github.com/antlr/antlr4/issues/2006
Yes, absolutely right. It's related to antlr/antlr4#2006.
Without this check, we encountered an EmptyStackException
in the absence of an opening }
and couldn't write the corresponding grammar tests.
Unfortunately, with this check, the grammar is language-dependent, so we hope that ANTLR will not fall hard in the future in this case, and that we can remove the empty stack check.
I ran into this exact problem. Because it's language specific now, I can't use the lexer without modifying it, so it matches the generated C# code. I've worked around it, but I do hope they fix the problem in the future.
Does anyone have an example of what changes they made to this line for their specific programming language? I'm using antlr_rust
and a bit unsure how this line should be modified for this library.
All targets have similar fields _modeStack
and similar methods (isEmpty
, popMode
).
@KvanTTT thank you!!