Antlr4 maven plugin cannot find grammar files in different directories

I use the antlr4 maven plugin to create my maven project that uses antlr4:

<groupId>org.antlr</groupId> <artifactId>antlr4-maven-plugin</artifactId> <version>4.0</version> 

I started with one grammar file and got my pom.xml setting and everything was beautifully built.

Then I decided to split my grammar into logical parts and therefore used several grammar files, but in different directories (therefore, the generated code will be placed in separate packages), but still they are all under the same root directory src / main / antlr4.

I use the import statement in my "top" level grammar file to import other necessary files.

But now maven gives me the following error when trying to build:

 [ERROR] Message{errorType=CANNOT_FIND_IMPORTED_GRAMMAR 

Why can't I find other files that I import?

thanks, Ryan.

+4
source share
2 answers

I had the same problem and solved with the following configuration:

 <libDirectory>${basedir}/src/main/antlr4/yourGrammarDirectory</libDirectory> 

Take a look here: How to import grammar into Antlr4 for assembly using maven

+3
source

For the release of ANTLR 4.0, import testing was not carried out in many directories.

Due to the limited benefits (IMO) provided by the current grammar import mechanism, this is currently a very low priority. Currently, sharing grammar files using imports will not allow you to use the code for the generated parsers or parse trees that they produce. I have been using ANTLR for dozens of products (including commercial releases) for many years, and have never found compound grammars to provide more benefits than troubles. (Note that I'm talking about the import statement here. Separating lexical and parser grammars into separate files in the same directory is often useful and my preferred way of working.)

0
source

Source: https://habr.com/ru/post/951303/


All Articles