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
@Mojo(name="antlr", defaultPhase=GENERATE_SOURCES, requiresDependencyResolution=COMPILE, requiresProject=true, threadSafe=true) public class Antlr3Mojo extends org.apache.maven.plugin.AbstractMojoParses ANTLR grammar files*.gand transforms them into Java source files.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandebugIf set to true, then the code generated by the ANTLR code generator will be set to debug mode.protected booleandfaIf set to true, then the ANTLR tool will generate a description of the DFA for each decision in the grammar in Dot format.protected java.util.Set<java.lang.String>excludesA set of Ant-like exclusion patterns used to prevent certain files from being processed.protected java.util.Set<java.lang.String>includesProvides an explicit list of all the grammars that should be included in the generate phase of the plugin.private java.io.FilelibDirectoryLocation for imported token files, e.g.private intmaxSwitchCaseLabelsThe maximum number of alternatives allowed in an inline switch statement.protected java.lang.StringmessageFormatIf this parameter is set, it indicates that any warning or error messages returned by ANLTR, should be formatted in the specified way.private intminSwitchAltsThe minimum number of alternatives for ANTLR to generate a switch statement.protected booleannfaIf set to true, then the ANTLR tool will generate a description of the NFA for each rule in Dot formatprivate java.io.FileoutputDirectoryThe directory where the parser files generated by ANTLR will be stored.protected booleanprintGrammarIf set to true, then the ANTLR tool will print a version of the input grammar(s) which are stripped of any embedded actions.protected booleanprofileIf set to true, then the generated parser will compute and report profile information at runtime.protected org.apache.maven.project.MavenProjectprojectThe current Maven project.protected booleanreportIf set to true, then after the tool has processed an input grammar file it will report various statistics about the parser, such as information on cyclic DFAs, which rules may use backtracking, and so on.private java.io.FilesourceDirectoryThe directory where the ANTLR grammar files (*.g) are located.protected TooltoolAn instance of the ANTLR tool build.protected booleantraceIf set to true, the generated parser code will log rule entry and exit points to stdout (System.outfor the Java target) as an aid to debugging.protected booleanverboseIf set to true, then ANTLR will report verbose messages during the code generation process.
-
Constructor Summary
Constructors Constructor Description Antlr3Mojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddSourceRoot(java.io.File outputDir)voidexecute()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.StringfindSourceSubdir(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 thesourceDirectory.java.util.Set<java.lang.String>getIncludesPatterns()java.io.FilegetLibDirectory()java.io.FilegetOutputDirectory()java.io.FilegetSourceDirectory()private voidprocessGrammarFiles(java.io.File sourceDirectory, java.io.File outputDirectory)
-
-
-
Field Detail
-
report
@Parameter(property="report", defaultValue="false") protected boolean reportIf set to true, then after the tool has processed an input grammar file it will report various statistics about the parser, such as information on cyclic DFAs, which rules may use backtracking, and so on.
-
printGrammar
@Parameter(property="printGrammar", defaultValue="false") protected boolean printGrammarIf set to true, then the ANTLR tool will print a version of the input grammar(s) which are stripped of any embedded actions.
-
debug
@Parameter(property="debug", defaultValue="false") protected boolean debugIf 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
@Parameter(property="profile", defaultValue="false") protected boolean profileIf set to true, then the generated parser will compute and report profile information at runtime.
-
nfa
@Parameter(property="nfa", defaultValue="false") protected boolean nfaIf set to true, then the ANTLR tool will generate a description of the NFA for each rule in Dot format
-
dfa
@Parameter(property="dfa", defaultValue="false") protected boolean dfaIf set to true, then the ANTLR tool will generate a description of the DFA for each decision in the grammar in Dot format.
-
trace
@Parameter(property="trace", defaultValue="false") protected boolean traceIf set to true, the generated parser code will log rule entry and exit points to stdout (System.outfor the Java target) as an aid to debugging.
-
messageFormat
@Parameter(property="messageFormat", defaultValue="antlr") protected java.lang.String messageFormatIf 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 formatsantlr,gnuandvs2005.
-
verbose
@Parameter(property="verbose", defaultValue="true") protected boolean verboseIf 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.
-
maxSwitchCaseLabels
@Parameter(property="maxSwitchCaseLabels", defaultValue="300") private int maxSwitchCaseLabelsThe maximum number of alternatives allowed in an inline switch statement. Beyond this, ANTLR will not generate a switch statement for the DFA.
-
minSwitchAlts
@Parameter(property="minSwitchAlts", defaultValue="3") private int minSwitchAltsThe 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.
-
includes
@Parameter protected java.util.Set<java.lang.String> 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.A set of Ant-like inclusion patterns used to select files from the source directory for processing. By default, the pattern
**/*.gis used to select grammar files.
-
excludes
@Parameter protected java.util.Set<java.lang.String> excludes
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.
-
project
@Parameter(property="project", required=true, readonly=true) protected org.apache.maven.project.MavenProject projectThe current Maven project.
-
sourceDirectory
@Parameter(defaultValue="${basedir}/src/main/antlr3") private java.io.File sourceDirectoryThe directory where the ANTLR grammar files (*.g) are located.
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-sources/antlr3", required=true) private java.io.File outputDirectoryThe 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.
-
libDirectory
@Parameter(defaultValue="${basedir}/src/main/antlr3/imports") private java.io.File libDirectoryLocation for imported token files, e.g.*.tokensand 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.MojoFailureExceptionThe 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- if a configuration or grammar error causes the code generation process to failorg.apache.maven.plugin.MojoFailureException- if an instance of the ANTLR 3Toolcannot be created
-
processGrammarFiles
private void processGrammarFiles(java.io.File sourceDirectory, java.io.File outputDirectory) throws java.io.IOException, org.codehaus.plexus.compiler.util.scan.InclusionScanException- Parameters:
sourceDirectory-outputDirectory-- Throws:
java.io.IOExceptionorg.codehaus.plexus.compiler.util.scan.InclusionScanException
-
getIncludesPatterns
public java.util.Set<java.lang.String> 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 thesourceDirectory. 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 directoryFileobjectgrammarFileName- The full path to the input grammar file- Returns:
- The path to the grammar file relative to the source directory
-
-