antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.26k stars 3.29k forks source link

Java packages directory structure is not adding automatically #455

Closed dzavodnikov closed 10 years ago

dzavodnikov commented 10 years ago

When I want to generate lexer/parser into package a.b.c I am using following code:

$ java -cp antlr-4.1-complete.jar org.antlr.v4.Tool -o src -package a.b.c A.g4

and get generated parser and lexer into src directory:

and etc. But I expect:

To get it I should duplicate structure informatio into -o option:

$ java -cp antlr-4.1-complete.jar org.antlr.v4.Tool -o src/a/b/c -package a.b.c A.g4

But It is not so useful as It can be.

sharwell commented 10 years ago

Please include a description of the inputs you used, the current behavior, and the expected behavior.

dzavodnikov commented 10 years ago

It is not a bug, it is improvement.

sharwell commented 10 years ago

Unfortunately, we won't be able to make this change for ANTLR 4 as it would break any existing build tools that are in place. I recommend that you use the Maven plugin or an Ant task to generate your grammars during your build process, as each of those tools automatically accounts for the -package option and the directory structure required for Java source files.

parrt commented 10 years ago

The other issue is that that only makes sense for Java; For C++ or another language, all files might go in a single directory regardless of their package.

ctubbsii commented 9 months ago

This situation is worse with the antlr4-maven-plugin, because it automatically adds the outputDirectory to the build class path (since it contains generated sources), but that directory can't be properly viewed as a source directory in an IDE, since the classes don't follow Java's rules about how to organize source files into package folders.

I think it's a mistake to not fix this. Just Google for this issue, and you find users complaining all over the internet, confused and struggling by this behavior.