Is Antlr3 supported by the Antlr plugin?

The documentation page is a bit skimpy; when I’ve stripped out my custom Antlr4 build logic, I get errors that make me think that Antlr3 is still not supported.

Typo: I have custom Antlr3 logic;

Here’s the build script which works; trying to cut this down to use the provided Antlr plugin fails.

description = “A DSL for configuring and querying the Novate platform”

project.ext {

antlrSource = “src/main/antlr3”

generatedDir = “$buildDir/generated-sources”

antlrOutput = “$generatedDir/antlr” }

configurations {

antlr3 }

sourceSets.main.java.srcDir antlrOutput

dependencies {

compile project(":logging")

compile “org.antlr:antlr:3.4”

// Note: pom.xml used exclusions to force anltr-runtime:3.3

antlr3 “org.antlr:antlr:3.3” }

task generateGrammarSource(type: JavaExec) {

description “Generates Java sources from Antlr3 grammars.”

inputs.source fileTree(dir: antlrSource, include: “**/*.g”)

outputs.dir file(antlrOutput)

classpath configurations.antlr3

main “org.antlr.Tool”

args “-o”, “${antlrOutput}/com/annadaletech/nexus/core/grammar”

args inputs.sourceFiles

doFirst {

logger.info “Executing Antlr3 grammar generation:\n${commandLine.join(’ ')}”

} }

idea.module {

// Hack the IML so that “build” is not excluded; necessary because several directories under build

// are added as source, resources, or test folders.

iml.whenMerged { module ->

module.excludeFolders.removeAll {

it.canonicalUrl.endsWith “/build”

}

} }

compileJava.dependsOn generateGrammarSource compileClojure.dependsOn compileJava

The ANTLR plugin that ships with Gradle only supports ANTLR 2.

I was hoping that had changed in the interrum!

Could the documentation be a little more clear about this?

I’ve added a clarifying statement.

… you could always invoke an Ant task IMHO :wink:

Well, it didn’t format well, but what I have above works well enough. I suspect if you had dozens of grammar files across multiple modules, you’d want to create something a bit more sophisticated and easily-reused.

You can use HTML ‘code’ tags for code snippets.