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

Invalid C# code being generated #3000

Closed
Ozzah opened this issue Dec 11, 2020 · 4 comments · Fixed by #3019
Closed

Invalid C# code being generated #3000

Ozzah opened this issue Dec 11, 2020 · 4 comments · Fixed by #3019
Labels
Milestone

Comments

@Ozzah
Copy link

Ozzah commented Dec 11, 2020

I'm trying to use ANTLR4.9 to build the ANTLR4 lexer/parser grammar from the antlr/grammars-v4 repo. ANTLR does generate the C# files without warnings or errors, however there is an invalid

const int
;

in the generated LexBasic.cs file.

In this example, I'm using antlr-4.9-complete.jar (SHA-1: 05f8b86f121c4239939b95b0eed0411dec3917e7) with the command

java -jar antlr-4.9-complete.jar -Dlanguage=CSharp -o Generated -visitor LexBasic.g4

to build just this one file. I have also tried building the whole ANTLR4 grammar set together. I've used the dotnet-based compiler using

<PropertyGroup>
  <Antlr4UseCSharpGenerator>True</Antlr4UseCSharpGenerator>
</PropertyGroup>

and I've also tried building ANTLR4.9.1 from source. Everything results in the same invalid LexBasic.cs file.

Looking at the LexBasic.g4 file, I can't see anything immediately obvious as out of place that could cause this.

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Dec 11, 2020 via email

@KvanTTT
Copy link
Member

KvanTTT commented Dec 11, 2020

It's the bug because ANTLR should throw clear error messages instead of invalid code generating.

@Ozzah
Copy link
Author

Ozzah commented Dec 11, 2020

@ericvergnaud ok, well if I go

java -jar antlr-4.9-complete.jar -Dlanguage=CSharp -o Generated -visitor LexBasic.g4 ANTLRv4Lexer.g4 ANTLRv4Parser.g4

then I get the same syntax error in LexBasic.cs, and there is no combination with Sam Harwell's tool.

@KvanTTT
Copy link
Member

KvanTTT commented Dec 29, 2020

Consider the following grammar:

lexer grammar Lexer;

ANTLR produces the following error:

Lexer.g4::: grammar Lexer has no rules

But If we are trying to generate lexer for the following code:

lexer grammar Lexer;
fragment FRAGMENT: 'FRAGMENT';

ANTLR does not show any error and produces invalid code at least for C# runtime.

Obviously, it's a bug.

KvanTTT added a commit to KvanTTT/antlr4 that referenced this issue Dec 29, 2020
@parrt parrt added this to the 4.9.1 milestone Jan 2, 2021
@parrt parrt added the code-gen label Jan 2, 2021
KvanTTT added a commit to KvanTTT/antlr4 that referenced this issue Jun 28, 2021
…end TestToolSyntaxErrors testA, fix antlr#3000", fix antlr#3147

This reverts commit 67f6089.
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 a pull request may close this issue.

4 participants