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

Not all context accessor methods are generated when an alternative rule label is used for multiple alternatives #433

Closed
ronangel opened this issue Jan 20, 2014 · 2 comments · Fixed by #501

Comments

@ronangel
Copy link

When I reuse the same alternative rule label for multiple alternatives, ANTLR only generates accessor methods for the last alternative with the given label.

For example, with the following rule:

expression : '(' expression ')'                                 # ParenthesizedExpression
           | expression Caret<assoc=right> expression           # BinaryNumericExpression
           | expression (Times|DividedBy|ModuloDiv) expression  # BinaryNumericExpression
           | expression (Plus|Minus) expression                 # BinaryNumericExpression
           ;

The generated BinaryNumericExpressionContext class will only have Plus() and Minus() accessors, but not Caret(), Times(), DividedBy(), or ModuloDiv().

@ghost ghost assigned sharwell Jan 29, 2014
@parrt
Copy link
Member

parrt commented Jan 29, 2014

Interesting. I wonder if it should have all accessors or should it be an error?

@sharwell
Copy link
Member

As mentioned in response to my deleted answer to this StackOverflow question, the ANTLR 4 documentation clearly states that multiple outer alternatives in the same rule can share a context class. I was not aware of this when I wrote the analysis in getDeclsForAllElements as part of this optimization, hence the bug.

sharwell added a commit to sharwell/antlr4 that referenced this issue Mar 20, 2014
sharwell added a commit to sharwell/antlr4 that referenced this issue Mar 20, 2014
@sharwell sharwell mentioned this issue Mar 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants