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

feat(#3744): Human-Readable Message for Prohibited Comment #3802

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

volodya-lombrozo
Copy link
Member

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.

@github-actions github-actions bot added the core label Jan 10, 2025
@volodya-lombrozo volodya-lombrozo marked this pull request as draft January 10, 2025 13:26
@volodya-lombrozo volodya-lombrozo marked this pull request as ready for review January 10, 2025 14:02
@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Could you have a look, please?

@maxonfjvipon
Copy link
Member

@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?

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Jan 10, 2025

@maxonfjvipon I share your concern. Actually, using this approach was a last resort. I didn’t want to use it initially.
As for examples, yes, there are plenty of them:

  1. The Definitive ANTLR 4 Reference 2nd Edition: Section 9.4 Error Alternatives
  2. The real example is the Groovy lang. They use this technique a lot (at least in Lexer). For example for UNEXPECTED_CHAR
  3. Also some sites mention this approach as well

@yegor256
Copy link
Member

@volodya-lombrozo maybe we should use a two-phases compilation pipeline for the .g4 file. First, we take the original .g4 file and inject such additional constructs into it, producing new (very large) .g4 file. Then, we let ANTLR compile this large file. WDYT?

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

Successfully merging this pull request may close these issues.

comment-in-method.yaml:24-26: The error message doesn't...
3 participants