-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Wrong generated code for arguments with default value in Python target #4443
Comments
In the above example, the generated Java code does not compile. Java 8 doesn't not support type inference required for |
@ericvergnaud I know that Java won't compile. The only reason I've pasted the Java output to show the way the Java runtime is generated compared to the Python version. The bug report is about to show that the Python code is wrong. |
Sorry, but what is wrong is the grammar i.e. |
@ericvergnaud I still think that there is a misunderstanding here. I want ANTLR to copy-paste my argument with the initialization as is. I don't expect to interpret it or so. And this is the expected behaviour according to the documentation:
Since Python has a no-type notation and since initializers are supported, I cannot see why I've checked another targets (Java and CPP) and they do exactly what is written. (For those targets, the content of the argument was adapted ofc. to match the expectations of the specific target language.) One more note: the generated Python code of the grammar above is syntactically correct, it runs but behaves differently as the other targets. |
An initializer and a default parameter value are 2 different things. |
@ericvergnaud Okay, I see the reason of the misunderstanding eventually! My initial sloppiness with the Java example made you think that I wanted to have multi-target support. But I didn't even think of such thing! I simply wanted to have an argument with a default value to be generated correctly into my Python language parser. I only intended to use Python runtime. I expected that this argument code will be copied just as is into the generated Python parser to the appropriate position. I saw that it was the intention of ANTLR, but it made some mistakes during the parser generation. (I put some notes into the generated Python language code snippet above.) Initially, I used the same grammar to generate a parser for the Java runtime to emphasise the differences how the various targets handles the same argument. But I see now that it was misleading, hence I've updated the original report to be more precise. |
For this grammar - which is written to produce a Python parser:
ANTLR 4.13.1 generates the following Python code:
While this equivalent construct written for Java:
... results the following:
I think, that Python target should have something like this:
The text was updated successfully, but these errors were encountered: