-
Notifications
You must be signed in to change notification settings - Fork 146
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
feat(#3744): Human-Readable Message for Prohibited Comment #3802
feat(#3744): Human-Readable Message for Prohibited Comment #3802
Conversation
@maxonfjvipon Could you have a look, please? |
@volodya-lombrozo it's a very interesting idea, but I'm not sure if it's "right" to put wrong scenarios to grammar to detect errors. It seems that grammar is supposed to contain only "possible" scenarios. Did you see anywhere else such approach when obviously incorrect scenarios are put into grammar to detect syntax errors? |
@maxonfjvipon I share your concern. Actually, using this approach was a last resort. I didn’t want to use it initially.
|
@volodya-lombrozo maybe we should use a two-phases compilation pipeline for the |
@yegor256 I believe this solution would be overly complicated, to be honest. Originally, the problem with error handling was related to the EO ANTLR grammar. The grammar is created in such a way that if one of the comments is prohibited (by the grammar), then almost the entire AST becomes incorrect (see the picture below). The perfect solution would be to rework the grammar in a way to avoid such situations. But it might require more dramatic changes that I would like to avoid. |
@volodya-lombrozo could you please describe how would you change the grammar so it would be more convenient for catching error? Maybe I could figure it out |
@volodya-lombrozo I do like this PR, but I don't understand how many of such PRs we will have in the future, with similar grammar tricks. If it's only one, that's fine. However, if there will be others, maybe we should think about something less intrusive -- something that doesn't pollute our |
@maxonfjvipon I can't say for now, it requires some additional deep investigation. ANTLR can't recognise either object
: master
| slave
; All the available recovery strategies don't help either. |
@yegor256 I can't agree more here. However, I can't say for now how much of such PR's we will have in the future. I need to move forward and try to solve similar issues: If they will require same "tricks", it will mean that we need to solve this problem somehow else. And we will be able to discuss it in the next PR. |
@volodya-lombrozo maybe we should try to implement our own "Error Strategy": https://www.antlr.org/api/Java/org/antlr/v4/runtime/ANTLRErrorStrategy.html Also, check this: https://stackoverflow.com/questions/26675254/antlr-error-strategy-to-skip-tokens-until-rule-matches-again |
We solved this issue by using different approach. See #3818 |
In this PR I've added supportive grammar rule that is used to catch prohibited comments and report them to a user:
prohibitedComment : comment ;
Closes: #3744.