kotlin-spec icon indicating copy to clipboard operation
kotlin-spec copied to clipboard

Purpose of modes stack size checking in lexer

Open KvanTTT opened this issue 4 years ago • 6 comments

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

KvanTTT avatar Sep 20 '19 17:09 KvanTTT

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.

petukhovv avatar Oct 18 '19 09:10 petukhovv

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.

wmeints avatar Apr 28 '20 09:04 wmeints

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.

mlynch avatar Jul 03 '22 21:07 mlynch

All targets have similar fields _modeStack and similar methods (isEmpty, popMode).

KvanTTT avatar Jul 03 '22 22:07 KvanTTT

mode_stack, pop_mode

KvanTTT avatar Jul 04 '22 07:07 KvanTTT

@KvanTTT thank you!!

mlynch avatar Jul 04 '22 14:07 mlynch