Package org.antlr.mojo.antlr3
Class Antlr3Mojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.antlr.mojo.antlr3.Antlr3Mojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
public class Antlr3Mojo extends org.apache.maven.plugin.AbstractMojo
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 ...
-
-
Field Summary
Fields Modifier and Type Field Description private int
conversionTimeout
The number of milliseconds ANTLR will wait for analysis of each alternative in the grammar to complete before giving up.protected boolean
debug
If set to true, then the code generated by the ANTLR code generator will be set to debug mode.protected boolean
dfa
If set to true then the ANTLR tool will generate a description of the DFA for each decision in the grammar in Dot formatprotected java.util.Set
excludes
Provides an explicit list of any grammars that should be excluded from the generate phase of the plugin.protected java.util.Set
includes
Provides an explicit list of all the grammars that should be included in the generate phase of the plugin.private java.io.File
libDirectory
Location for imported token files, e.g.private int
maxSwitchCaseLabels
The number of alts, beyond which ANTLR will not generate a switch statement for the DFA.protected java.lang.String
messageFormat
If this parameter is set, it indicates that any warning or error messages returned by ANLTR, shoould be formatted in the specified way.private int
minSwitchAlts
The number of alts, below which ANTLR will not choose to generate a switch statement over an if statement.protected boolean
nfa
If set to true then the ANTLR tool will generate a description of the nfa for each rule in Dot formatprivate java.io.File
outputDirectory
Location for generated Java files.protected boolean
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.protected boolean
profile
If set to true, then then the generated parser will compute and report on profile information at runtime.protected org.apache.maven.project.MavenProject
project
protected boolean
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.private java.io.File
sourceDirectory
Specifies the Antlr directory containing grammar files.protected Tool
tool
An instance of the ANTLR tool buildprotected boolean
trace
If set to true, the generated parser code will log rule entry and exit points to stdout as an aid to debugging.protected boolean
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.
-
Constructor Summary
Constructors Constructor Description Antlr3Mojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addSourceRoot(java.io.File outputDir)
void
execute()
The main entry point for this Mojo, it is responsible for converting ANTLR 3.x grammars into the target language specified by the grammar.private java.lang.String
findSourceSubdir(java.io.File sourceDirectory, java.lang.String grammarFileName)
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.java.util.Set
getIncludesPatterns()
java.io.File
getLibDirectory()
java.io.File
getOutputDirectory()
java.io.File
getSourceDirectory()
private void
processGrammarFiles(java.io.File sourceDirectory, java.io.File outputDirectory)
-
-
-
Field Detail
-
report
protected boolean 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.
-
printGrammar
protected boolean 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.
-
debug
protected boolean 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).
-
profile
protected boolean profile
If set to true, then then the generated parser will compute and report on profile information at runtime.
-
nfa
protected boolean nfa
If set to true then the ANTLR tool will generate a description of the nfa for each rule in Dot format
-
dfa
protected boolean dfa
If set to true then the ANTLR tool will generate a description of the DFA for each decision in the grammar in Dot format
-
trace
protected boolean trace
If set to true, the generated parser code will log rule entry and exit points to stdout as an aid to debugging.
-
messageFormat
protected java.lang.String 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 suports the built-in formats of antlr, gnu and vs2005.
-
verbose
protected boolean 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.
-
conversionTimeout
private int 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.
-
maxSwitchCaseLabels
private int maxSwitchCaseLabels
The number of alts, beyond which ANTLR will not generate a switch statement for the DFA.
-
minSwitchAlts
private int minSwitchAlts
The number of alts, below which ANTLR will not choose to generate a switch statement over an if statement.
-
includes
protected java.util.Set 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
protected java.util.Set 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.
-
project
protected org.apache.maven.project.MavenProject project
-
sourceDirectory
private java.io.File 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.
-
outputDirectory
private java.io.File 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.
-
libDirectory
private java.io.File libDirectory
Location for imported token files, e.g..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).
-
tool
protected Tool tool
An instance of the ANTLR tool build
-
-
Method Detail
-
getSourceDirectory
public java.io.File getSourceDirectory()
-
getOutputDirectory
public java.io.File getOutputDirectory()
-
getLibDirectory
public java.io.File getLibDirectory()
-
addSourceRoot
void addSourceRoot(java.io.File outputDir)
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
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 disvocered such as a missing sourceorg.apache.maven.plugin.MojoFailureException
- When something really bad happesn such as not being able to create the ANTLR Tool
-
processGrammarFiles
private void processGrammarFiles(java.io.File sourceDirectory, java.io.File outputDirectory) throws antlr.TokenStreamException, antlr.RecognitionException, java.io.IOException, org.codehaus.plexus.compiler.util.scan.InclusionScanException
- Parameters:
sourceDirectory
-outputDirectory
-- Throws:
antlr.TokenStreamException
antlr.RecognitionException
java.io.IOException
org.codehaus.plexus.compiler.util.scan.InclusionScanException
-
getIncludesPatterns
public java.util.Set getIncludesPatterns()
-
findSourceSubdir
private java.lang.String findSourceSubdir(java.io.File sourceDirectory, java.lang.String grammarFileName)
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 produce output relative to the base of the output directory and reflect the input organization of the grammar files.- Parameters:
sourceDirectory
- The source directory File objectgrammarFileName
- The full path to the input grammar file- Returns:
- The path to the grammar file relative to the source directory
-
-