Is Antlr3 supported by the Antlr plugin?


(Howard Lewis Ship) #1

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.


(Howard Lewis Ship) #2

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


(Peter Niederwieser) #3

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


(Howard Lewis Ship) #4

I was hoping that had changed in the interrum!


(Howard Lewis Ship) #5

Could the documentation be a little more clear about this?


(Peter Niederwieser) #6

I’ve added a clarifying statement.


(Jesús Zazueta) #7

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


(Howard Lewis Ship) #8

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.


(Peter Niederwieser) #9

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