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
Parses ANTLR grammar files
*.g
and transforms them into Java source
files.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
If set to true, then the code generated by the ANTLR code generator will be set to debug mode.protected boolean
If set to true, then the ANTLR tool will generate a description of the DFA for each decision in the grammar in Dot format.A set of Ant-like exclusion patterns used to prevent certain files from being processed.Provides an explicit list of all the grammars that should be included in the generate phase of the plugin.private File
Location for imported token files, e.g.private int
The maximum number of alternatives allowed in an inline switch statement.protected String
If this parameter is set, it indicates that any warning or error messages returned by ANLTR, should be formatted in the specified way.private int
The minimum number of alternatives for ANTLR to generate a switch statement.protected boolean
If set to true, then the ANTLR tool will generate a description of the NFA for each rule in Dot formatprivate File
The directory where the parser files generated by ANTLR will be stored.protected boolean
If set to true, then the ANTLR tool will print a version of the input grammar(s) which are stripped of any embedded actions.protected boolean
If set to true, then the generated parser will compute and report profile information at runtime.protected org.apache.maven.project.MavenProject
The current Maven project.protected boolean
If 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 File
The directory where the ANTLR grammar files (*.g
) are located.protected Tool
An instance of the ANTLR tool build.protected boolean
If set to true, the generated parser code will log rule entry and exit points to stdout (System.out
for the Java target) as an aid to debugging.protected boolean
If set to true, then ANTLR will report verbose messages during the code generation process.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
addSourceRoot
(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 String
findSourceSubdir
(File sourceDirectory, 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
.private void
processGrammarFiles
(File sourceDirectory, File outputDirectory) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
report
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
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
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
protected boolean profileIf set to true, then the generated parser will compute and report profile information at runtime. -
nfa
protected boolean nfaIf set to true, then the ANTLR tool will generate a description of the NFA for each rule in Dot format -
dfa
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
protected boolean traceIf set to true, the generated parser code will log rule entry and exit points to stdout (System.out
for the Java target) as an aid to debugging. -
messageFormat
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 formatsantlr
,gnu
andvs2005
. -
verbose
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
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
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
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
**/*.g
is used to select grammar files. -
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
protected org.apache.maven.project.MavenProject projectThe current Maven project. -
sourceDirectory
The directory where the ANTLR grammar files (*.g
) are located. -
outputDirectory
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. -
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
An instance of the ANTLR tool build.
-
-
Constructor Details
-
Antlr3Mojo
public Antlr3Mojo()
-
-
Method Details
-
getSourceDirectory
-
getOutputDirectory
-
getLibDirectory
-
addSourceRoot
-
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 3Tool
cannot be created
-
processGrammarFiles
private void processGrammarFiles(File sourceDirectory, File outputDirectory) throws IOException, org.codehaus.plexus.compiler.util.scan.InclusionScanException - Parameters:
sourceDirectory
-outputDirectory
-- Throws:
IOException
org.codehaus.plexus.compiler.util.scan.InclusionScanException
-
getIncludesPatterns
-
findSourceSubdir
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 directoryFile
objectgrammarFileName
- The full path to the input grammar file- Returns:
- The path to the grammar file relative to the source directory
-