Skip to content
Snippets Groups Projects
Commit b7f974f3 authored by Haibo Huang's avatar Haibo Huang
Browse files

Update antlr to 3.5.2

1. Add post_update.sh to preserve build.gradle.
2. Add the patches/fix_infinite_recursion.diff to fix infinite
recursion.
3. Run tools/external_updater/updater.sh update antlr

(Should we upgrade to v4?)

Test: m javac-check RUN_ERROR_PRONE=true
Change-Id: Idafdb1cf6cf2310d983be612f36c5e6596a6e23f
parent bbed35ef
Branches
No related tags found
No related merge requests found
Showing
with 396 additions and 1057 deletions
# Maven build folders
target/
# IntelliJ project files
*.iml
*.ipr
*.iws
.idea/
# Eclipse project files
.project
.classpath
.settings/
# NetBeans user configuration
nbactions.xml
nb-configuration.xml
# Python runtime files
*.py[co]
# ANTLR C# target build folders
/runtime/CSharp3/Sources/Antlr3.Runtime/bin/
/runtime/CSharp3/Sources/Antlr3.Runtime/obj/
/runtime/CSharp3/Sources/Antlr3.Runtime.Debug/bin/
/runtime/CSharp3/Sources/Antlr3.Runtime.Debug/obj/
/runtime/CSharp3/Sources/Antlr3.Runtime.JavaExtensions/bin/
/runtime/CSharp3/Sources/Antlr3.Runtime.JavaExtensions/obj/
/runtime/CSharp3/Sources/Antlr3.Runtime.Test/bin/
/runtime/CSharp3/Sources/Antlr3.Runtime.Test/obj/
This diff is collapsed.
name: "antlr3"
description:
"ANTLR (ANother Tool for Language Recognition) is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages."
description: "ANTLR (ANother Tool for Language Recognition) is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages."
third_party {
url {
type: HOMEPAGE
......@@ -9,8 +7,12 @@ third_party {
}
url {
type: ARCHIVE
value: "https://github.com/antlr/antlr3/archive/antlr-3.4.zip"
value: "https://github.com/antlr/antlr3/archive/3.5.2.zip"
}
version: "3.5.2"
last_upgrade_date {
year: 2018
month: 8
day: 28
}
version: "3.4"
last_upgrade_date { year: 2011 month: 11 day: 15 }
}
ANTLR v3.4
July 18, 2011
ANTLR v3.5
January 4, 2013
Terence Parr, parrt at cs usfca edu
ANTLR project lead and supreme dictator for life
......@@ -13,8 +13,8 @@ recognizers, interpreters, compilers, and translators from grammatical
descriptions containing actions in a variety of target
languages. ANTLR provides excellent support for tree construction,
tree walking, translation, error recovery, and error reporting. I've
been working on parser generators for 20 years and on this particular
version of ANTLR for 7 years.
been working on parser generators for 25 years and on this particular
version of ANTLR for 9 years.
You should use v3 in conjunction with ANTLRWorks:
......@@ -74,17 +74,12 @@ EXAMPLES
ANTLR v3 sample grammars:
http://www.antlr.org/download/examples-v3.tar.gz
https://github.com/antlr/examples-v3
Examples from Language Implementation Patterns:
http://www.pragprog.com/titles/tpdsl/source_code
Also check out Mantra Programming Language for a prototype (work in
progress) using v3:
http://www.linguamantra.org/
----------------------------------------------------------------------
What is ANTLR?
......@@ -113,27 +108,35 @@ See migration guide:
How do I install this damn thing?
Just untar antlr-3.4.tar.gz and you'll get:
antlr-3.4/BUILD.txt
antlr-3.4/antlr3-maven-plugin
antlr-3.4/antlrjar.xml
antlr-3.4/antlrsources.xml
antlr-3.4/gunit
antlr-3.4/gunit-maven-plugin
antlr-3.4/pom.xml
antlr-3.4/runtime
antlr-3.4/tool
antlr-3.4/lib
This is the source and java binaries. You could grab the
antlr-3.4-complete.jar file from the website, but it's in lib dir.
You will have grabbed either of these:
http://antlr.org/download/antlr-3.5-complete-no-st3.jar
http://antlr.org/download/antlr-3.5-complete.jar
It has all of the jars you need combined into one. Then you need to
add antlr-3.4-complete.jar to your CLASSPATH or add
to arg list; e.g., on unix:
add antlr-3.5-complete.jar to your CLASSPATH or add to arg list; e.g., on unix:
$ java -cp "/usr/local/lib/antlr-3.5-complete.jar:$CLASSPATH" org.antlr.Tool Test.g
$ java -cp "/usr/local/lib/antlr-3.4-complete.jar:$CLASSPATH" org.antlr.Tool Test.g
Source + java binaries: Just untar antlr-3.5.tar.gz and you'll get:
antlr-3.5/BUILD.txt
antlr-3.5/antlr3-maven-plugin
antlr-3.5/antlrjar.xml
antlr-3.5/antlrsources.xml
antlr-3.5/gunit
antlr-3.5/gunit-maven-plugin
antlr-3.5/pom.xml
antlr-3.5/runtime
antlr-3.5/tool
antlr-3.5/lib
Please see the FAQ
http://www.antlr.org/wiki/display/ANTLR3/ANTLR+v3+FAQ
-------------------------
How can I contribute to ANTLR v3?
http://www.antlr.org/wiki/pages/viewpage.action?pageId=33947666
URL: https://github.com/antlr/website-antlr3/raw/gh-pages/download/antlr-3.4.tar.gz
Version: 3.4
BugComponent: 99142
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>antlr-complete</artifactId>
<packaging>jar</packaging>
<name>ANTLR 3 Complete</name>
<description>Complete distribution for ANTLR 3</description>
<!--
Inherit from the ANTLR master pom, which tells us what
version we are and allows us to inherit dependencies
and so on.
-->
<parent>
<groupId>org.antlr</groupId>
<artifactId>antlr-master</artifactId>
<version>3.5.2</version>
</parent>
<url>http://antlr.org/</url>
<!--
The complete distribution includes the following modules and their dependencies:
ANTLR 3 Tool
ANTLR 3 Runtime
gUnit for ANTLR 3
StringTemplate 4 (dependency of code generator in the ANTLR 3 Tool)
StringTemplate 3 (dependency of grammars with output=template)
ANTLR 2.7.7 (dependency of template parser in StringTemplate 3)
-->
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>gunit</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<minimizeJar>false</minimizeJar>
<createSourcesJar>true</createSourcesJar>
<filters>
<filter>
<artifact>org.antlr:antlr-complete</artifact>
<includes>
<include>META-INF/**</include>
</includes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.antlr.Tool</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<id>complete-no-st3</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>no-st3</shadedClassifierName>
<filters>
<filter>
<artifact>antlr:antlr</artifact>
<excludes>
<exclude>**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.antlr:stringtemplate</artifact>
<excludes>
<exclude>**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
<execution>
<id>complete</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<includeDependencySources>true</includeDependencySources>
</configuration>
</plugin>
</plugins>
</build>
</project>
fred=99
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-archetype</artifactId>
<version>3.4</version>
<packaging>maven-archetype</packaging>
<name>ANTLR3 Maven Archetype 3.4</name>
<name>ANTLR 3 Maven Archetype</name>
<description>ANTLR 3 Maven Archetype</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--
Inherit from the ANTLR master pom, which tells us what
version we are and allows us to inherit dependencies
and so on.
Unfortunately, because of a bug in the archetype plugin
we cannot use the parent pom because it causes the
artifactId in the generated pom to be set to antlr3-maven-archetype
We will reinstate this parent usage when that is fixed.
-->
<parent>
<groupId>org.antlr</groupId>
<artifactId>antlr-master</artifactId>
<version>3.4</version>
</parent>
-->
<!--
The ANTLR Maven artifacts are now released via the Sonotype OSS
repository, which means that they are synced to Maven central
within a few minutes of hitting the release repo for Sonotype.
To enable this, we inherit from the Sonotype provided parent
pom. However, we must also configure our .m2/settings.xml to include
the snapshot and staging server and the sonotype password. This
means that only ANTLR developers can released the artifacts, but
anyone can build locally.
-->
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
<version>3.5.2</version>
</parent>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>deploy</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<extensions>
......@@ -84,7 +29,7 @@
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.0</version>
<version>2.2</version>
</extension>
</extensions>
......@@ -93,38 +38,10 @@
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0</version>
<version>2.2</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
......@@ -24,7 +24,7 @@
Archetype by Jim Idle (jimi@temporal-wave.com) - Oct 2009
Report bugs to the ANTLR interest list at http://www.antlr.org
Generated by antlr3-maven-archetype version 3.4
Generated by antlr3-maven-archetype version 3.4.1-SNAPSHOT
=======================================================================
-->
......@@ -58,7 +58,7 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.4</version>
<version>3.4.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
......@@ -84,7 +84,7 @@
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.4</version>
<version>3.4.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
......@@ -100,7 +100,7 @@
the prototype, but we use it to illustrate how you can get
the JDK 6 Java compiler to accept 1.5 or 1.6 targeted source code
but produce class files that are compatible with JRE 1.4. As
Michael Caine might not say, "Not a lot of people know that!"
Michael Caine might say, "Not a lot of people know that!"
-->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
......
......@@ -33,25 +33,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--
The ANTLR Maven artifacts are now released via the Sonotype OSS
repository, which means that they are synced to Maven central
within a few minutes of hitting the release repo for Sonotype.
To enable this, we inherit from the Sonotype provided parent
pom. However, we must also configure our .m2/settings.xml to include
the snapshot and staging server and the sonotype password. This
means that only ANTLR developers can released the artifacts, but
anyone can build locally.
-->
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- Maven model we are inheriting from
-->
......@@ -77,12 +59,13 @@
<artifactId>antlr3-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<!-- Note that as this plugin depends on the ANTLR tool itself
we cannot use the paren pom to control the version number
and MUST update <version> in this pom manually!
-->
<version>3.4</version>
<name>Maven plugin for ANTLR V3.4</name>
<parent>
<groupId>org.antlr</groupId>
<artifactId>antlr-master</artifactId>
<version>3.5.2</version>
</parent>
<name>ANTLR 3 Maven plugin</name>
<prerequisites>
<maven>2.0</maven>
</prerequisites>
......@@ -126,44 +109,13 @@ Jim Idle - March 2009
</description>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>deploy</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<developers>
<developer>
<name>Jim Idle</name>
<url>http://www.temporal-wave.com</url>
<roles>
<role>Originator, version 3.1.3+</role>
<role>Originator, version 3.1.3</role>
</roles>
</developer>
......@@ -193,44 +145,6 @@ Jim Idle - March 2009
</developers>
<!-- Where do we track bugs for this project?
-->
<issueManagement>
<system>JIRA</system>
<url>http://antlr.org/jira/browse/ANTLR</url>
</issueManagement>
<!-- Location of the license description for this project
-->
<licenses>
<license>
<distribution>repo</distribution>
<name>The BSD License</name>
<url>http://www.antlr.org/LICENSE.txt </url>
</license>
</licenses>
<!-- Ancilliary information for completeness
-->
<inceptionYear>2009</inceptionYear>
<mailingLists>
<mailingList>
<archive>http://antlr.markmail.org/</archive>
<otherArchives>
<otherArchive>http://www.antlr.org/pipermail/antlr-interest/</otherArchive>
</otherArchives>
<name>ANTLR Users</name>
<subscribe>http://www.antlr.org/mailman/listinfo/antlr-interest/</subscribe>
<unsubscribe>http://www.antlr.org/mailman/options/antlr-interest/</unsubscribe>
<post>antlr-interest@antlr.org</post>
</mailingList>
</mailingLists>
<organization>
<name>ANTLR.org</name>
<url>http://www.antlr.org</url>
</organization>
<!-- ============================================================================= -->
<!--
......@@ -261,7 +175,7 @@ Jim Idle - March 2009
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>1.5.3</version>
<version>2.0</version>
</dependency>
<!--
......@@ -272,25 +186,13 @@ Jim Idle - March 2009
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>3.4</version>
</dependency>
<!--
Testing requirements...
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>1.0</version>
<version>1.1</version>
<scope>test</scope>
</dependency>
......@@ -298,64 +200,34 @@ Jim Idle - March 2009
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>jsr14</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.0</version>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1.1</version>
<version>2.7</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
</plugin>
</plugins>
</build>
</reporting>
</project>
......@@ -56,7 +56,7 @@ public class Antlr3ErrorLog implements ANTLRErrorListener {
/**
* Sends an informational message to the Maven log sink.
* @param s The message to send to Maven
* @param message The message to send to Maven
*/
public void info(String message) {
log.info(message);
......
......@@ -45,7 +45,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.antlr.Tool;
import org.antlr.runtime.RecognitionException;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
......@@ -54,13 +53,11 @@ import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
/**
* Goal that picks up all the ANTLR grammars in a project and moves those that
* are required for generation of the compilable sources into the location
* that we use to compile them, such as target/generated-sources/antlr3 ...
* Parses ANTLR grammar files {@code *.g} and transforms them into Java source
* files.
*
* @goal antlr
*
* @phase process-sources
* @phase generate-sources
* @requiresDependencyResolution compile
* @requiresProject true
*
......@@ -82,7 +79,7 @@ public class Antlr3Mojo
protected boolean report;
/**
* If set to true, then the ANTLR tool will print a version of the input
* grammar which is devoid of any actions that may be present in the input file.
* grammar(s) which are stripped of any embedded actions.
*
* @parameter default-value="false"
*/
......@@ -96,119 +93,124 @@ public class Antlr3Mojo
*/
protected boolean debug;
/**
* If set to true, then then the generated parser will compute and report on
* profile information at runtime.
* If set to true, then the generated parser will compute and report profile
* information at runtime.
*
* @parameter default-value="false"
*/
protected boolean profile;
/**
* If set to true then the ANTLR tool will generate a description of the nfa
* for each rule in <a href="http://www.graphviz.org">Dot format</a>
* If set to true, then the ANTLR tool will generate a description of the
* NFA for each rule in <a href="http://www.graphviz.org">Dot format</a>
*
* @parameter default-value="false"
*/
protected boolean nfa;
/**
* If set to true then the ANTLR tool will generate a description of the DFA
* for each decision in the grammar in <a href="http://www.graphviz.org">Dot format</a>
* If set to true, then the ANTLR tool will generate a description of the
* DFA for each decision in the grammar in
* <a href="http://www.graphviz.org">Dot format</a>.
*
* @parameter default-value="false"
*/
protected boolean dfa;
/**
* If set to true, the generated parser code will log rule entry and exit points
* to stdout as an aid to debugging.
* If set to true, the generated parser code will log rule entry and exit
* points to stdout ({@link System#out} for the Java target) as an aid to
* debugging.
*
* @parameter default-value="false"
*/
protected boolean trace;
/**
* If this parameter is set, it indicates that any warning or error messages returned
* by ANLTR, should be formatted in the specified way. Currently, ANTLR supports the
* built-in formats of antlr, gnu and vs2005.
* If this parameter is set, it indicates that any warning or error messages
* returned by ANLTR, should be formatted in the specified way. Currently,
* ANTLR supports the built-in formats {@code antlr}, {@code gnu} and
* {@code vs2005}.
*
* @parameter default-value="antlr"
*/
protected String messageFormat;
/**
* If this parameter is set to true, then ANTLR will report all sorts of things
* about what it is doing such as the names of files and the version of ANTLR and so on.
* If set to true, then ANTLR will report verbose messages during the code
* generation process. This includes the names of files, the version of
* ANTLR, and more.
*
* @parameter default-value="true"
*/
protected boolean verbose;
/**
* The number of alts, beyond which ANTLR will not generate a switch statement
* for the DFA.
* The maximum number of alternatives allowed in an inline switch statement.
* Beyond this, ANTLR will not generate a switch statement for the DFA.
*
* @parameter default-value="300"
*/
private int maxSwitchCaseLabels;
/**
* The number of alts, below which ANTLR will not choose to generate a switch
* statement over an if statement.
* The minimum number of alternatives for ANTLR to generate a switch
* statement. For decisions with fewer alternatives, an if/else if/else
* statement will be used instead.
*
* @parameter default-value="3"
*/
private int minSwitchAlts;
/* --------------------------------------------------------------------
* The following are Maven specific parameters, rather than specificlly
* The following are Maven specific parameters, rather than specific
* options that the ANTLR tool can use.
*/
/**
* Provides an explicit list of all the grammars that should
* be included in the generate phase of the plugin. Note that the plugin
* is smart enough to realize that imported grammars should be included but
* not acted upon directly by the ANTLR Tool.
*
* Unless otherwise specified, the include list scans for and includes all
* files that end in ".g" in any directory beneath src/main/antlr3. Note that
* this version of the plugin looks for the directory antlr3 and not the directory
* antlr, so as to avoid clashes and confusion for projects that use both v2 and v3 grammars
* such as ANTLR itself.
* Provides an explicit list of all the grammars that should be included in
* the generate phase of the plugin. Note that the plugin is smart enough to
* realize that imported grammars should be included but not acted upon
* directly by the ANTLR Tool.
* <p>
* A set of Ant-like inclusion patterns used to select files from the source
* directory for processing. By default, the pattern <code>**&#47;*.g</code>
* is used to select grammar files.</p>
*
* @parameter
*/
protected Set includes = new HashSet();
protected Set<String> includes = new HashSet<String>();
/**
* Provides an explicit list of any grammars that should be excluded from
* the generate phase of the plugin. Files listed here will not be sent for
* processing by the ANTLR tool.
* A set of Ant-like exclusion patterns used to prevent certain files from
* being processed. By default, this set is empty such that no files are
* excluded.
*
* @parameter
*/
protected Set excludes = new HashSet();
protected Set<String> excludes = new HashSet<String>();
/**
* The current Maven project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;
/**
* Specifies the Antlr directory containing grammar files. For
* antlr version 3.x we default this to a directory in the tree
* called antlr3 because the antlr directory is occupied by version
* 2.x grammars.
* The directory where the ANTLR grammar files ({@code *.g}) are located.
*
* @parameter default-value="${basedir}/src/main/antlr3"
* @required
*/
private File sourceDirectory;
/**
* Location for generated Java files. For antlr version 3.x we default
* this to a directory in the tree called antlr3 because the antlr
* directory is occupied by version 2.x grammars.
* The directory where the parser files generated by ANTLR will be stored.
* The directory will be registered as a compile source root of the project
* such that the generated files will participate in later build phases like
* compiling and packaging.
*
* @parameter default-value="${project.build.directory}/generated-sources/antlr3"
* @required
*/
private File outputDirectory;
/**
* Location for imported token files, e.g. <code>.tokens</code> and imported grammars.
* Note that ANTLR will not try to process grammars that it finds to be imported
* into other grammars (in the same processing session).
* Location for imported token files, e.g. {@code *.tokens} and imported
* grammars. Note that ANTLR will not try to process grammars that it finds
* to be imported into other grammars (in the same processing session).
*
* @parameter default-value="${basedir}/src/main/antlr3/imports"
*/
......@@ -230,7 +232,7 @@ public class Antlr3Mojo
project.addCompileSourceRoot(outputDir.getPath());
}
/**
* An instance of the ANTLR tool build
* An instance of the ANTLR tool build.
*/
protected Tool tool;
......@@ -238,8 +240,10 @@ public class Antlr3Mojo
* The main entry point for this Mojo, it is responsible for converting
* ANTLR 3.x grammars into the target language specified by the grammar.
*
* @throws org.apache.maven.plugin.MojoExecutionException When something is discovered such as a missing source
* @throws org.apache.maven.plugin.MojoFailureException When something really bad happens such as not being able to create the ANTLR Tool
* @throws MojoExecutionException if a configuration or grammar error causes
* the code generation process to fail
* @throws MojoFailureException if an instance of the ANTLR 3 {@link Tool}
* cannot be created
*/
public void execute()
throws MojoExecutionException, MojoFailureException {
......@@ -253,15 +257,13 @@ public class Antlr3Mojo
// Excludes
//
for (String e : (Set<String>) excludes) {
for (String e : excludes) {
log.debug("ANTLR: Exclude: " + e);
}
// Includes
//
for (String e : (Set<String>) includes) {
for (String e : includes) {
log.debug("ANTLR: Include: " + e);
}
......@@ -401,20 +403,18 @@ public class Antlr3Mojo
*
* @param sourceDirectory
* @param outputDirectory
* @throws antlr.TokenStreamException
* @throws antlr.RecognitionException
* @throws java.io.IOException
* @throws org.codehaus.plexus.compiler.util.scan.InclusionScanException
* @throws IOException
* @throws InclusionScanException
*/
private void processGrammarFiles(File sourceDirectory, File outputDirectory)
throws RecognitionException, IOException, InclusionScanException {
throws IOException, InclusionScanException {
// Which files under the source set should we be looking for as grammar files
//
SourceMapping mapping = new SuffixMapping("g", Collections.EMPTY_SET);
SourceMapping mapping = new SuffixMapping("g", Collections.<String>emptySet());
// What are the sets of includes (defaulted or otherwise).
//
Set includes = getIncludesPatterns();
Set<String> includes = getIncludesPatterns();
// Now, to the excludes, we need to add the imports directory
// as this is autoscanned for importd grammars and so is auto-excluded from the
......@@ -425,7 +425,7 @@ public class Antlr3Mojo
SourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, excludes);
scan.addSourceMapping(mapping);
Set grammarFiles = scan.getIncludedSources(sourceDirectory, null);
Set<File> grammarFiles = scan.getIncludedSources(sourceDirectory, null);
if (grammarFiles.isEmpty()) {
if (getLog().isInfoEnabled()) {
......@@ -440,7 +440,7 @@ public class Antlr3Mojo
// Iterate each grammar file we were given and add it into the tool's list of
// grammars to process.
//
for (File grammar : (Set<File>) grammarFiles) {
for (File grammar : grammarFiles) {
if (getLog().isDebugEnabled()) {
getLog().debug("Grammar file '" + grammar.getPath() + "' detected.");
......@@ -461,7 +461,7 @@ public class Antlr3Mojo
}
public Set getIncludesPatterns() {
public Set<String> getIncludesPatterns() {
if (includes == null || includes.isEmpty()) {
return Collections.singleton("**/*.g");
}
......@@ -471,11 +471,11 @@ public class Antlr3Mojo
/**
* Given the source directory File object and the full PATH to a
* grammar, produce the path to the named grammar file in relative
* terms to the sourceDirectory. This will then allow ANTLR to
* terms to the {@code sourceDirectory}. This will then allow ANTLR to
* produce output relative to the base of the output directory and
* reflect the input organization of the grammar files.
*
* @param sourceDirectory The source directory File object
* @param sourceDirectory The source directory {@link File} object
* @param grammarFileName The full path to the input grammar file
* @return The path to the grammar file relative to the source directory
*/
......@@ -487,7 +487,11 @@ public class Antlr3Mojo
}
File unprefixedGrammarFileName = new File(grammarFileName.substring(srcPath.length()));
if ( unprefixedGrammarFileName.getParent()!=null ) {
return unprefixedGrammarFileName.getParent() + File.separator;
}
else {
return "";
}
}
}
Imported Grammar Files
In order to have the ANTLR plugin automatically locate and use grammars used
as imports in your main .g files, you need to place the imported grammar
as imports in your main <<<.g>>> files, you need to place the imported grammar
files in the imports directory beneath the root directory of your grammar
files (which is <<<src/main/antlr3>>> by default of course).
......
......@@ -2,23 +2,23 @@ Libraries
The introduction of the import directive in a grammar allows reuse of common grammar files
as well as the ability to divide up functional components of large grammars. However it has
caused some confusion in regard to the fact that generated vocab files (<<<xxx.tokens>>>) can also
caused some confusion in regard to the fact that generated vocabulary files (<<<*.tokens>>>) can also
be searched for with the <<<<libDirectory>>>> directive.
This has confused two separate functions and imposes a structure upon the layout of
your grammar files in certain cases. If you have grammars that both use the import
directive and also require the use of a vocab file then you will need to locate
the grammar that generates the .tokens file alongside the grammar that uses it. This
directive and also require the use of a vocabulary file then you will need to locate
the grammar that generates the <<<.tokens>>> file alongside the grammar that uses it. This
is because you will need to use the <<<<libDirectory>>>> directive to specify the
location of your imported grammars and ANTLR will not find any vocab files in
location of your imported grammars and ANTLR will not find any vocabulary files in
this directory.
The .tokens files for any grammars are generated within the same output directory structure
as the .java files. So, whereever the .java files are generated, you will also find the .tokens
files. ANTLR looks for .tokens files in both the <<<<libDirectory>>>> and the output directory
where it is placing the geenrated .java files. Hence when you locate the grammars that generate
.tokens files in the same source directory as the ones that use the .tokens files, then
the Maven plugin will find the expected .tokens files.
The <<<.tokens>>> files for any grammars are generated within the same output directory structure
as the <<<.java>>> files. So, wherever the <<<.java>>> files are generated, you will also find the <<<.tokens>>>
files. ANTLR looks for <<<.tokens>>> files in both the <<<<libDirectory>>>> and the output directory
where it is placing the generated <<<.java>>> files. Hence when you locate the grammars that generate
<<<.tokens>>> files in the same source directory as the ones that use the <<<.tokens>>> files, then
the Maven plugin will find the expected <<<.tokens>>> files.
The <<<<libDirectory>>>> is specified like any other directory parameter in Maven. Here is an
example:
......@@ -27,10 +27,9 @@ Libraries
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.1.3-1</version>
<version>${plugin.version}</version>
<executions>
<execution>
<configuration>
<goals>
......
Simple configuration
If your grammar files are organized into the default locations as described in the {{{../index.html}introduction}},
then configuring the pom.xml file for your project is as simple as adding this to it
then configuring the <<<pom.xml>>> file for your project is as simple as adding this to it
+--
<plugins>
......@@ -21,12 +21,12 @@ Simple configuration
</plugins>
+--
When the mvn command is executed all grammar files under <<<src/main/antlr3>>>, except any
When the <<<mvn>>> command is executed all grammar files under <<<src/main/antlr3>>>, except any
import grammars under <<<src/main/antlr3/imports>>> will be analyzed and converted to
java source code in the output directory <<<target/generated-sources/antlr3>>>.
Java source code in the output directory <<<target/generated-sources/antlr3>>>.
Your input files under <<<antlr3>>> should be stored in sub directories that
reflect the package structure of your java parsers. If your grammar file parser.g contains:
reflect the package structure of your java parsers. If your grammar file <<<parser.g>>> contains:
+---
@header {
......@@ -34,7 +34,7 @@ package org.jimi.themuss;
}
+---
Then the .g file should be stored in: <<<src/main/antlr3/org/jimi/themuss/parser.g>>>. THis way
the generated .java files will correctly reflect the package structure in which they will
Then the <<<.g>>> file should be stored in: <<<src/main/antlr3/org/jimi/themuss/parser.g>>>. This way
the generated <<<.java>>> files will correctly reflect the package structure in which they will
finally rest as classes.
FAQ
......@@ -49,10 +49,10 @@ ANTLR v3 Maven plugin
+--- imports/ .g files that are imported by other grammars.
+--
If your grammar is intended to be part of a package called org.foo.bar then you would
If your grammar is intended to be part of a package called <<<org.foo.bar>>> then you would
place it in the directory <<<src/main/antlr3/org/foo/bar>>>. The plugin will then produce
.java and .tokens files in the output directory <<<target/generated-sources/antlr3/org/foo/bar>>>
When the Java files are compiled they will be in the correct location for the javac
<<<.java>>> and <<<.tokens>>> files in the output directory <<<target/generated-sources/antlr3/org/foo/bar>>>
When the Java files are compiled they will be in the correct location for the Javac
compiler without any special configuration. The generated java files are automatically
submitted for compilation by the plugin.
......@@ -60,4 +60,3 @@ ANTLR v3 Maven plugin
any grammar files that are imported by other grammar files (do not make subdirectories here.)
Such files are never built on their own, but the plugin will automatically tell the ANTLR
tool to look in this directory for library files.
Usage
The Maven plugin for antlr is simple to use but is at its simplest when you use the default
layouts for your grammars, as so:
The ANTLR 3 plugin for Maven can generate parsers for any number of grammars in
your project.
* Compiling Grammars into Parsers
By default, the <<<{{{./antlr-mojo.html}antlr}}>>> goal will search for grammar
files in the directory <<<$\{basedir\}/src/main/antlr3>>> and any additional
<<<.tokens>>> files in the directory <<<$\{basedir\}/src/main/antlr3/imports>>>.
This can be configured to search other directories using the plugin configuration
parameters as described in the <<<{{{./antlr-mojo.html}antlr}}>>> goal
documentation.
The following figure shows the expected layout of files for the default
configuration of this plugin.
+--
src/main/
|
+--- antlr3/... .g files organized in the required package structure
|
+--- imports/ .g files that are imported by other grammars.
+--- imports/ user-created .tokens files and .g files that are imported by other grammars
+--
However, if you are not able to use this structure for whatever reason, you
can configure the locations of the grammar files, where library/import files
are located and where the output files should be generated.
* Plugin Descriptor
The current version of the plugin is shown at the top of this page after the <<Last Deployed>> date.
The full layout of the descriptor (at least, those parts that are not standard Maven things),
showing the default values of the configuration options, is as follows:
The next step is to configure your POM to call the plugin. The goals will
normally run during the generate-sources phase of the build. Examples of how to
configure your POM can be found on the various examples pages, reachable via
the page menu. If you stick with the default values, the snippet below will
suffice:
+--
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.1.3-1</version>
<version>${project.version}</version>
<executions>
<execution>
<configuration>
<id>antlr</id>
<goals>
<goal>antlr</goal>
</goals>
<conversionTimeout>10000</conversionTimeout>
<debug>false</debug>
<dfa>false</dfa>
<nfa>false</nfa>
<excludes><exclude/></excludes>
<includes><include/></includes>
<libDirectory>src/main/antlr3/imports</libDirectory>
<messageFormat>antlr</messageFormat>
<outputDirectory>target/generated-sources/antlr3</outputDirectory>
<printGrammar>false</printGrammar>
<profile>false</profile>
<report>false</report>
<sourceDirectory>src/main/antlr3</sourceDirectory>
<trace>false</trace>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
+--
Note that you can create multiple executions, and thus build some grammars with different
options to others (such as setting the debug option for instance).
** Configuration parameters
*** report
If set to true, then after the tool has processed an input grammar file
it will report variaous statistics about the parser, such as information
on cyclic DFAs, which rules may use backtracking, and so on.
default-value="false"
*** printGrammar
If set to true, then the ANTLR tool will print a version of the input
grammar which is devoid of any actions that may be present in the input file.
default-value = "false"
*** debug
If set to true, then the code generated by the ANTLR code generator will
be set to debug mode. This means that when run, the code will 'hang' and
wait for a debug connection on a TCP port (49100 by default).
default-value="false"
*** profile
If set to true, then then the generated parser will compute and report on
profile information at runtime.
default-value="false"
*** nfa
If set to true then the ANTLR tool will generate a description of the nfa
for each rule in <a href="http://www.graphviz.org">Dot format</a>
default-value="false"
protected boolean nfa;
*** dfa
If set to true then the ANTLR tool will generate a description of the DFA
for each decision in the grammar in <a href="http://www.graphviz.org">Dot format</a>
default-value="false"
*** trace
If set to true, the generated parser code will log rule entry and exit points
to stdout as an aid to debugging.
default-value="false"
*** messageFormat
If this parameter is set, it indicates that any warning or error messages returned
by ANLTR, shoould be formatted in the specified way. Currently, ANTLR supports the
built-in formats of antlr, gnu and vs2005.
default-value="antlr"
*** verbose
If this parameter is set to true, then ANTLR will report all sorts of things
about what it is doing such as the names of files and the version of ANTLR and so on.
default-value="true"
*** conversionTimeout
The number of milliseconds ANTLR will wait for analysis of each
alternative in the grammar to complete before giving up. You may raise
this value if ANTLR gives up on a complicated alt and tells you that
there are lots of ambiguties, but you know that it just needed to spend
more time on it. Note that this is an absolute time and not CPU time.
default-value="10000"
*** includes
Provides an explicit list of all the grammars that should
be included in the generate phase of the plugin. Note that the plugin
is smart enough to realize that imported grammars should be included but
not acted upon directly by the ANTLR Tool.
Unless otherwise specified, the include list scans for and includes all
files that end in ".g" in any directory beneath src/main/antlr3. Note that
this version of the plugin looks for the directory antlr3 and not the directory
antlr, so as to avoid clashes and confusion for projects that use both v2 and v3 grammars
such as ANTLR itself.
*** excludes
Provides an explicit list of any grammars that should be excluded from
the generate phase of the plugin. Files listed here will not be sent for
processing by the ANTLR tool.
*** sourceDirectory
Specifies the Antlr directory containing grammar files. For
antlr version 3.x we default this to a directory in the tree
called antlr3 because the antlr directory is occupied by version
2.x grammars.
<<NB>> Take careful note that the default location for antlr grammars
is now <<antlr3>> and NOT <<antlr>>
default-value="<<<${basedir}/src/main/antlr3>>>"
*** outputDirectory
Location for generated Java files. For antlr version 3.x we default
this to a directory in the tree called antlr3 because the antlr
directory is occupied by version 2.x grammars.
default-value="<<<${project.build.directory}/generated-sources/antlr3>>>"
*** libDirectory
Location for imported token files, e.g. <code>.tokens</code> and imported grammars.
Note that ANTLR will not try to process grammars that it finds in this directory, but
will include this directory in the search for .tokens files and import grammars.
<<NB>> If you change the lib directory from the default but the directory is
still under<<<${basedir}/src/main/antlr3>>>, then you will need to exclude
the grammars from processing specifically, using the <<<<excludes>>>> option.
default-value="<<<${basedir}/src/main/antlr3/imports>>>"
Note that you can create multiple executions, and thus build some grammars with
different options to others (such as setting the <<<debug>>> option for
instance).
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment