Debian Codegraph @

antlr4-maven-plugin/src/site/apt/examples/libraries.apt.vm

raw
1 Libraries
2
3 The introduction of the import directive in a grammar allows reuse of common grammar files
4 as well as the ability to divide up functional components of large grammars. However it has
5 caused some confusion in regard to the fact that generated vocabulary files (<<<*.tokens>>>) can also
6 be searched for with the <<<<libDirectory>>>> directive.
7
8 This has confused two separate functions and imposes a structure upon the layout of
9 your grammar files in certain cases. If you have grammars that both use the import
10 directive and also require the use of a vocabulary file then you will need to locate
11 the grammar that generates the <<<.tokens>>> file alongside the grammar that uses it. This
12 is because you will need to use the <<<<libDirectory>>>> directive to specify the
13 location of your imported grammars and ANTLR will not find any vocabulary files in
14 this directory.
15
16 The <<<.tokens>>> files for any grammars are generated within the same output directory structure
17 as the <<<.java>>> files. So, wherever the <<<.java>>> files are generated, you will also find the <<<.tokens>>>
18 files. ANTLR looks for <<<.tokens>>> files in both the <<<<libDirectory>>>> and the output directory
19 where it is placing the generated <<<.java>>> files. Hence when you locate the grammars that generate
20 <<<.tokens>>> files in the same source directory as the ones that use the <<<.tokens>>> files, then
21 the Maven plugin will find the expected <<<.tokens>>> files.
22
23 The <<<<libDirectory>>>> is specified like any other directory parameter in Maven. Here is an
24 example:
25
26 +--
27 <plugin>
28 <groupId>org.antlr</groupId>
29 <artifactId>antlr4-maven-plugin</artifactId>
30 <version>${project.version}</version>
31
32 <executions>
33 <execution>
34 <configuration>
35 <goals>
36 <goal>antlr4</goal>
37 </goals>
38 <libDirectory>src/main/antlr4_imports</libDirectory>
39 </configuration>
40 </execution>
41 </executions>
42 </plugin>
43 +--
44
45
46