Skip to content

daniellansun/antlr4-gradle-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Antlr4 Gradle Plugin

Build Status

The antlr4-gradle-plugin provides an easy way to generate grammars with Antlr4 using Gradle.

Installation

Use the following snippet inside a Gradle build file:

build.gradle
buildscript {
    repositories {
        maven {
            name 'JFrog OSS snapshot repo'
            url  'https://oss.jfrog.org/oss-snapshot-local/'
        }
        jcenter()
    }

    dependencies {
        classpath 'me.champeau.gradle:antlr4-gradle-plugin:0.1'
    }
}

repositories {
   jcenter()
}

apply plugin: 'me.champeau.gradle.antlr4'

Configuration

The plugin adds a new task named antlr4. This task exposes 5 properties as part of its configuration

source

where the source grammars are. Type: File. Default: src/main/antlr4.

output

where generated sources go. Type: File. Default: $buildDir/generated-src.

listener

generate parse tree listener. Type: boolean. Default: true

visitor

generate parse tree visitor. Type: boolean. Default: true

extraArgs

extra arguments to pass to the antlr4 tool. Type: List. Default: empty. Example: extraArgs=['-Werror']

Usage

Basic generation

Generating grammars can be done by calling the antlr4 task:

gradle antlr4

Dependency on generated sources

In general, you will want your main project to depend on the generated sources for compilation. You can easily do this by adding this configuration into your build.gradle:

build.gradle
// make the Java compile task depend on the antlr4 task
compileJava.dependsOn antlr4

// add the generated source files to the list of java sources
sourceSets.main.java.srcDirs += antlr4.output

// add antlr4 to classpath
configurations {
   compile.extendsFrom antlr4
}

About

Antlr4 plugin for Gradle

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 100.0%