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

Adjust ANTLR4 to generate a new interface that provides stubbed implementations for rules we don't care about #36

Open
incident-recipient opened this issue Aug 12, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@incident-recipient
Copy link
Collaborator

For Gherkin-style tests ANTLR4 gives us two choices for the listener: an abstract class with empty implementations for everything or an interface.

The problem with the abstract class is it is too easy for the grammar to change and other clients will not realize they need to provide an implementation. This can lead to false positives.

The interface requires implementing a lot of methods that have no value (such as the exit methods).

It would be great to have a third option that provided an empty implementation for all exit methods as well as any rules that follow some convention (such as a '_' character at the end of the rule name. In this manner the user will only need to provide implementations for the enter methods of consequence and changes will allow other clients to see they need to add new functionality.

@incident-recipient
Copy link
Collaborator Author

I think another useful way to do this would be to have ANTLRs tool generate another java interface that has a default implementation that does nothing for all exit methods and ParseTreeListener methods. This would only force the user to implement the enter methods.

@incident-recipient
Copy link
Collaborator Author

So I made a pull request and issue for the antlr team at antlr/antlr4#3986

However there seems to be mixed feelings.

I have adjusted this framework to support generated visitors which can act as a work around, but I'll keep this issue open until Parr has made a decision on the pull request.

@incident-recipient incident-recipient added the enhancement New feature or request label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant