Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purpose of modes stack size checking in lexer #37

Open
KvanTTT opened this issue Sep 20, 2019 · 6 comments
Open

Purpose of modes stack size checking in lexer #37

KvanTTT opened this issue Sep 20, 2019 · 6 comments

Comments

@KvanTTT
Copy link
Contributor

KvanTTT commented Sep 20, 2019

Could you explain the purpose of modes stack size checking before popMode()?

RCURL: '}' { if (!_modeStack.isEmpty()) { popMode(); } };

Is this a workaround for more reliable error handling if the first open LCURL is missed?

Is this related to antlr/antlr4#2006

@petukhovv
Copy link
Contributor

petukhovv commented Oct 18, 2019

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.

@wmeints
Copy link

wmeints commented Apr 28, 2020

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.

@mlynch
Copy link

mlynch commented Jul 3, 2022

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.

@KvanTTT
Copy link
Contributor Author

KvanTTT commented Jul 3, 2022

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

@KvanTTT
Copy link
Contributor Author

KvanTTT commented Jul 4, 2022

mode_stack, pop_mode

@mlynch
Copy link

mlynch commented Jul 4, 2022

@KvanTTT thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants