Skip to content

Instantly share code, notes, and snippets.

@CAD97
Last active January 10, 2017 02:50
Show Gist options
  • Select an option

  • Save CAD97/d607d5b7965b640949c80e9ec3231830 to your computer and use it in GitHub Desktop.

Select an option

Save CAD97/d607d5b7965b640949c80e9ec3231830 to your computer and use it in GitHub Desktop.
antlr/intellij-plugin-v4 disagrees with antlr/antlr4/antlr4-maven-plugin/ on `.tokens` location

This is an issue when running separate lexer grammar and parser grammar (thus using options { tokenVocab = MyLexer ; }).

File Structure:

Project
| πŸ“ src
| | πŸ“ main
| | | πŸ“ antlr4
| | | | πŸ“ imports
| | | | πŸ“¦ some.package
| | | | | πŸ“„ MyLexer.g4
| | | | | πŸ“„ MyParser.g4
| πŸ“ target
| | πŸ“ generated-sources
| | | πŸ“ antlr4
| | | | πŸ“¦ some.package
| | | | | πŸ“„ MyLexer.java
| | | | | πŸ“„ MyParser.java
| | | | πŸ“„ MyLexer.tokens
| | | | πŸ“„ MyParser.tokens
| πŸ“„ pom.xml

The configuration for each .g4 is correct (~ means path to project)

Output directory where all output is generated | ~\target\generated-sources\antlr4
Location of imported grammars                  | ~\src\main\antlr4\imports
Grammar file encoding; e.g., euc-jp            | UTF-8
Package/namespace for the generated code       | some.package
Language (e.g., Java, Python2, CSharp, ...)    | Java

The IDEA plugin looks for the .tokenss in the folder ~/target/generated-sources/antlr4/some/package, but the maven plugin puts them in ~/target/generated-sources/antlr4.

IMHO, it makes more sense for the .tokens to be generated in the corresponding package where the generated code is located. This means that projects with grammars in multiple packages will have the .tokens files in the folders alongside the generated sources, instead of flat in the root of the generated sources folder.

I've uploaded a zip of a minimal reproduction case to a GitHub Gist. Note that the ANTLR file configuration has a ~ in the paths rather than the path to the project (as I don't know where you're putting the project). https://gist.github.com/CAD97/d607d5b7965b640949c80e9ec3231830

As this is a disagreement between the IDEA plugin and the Maven plugin, I've created this bug on both repositories. antlr/intellij-plugin-v4: antlr/intellij-plugin-v4#293 antlr/antlr4/antlr4-maven-plugin: antlr/antlr4#1593

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