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

Wrong grammarFileName in generated code #3937

Closed
parrt opened this issue Oct 23, 2022 · 4 comments
Closed

Wrong grammarFileName in generated code #3937

parrt opened this issue Oct 23, 2022 · 4 comments

Comments

@parrt
Copy link
Member

parrt commented Oct 23, 2022

Somehow the grammarFileName is now messed up. We always get:

// Generated from java-escape by ANTLR 4.11.1
...
       @Override
        public String getGrammarFileName() { return "java-escape"; }

no matter what the grammar file name is. Tool code gen is messed up.

Seems to be from the templates. E.g.,

fileHeader(grammarFileName, ANTLRVersion, header) ::= <<
<header>

// Generated from <grammarFileName> by ANTLR <ANTLRVersion>
>>

LexerFileHeader(file, lexer, namedActions) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion, namedActions.header)>

file.grammarFileName isn't right. Could it be an error in the template engine or object we pass in?

static grammarFileName = "<parser.grammarFileName; format="java-escape">";  <=============
@parrt parrt added this to the 4.11.2 milestone Oct 23, 2022
@parrt
Copy link
Member Author

parrt commented Oct 23, 2022

@KvanTTT Looks like you killed java-escape in your refactoring (another reason not to resist refactoring).

6a7e651

@parrt
Copy link
Member Author

parrt commented Oct 23, 2022

Solution is maybe to remove java-escape from templates

parrt added a commit to parrt/antlr4 that referenced this issue Oct 23, 2022
…marFileName was not generated properly.

Output is now proper: // Generated from org/antlr/v4/test/runtime/java/api/Java.g4 by ANTLR 4.11.2-SNAPSHOT

Signed-off-by: Terence Parr <parrt@antlr.org>
@parrt parrt closed this as completed Oct 23, 2022
@KvanTTT
Copy link
Member

KvanTTT commented Oct 23, 2022

Is it just an error during template rendering? Does it cause any user bug on grammar?

@parrt
Copy link
Member Author

parrt commented Oct 24, 2022

getGrammarFileName() functions fail for multiple targets; returns "java-escape" not T.g4 or whatever. parsing is unaffected.

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

No branches or pull requests

2 participants