| 1 |
Usage |
| 2 |
|
| 3 |
The ANTLR 4 plugin for Maven can generate parsers for any number of grammars in |
| 4 |
your project. |
| 5 |
|
| 6 |
* Compiling Grammars into Parsers |
| 7 |
|
| 8 |
By default, the <<<{{{./antlr4-mojo.html}antlr4}}>>> goal will search for grammar |
| 9 |
files in the directory <<<$\{basedir\}/src/main/antlr4>>> and any additional |
| 10 |
<<<.tokens>>> files in the directory <<<$\{basedir\}/src/main/antlr4/imports>>>. |
| 11 |
This can be configured to search other directories using the plugin configuration |
| 12 |
parameters as described in the <<<{{{./antlr4-mojo.html}antlr4}}>>> goal |
| 13 |
documentation. |
| 14 |
|
| 15 |
The following figure shows the expected layout of files for the default |
| 16 |
configuration of this plugin. |
| 17 |
|
| 18 |
+-- |
| 19 |
src/main/ |
| 20 |
| |
| 21 |
+--- antlr4/... .g4 files organized in the required package structure |
| 22 |
| |
| 23 |
+--- imports/ user-created .tokens files and .g4 files that are imported by other grammars |
| 24 |
+-- |
| 25 |
|
| 26 |
The next step is to configure your POM to call the plugin. The goals will |
| 27 |
normally run during the generate-sources phase of the build. Examples of how to |
| 28 |
configure your POM can be found on the various examples pages, reachable via |
| 29 |
the page menu. If you stick with the default values, the snippet below will |
| 30 |
suffice: |
| 31 |
|
| 32 |
+-- |
| 33 |
<project> |
| 34 |
... |
| 35 |
<build> |
| 36 |
<plugins> |
| 37 |
<plugin> |
| 38 |
<groupId>org.antlr</groupId> |
| 39 |
<artifactId>antlr4-maven-plugin</artifactId> |
| 40 |
<version>${project.version}</version> |
| 41 |
<executions> |
| 42 |
<execution> |
| 43 |
<id>antlr</id> |
| 44 |
<goals> |
| 45 |
<goal>antlr4</goal> |
| 46 |
</goals> |
| 47 |
</execution> |
| 48 |
</executions> |
| 49 |
</plugin> |
| 50 |
</plugins> |
| 51 |
... |
| 52 |
</build> |
| 53 |
... |
| 54 |
</project> |
| 55 |
+-- |
| 56 |
|
| 57 |
Note that you can create multiple executions, and thus build some grammars with |
| 58 |
different options to others (such as setting the <<<debug>>> option for |
| 59 |
instance). |