-
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
Compiling seperate lexer and parser in subdirectory fails #638
Comments
Hi. It could go either way. .tokens could be from some totally different grammar, area of the disk. Different runs of the tool could be used to generate stuff too which would not know where another had generated them. |
Hi, I agree that there's no way to necessarily know where to search. I'd me more than happy to implement this and submit a pull request if you think it could be useful. |
I recommend your initial post to include a concrete proposal describing the exact desired behavior according to the command line. Make sure to address the following:
You can then reopen the issue for consideration. |
I've updated my initial post with some more details :) |
I'd like to increase priority for this problem, so that it finally gets solved. I'm also hit by it and I wonder why this is still open given that a simple
call fails already (error: error(160): TParser.g4:4:14: cannot find tokens file ./TLexer.tokens). It also fails when an output path is specified. To me it looks fundamentally broken! A working search strategy could be this:
Sounds simple, right? But this only works if ANTLR would stop creating weird paths (e.g. by automatically combining output and grammar subpaths). Make the output path imperative. It's the ultimate target where to look. If a package-like folder structure is required one can easily construct the correct output path before invoking ANTLR. |
what about |
Well, yes, it would probably help in this particular case, but if you have your generated files spread over various subfolders in the output folder then a single lib path doesn't improve the situation. Also, wouldn't it be a misuse of the lib setting? I consider that as a fall back for everything that doesn't belong directly to the current grammar (e.g. shared grammars). After having looked at the way the paths are constructed I feel the need to make this simpler. Automatic subfolder structure creation is so suprising and makes management difficult. I love KISS, if there is an output folder given put the generated files there otherwise where the source files are. This is how most people would expect it, I believe. |
The |
I'm pretty sure that -o generates files into that specific directory. Are you confusing this with maven plug-in? That thing definitely adds the package. -lib should be where it finds .tokens and such. why won't that work? Have you seen that bug about maven versus antlr tool behavior differing? There was a bunch of explanation there |
Doesn't work for me either. I ended up using the default behavior and copy
the files into place (and back) to make it work with Bazel.
…On Thu, Apr 20, 2017, 07:34 Terence Parr ***@***.***> wrote:
I'm pretty sure that -o generates files into that specific directory. Are
you confusing this with maven plug-in? That thing definitely adds the
package. -lib should beware it finds .tokens and such. why won't that work?
Have you seen that bug about maven versus antlr tool behavior differing?
There was a bunch of explanation there
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#638 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALUC_fam0uNep4c5whBV6aWUaXqTRTEaks5rx20IgaJpZM4CFqKy>
.
|
I examined where tool vs mvn plugin dumps stuff #1593 and antlr/intellij-plugin-v4#293 I wrote "(mvn plugin) uses a custom Tool that alters standard tool behavior to write generated code using dir structure it sees for .g4 files." but I seem to contradict myself on the 2nd link "Ok, confirming mvn plugin shoves stuff in output dir not package subdir." Ugh. all this directory stuff is painful. ok, a test shows the following: varmint:/tmp/test $ mkdir -p us/parr
varmint:/tmp/test $ vi us/parr/T.g4
varmint:/tmp/test $ tree
.
└── us
└── parr
└── T.g4
2 directories, 1 file
varmint:/tmp/test $ a4.7.1 us/parr/T.g4
varmint:/tmp/test $ tree
.
└── us
└── parr
├── T.g4
├── T.tokens
├── TBaseListener.java
├── TLexer.java
├── TLexer.tokens
├── TListener.java
└── TParser.java
2 directories, 7 files
varmint:/tmp/test $ mkdir build
varmint:/tmp/test $ a4.7.1 -o build us/parr/T.g4
varmint:/tmp/test $ tree
.
├── build
│ └── us
│ └── parr
│ ├── T.tokens
│ ├── TBaseListener.java
│ ├── TLexer.java
│ ├── TLexer.tokens
│ ├── TListener.java
│ └── TParser.java
└── us
└── parr
├── T.g4
├── T.tokens
├── TBaseListener.java
├── TLexer.java
├── TLexer.tokens
├── TListener.java
└── TParser.java
5 directories, 13 files The tool (not mvn plugin) appears to write things based upon the relative path using varmint:/tmp/test/us/parr $ a4.7.1 -o /tmp/test/build T.g4
varmint:/tmp/test/us/parr $ tree /tmp/test
/tmp/test
├── build
│ ├── T.tokens
│ ├── TBaseListener.java
│ ├── TLexer.java
│ ├── TLexer.tokens
│ ├── TListener.java
│ └── TParser.java
└── us
└── parr
└── T.g4 And this still puts stuff in $ a4.7.1 -o /tmp/test/build -package us.parr T.g4 So it's listening to the relative dirs not the |
Seems like it'd be hard to change all this given the software that likely depends on this behavior. |
Agreed. We could add a commandline option to disable the new behavior and
then make it the default in a later version though.
…On Thu, Apr 20, 2017 at 10:23 AM Terence Parr ***@***.***> wrote:
Seems like it'd be hard to change all this given the software that likely
depends on this behavior.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#638 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALUC_RX5QbiYxjQDgayrVpnDyfeNt4Qaks5rx5R1gaJpZM4CFqKy>
.
|
Ah. Good thought. Seems @mike-lischke has the right idea. If no If Does that sound right? Then Relative path on grammar files is not relevant to where stuff gets generated. Gen'd files either go in Actually if they specify |
I'm fine with a deprecation step here, since the patch changes behavior. However, it only changes behavior for relative grammar paths. Everything else stays as it is (because it works fine). For absolute grammar paths the output dir structure is very flat (no subdirs from the grammar paths), which is what I prefer all the time. If no grammar path is given but an output path, everything ends up (again) in the output folder. If there is no output folder then generated files go to the same folder where the grammars are. About |
@mike-lischke is this something you would like to see inserted for 4.7.1? |
Yes, absolutely. I'm currently using a hand crafted jar with that fix and having this patch in the official jar is certainly way better. The belonging PR is #1905. Thanks. |
Roger that. I will implement the scheme I have above outlined. I need to tweak the |
I think this will also help to fix gradle/gradle#2565. |
There are actually 2 aspects here:
Note: I had to recreate the PR I created to fix this issue, because in the previous one all changes got lost (not the first time, thanks git). Please take a look at that. |
…ct if you use a new option `-Xexact-output-dir`. Fixes antlr#1087, Fixes antlr#753, Fixes antlr#638.
Closed by #2065 |
If one defines a seperate Parser and Lexer as such:
Lexer.g4:
Parser.g4:
With the following directory layout:
Compiling from the
project
directory with the following command:java -jar antlr-4.2.2-complete.jar -o build src/*.g4
Fails with:
error(3): cannot find tokens file 'build/Lexer.tokens'
Lexer.tokens
is correctly generated, but is inbuild/src/Lexer.tokens
as expected.This works fine if the grammar files are in the current directory when compiling them (ie one runs
java -jar ../antlr-4.2.2-complete.jar -o ../build *.g4
or if an extra-lib build/src/
option is used.It seems this shouldn't be required and antlr should know where to find the .tokens file it generates.
UPDATE:
Here are some additional details about the proposed feature:
For the following, assume this directory layout:
With the following dependency between the grammars:
In all the following cases it is assumed that all of the grammar files are compiled in a single invocation of antlr, and that we want the generated files
to be in the build directory (optionally in sub folders).
1st case: All grammars in working directory.
We wish to compile metarParser.g4
Our working directory is project/src/foo/
Run command: antlr *.g4 -o ../../build/
Observed behavior:
Desired behavior:
2nd case: All grammars are in a given subdirectory.
We wish to compile metarParser.g4
Our working directory is project/
Run command: antlr src/foo/*.g4 -o build/
Observed behavior:
Desired behavior:
3rd case: All grammars are in (potentially) different subdirectories.
We wish to compile tafParser.g4
Our working directory is project/
Run command: antlr src/foo/*.g4 src/bar/tafParser.g4 -o build/
Observed behavior:
Desired behavior:
For the last two cases, all that is required is to keep track of the actual output directory (ie the directory specified with -o switch or the working directory, with the correct subdirectory) for every file, and to search those.
The text was updated successfully, but these errors were encountered: