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

[Gradle 4.0.1][AntlrTask]Failed to generate grammar source when g4 files is placed at packages #2565

Closed
daniellansun opened this issue Jul 21, 2017 · 11 comments

Comments

@daniellansun
Copy link

daniellansun commented Jul 21, 2017

When g4 files is placed at packages(e.g. package parrot whose path is src\main\antlr\parrot), generating grammar source fails because of tokens file not found.( The tokens file is generated to build\generated-src\antlr\main\parrot, but antlr4 will try to find the tokens file at build\generated-src\antlr\main\ )

D:\_APPS\git_apps\test-antlr-task>gradlew generateGrammarSource

> Task :generateGrammarSource
error(160): parrot\GroovyParser.g4:37:17: cannot find tokens file 'D:\_APPS\git_apps\test-antlr-task\build\generated-src\antlr\main\GroovyLexer.tokens'

Expected Behavior

Generate grammar source successfully.

Current Behavior

Fails to generate grammar source.

Context

Fails to generate grammar source.

Steps to Reproduce (for bugs)

  1. check out https://github.com/danielsun1106/test-antlr-task/releases/tag/0.0.2
  2. gradlew generateGrammarSource

Your Environment

Gradle 4.0.1

@daniellansun daniellansun changed the title [Gradle 4.0.1][AntlrTask]Failed to generate grammar source when package name is specified [Gradle 4.0.1][AntlrTask]Failed to generate grammar source when g4 file is placed at packages Jul 21, 2017
@daniellansun daniellansun changed the title [Gradle 4.0.1][AntlrTask]Failed to generate grammar source when g4 file is placed at packages [Gradle 4.0.1][AntlrTask]Failed to generate grammar source when g4 files is placed at packages Jul 21, 2017
@big-guy
Copy link
Member

big-guy commented Jul 28, 2017

@breskeby is this something that's configurable or look familiar?

@bot-plugin-portal
Copy link

bot-plugin-portal commented Jul 28, 2017

I think this is a known limitation in the antlr4 support in gradle. @danielsun1106 can you try to add the package declaration to the grammar header via

@header {
    package parrot;
}

and check if that workaround is working for you?

@breskeby
Copy link
Contributor

👆🏽 that was me

@daniellansun
Copy link
Author

@gradlewaregitbot I gave it a try, but still failed.

@svanteschubert
Copy link

Unfortunately, I only got a workaround for Windows. There it works if you explicitly address the lexer and the parser in the command line arguments:

generateGrammarSource {
arguments += ["-no-listener", "-package", "parrot", "parrot/GroovyLexer.g4", "parrot/GroovyParser.g4"]
}

The generated sources will be created beyond
test-antlr-task-0.0.2\build\generated-src\antlr\main
without package name, BUT if you would compile them, they would be placed right where they belong under
build\classes\java\main\parrot
Therefore it is possible to add for instance an own Listener with the package.

It works with Java classes for the repo I am working on:
https://github.com/svanteschubert/gumtree/tree/develop/gen.antlr4-xml

But it fails under Linux (tested with Ubuntu with gradle 2, 3 and 4.01 and 4.02).

@jest
Copy link

jest commented Aug 30, 2018

As antlr/antlr4#638 is closed, would changes according to antlr/antlr4#2065 (comment) solve this issue?

@daniellansun
Copy link
Author

Here is the workaround used by apache/groovy

https://github.com/apache/groovy/blob/master/subprojects/parser-antlr4/build.gradle#L34

@jest
Copy link

jest commented Sep 5, 2018

Thanks, works; with ANTLR 4.7.1 -Xexact-output-dir option has to be specified:

arguments += [ "-package", PARSER_PACKAGE_NAME, "-Xexact-output-dir" ]

@paflopes
Copy link

paflopes commented Sep 9, 2018

Solution mentioned by @danielsun1106 works great! Thanks!

@stale
Copy link

stale bot commented Jul 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

@stale stale bot added the stale label Jul 13, 2020
@stale
Copy link

stale bot commented Aug 3, 2020

This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.

@stale stale bot closed this as completed Aug 3, 2020
@wolfs wolfs closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2022
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

9 participants