The Antlr plugin extends the Java plugin to add support for generating parsers using Antlr.
To use the Antlr plugin, include in your build script:
The Antlr plugin adds a number of tasks to your project, as shown below.
Table 31.1. Antlr plugin - tasks
Task name | Depends on | Type | Description |
generateGrammarSource
|
- | AntlrTask |
Generates the source files for all production Antlr grammars. |
generateTestGrammarSource
|
- | AntlrTask |
Generates the source files for all test Antlr grammars. |
generate
|
- | AntlrTask |
Generates the source files for all Antlr grammars for the given source set. |
The Antlr plugin adds the following dependencies to tasks added by the Java plugin.
Table 31.2. Antlr plugin - additional task dependencies
Task name | Depends on |
compileJava | generateGrammarSource |
compileTestJava | generateTestGrammarSource |
compileSourceSet Java |
generateSourceSet GrammarSource |
Table 31.3. Antlr plugin - project layout
Directory | Meaning |
src/main/antlr
|
Production Antlr grammar files. |
src/test/antlr
|
Test Antlr grammar files. |
src/
|
Antlr grammar files for the given source set. |
The Antlr plugin adds an antlr
dependency configuration. You use this to declare the
version of Antlr you wish to use.
Example 31.2. Declare Antlr version
build.gradle
repositories {
mavenCentral()
}
dependencies {
antlr 'antlr:antlr:2.7.7'
}
The Antlr plugin adds the following properties to each source set in the project.
Table 31.4. Antlr plugin - source set properties
Property name | Type | Default value | Description |
antlr
|
SourceDirectorySet (read-only)
|
Not null |
The Antlr grammar files of this source set. Contains all .g found in the Antlr
source directories, and excludes all other types of files.
|
antlr.srcDirs
|
Set<File> . Can set using anything described in Section 15.5, “Specifying a set of input files”.
|
[
|
The source directories containing the Antlr grammar files of this source set. |