Ant task for Antlr3.2

org.apache.tools.ant.antlr
Class ANTLR3

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.antlr.ANTLR3
All Implemented Interfaces:
java.lang.Cloneable

public class ANTLR3
extends org.apache.tools.ant.Task

Invokes the ANTLR3 Translator generator on a grammar file.


Field Summary
private  java.io.ByteArrayOutputStream bos
          captures ANTLR's output
private  org.apache.tools.ant.types.CommandlineJava commandline
           
private  java.lang.String conversiontimeout
          Whether to override the default conversion timeout with -Xconversiontimeout nnnn
private  boolean dbgST
          put tags at start/stop of all templates in output
private  boolean debug
          The debug attribute
private  boolean depend
          depend
private  boolean dfa
          The dfa attribute
private  boolean diagnostic
          optional flag to print out a diagnostic file
private  org.apache.tools.ant.util.FileUtils fileUtils
          Instance of a utility class to use for file operations.
private  boolean fork
          fork
private  boolean grammarTree
          print AST
private  java.io.File libDirectory
          location of token files
private  boolean make
          The make attribute
private  java.lang.String maxinlinedfastates
          Set limit to max DFA states before table used rather than inlining with -Xmaxinlinedfastates m
private  java.lang.String messageFormatName
          name of output style for messages
private  boolean multiThreaded
          multi threaded analysis
private  boolean nfa
          The nfa attribute
private  boolean nocollapse
          collapse incident edges into DFA states
private  boolean noMergeStopStates
          do not merge stop states
private  boolean noprune
          test lookahead against EBNF block exit branches
private  java.io.File outputDirectory
          where to output the result
private  boolean print
          The print attribute
private  boolean profile
          The profile attribute
private  boolean report
          The report attribute
private  java.io.File superGrammar
          an optional super grammar file
private  java.io.File target
          the file to process
private  boolean trace
          optional flag to add methods
private  boolean traceLexer
          optional flag to add trace methods to the lexer only
private  boolean traceParser
          optional flag to add trace methods to the parser only
private  boolean verbose
          The verbose attribute
private  java.io.File workingdir
          working directory
 
Fields inherited from class org.apache.tools.ant.Task
taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
ANTLR3()
           
 
Method Summary
private  boolean addAntlrJarsToClasspath(java.lang.String antlrLibDir, java.lang.String envVariable)
          If the environment variable ANTLR_LIBDIR or ANTLR_HOME is defined and points to the installation directory of antlr3 then look for all antlr-*.jar and stringtemplate-*.jar files in the lib directory and add them to the classpath.
protected  void addClasspathEntry(java.lang.String resource, java.lang.String msg)
          Search for the given resource and add the directory or archive that contains it to the classpath.
 org.apache.tools.ant.types.Path createClasspath()
          Adds a classpath to be set because a directory might be given for Antlr debug.
 org.apache.tools.ant.types.Commandline.Argument createJvmarg()
          Adds a new JVM argument.
private  boolean dependencyCheck()
           
 void execute()
           
 java.io.File getOutputdirectory()
          The directory to write the generated files to.
 void init()
          Adds the jars or directories containing Antlr and associates.
private  void populateAttributes()
          A refactored method for populating all the command line arguments based on the user-specified attributes.
private  int run(java.lang.String[] command, java.io.OutputStream out, java.io.OutputStream err)
          execute in a forked VM
 void setConversiontimeout(java.lang.String conversiontimeoutString)
          Deprecated.  
 void setDbgST(boolean enable)
          test lookahead against EBNF block exit branches
 void setDebug(boolean enable)
          Sets a flag to enable ParseView debugging
 void setDepend(boolean s)
          Deprecated.  
 void setDfa(boolean enable)
          Sets a flag to enable nfa generation
 void setDiagnostic(boolean enable)
          Deprecated.  
 void setDir(java.io.File d)
          The working directory of the process
 void setFork(boolean s)
           
 void setGlib(java.io.File superGrammarFile)
          Deprecated.  
 void setGrammartree(boolean enable)
          Set a flag to enable printing of the grammar tree
 void setLibdirectory(java.io.File libDirectoryFile)
          The token files output directory.
 void setMake(boolean enable)
          Sets a flag to enable build only if generated files older than grammar
 void setMaxInlineDFAStates(java.lang.String maxinlinedfastatesString)
          override the default limit before table used rather han inlining with -Xmaxinlinedfastates m
 void setMessageformat(java.lang.String name)
          The output style for messages.
 void setMultithreaded(boolean enable)
          Run the analysis multithreaded
 void setNfa(boolean enable)
          Sets a flag to enable nfa generation
 void setNocollapse(boolean enable)
          collapse incident edges into DFA states
 void setNoMergeStopStates(boolean enable)
          do not merge stop states
 void setNoprune(boolean enable)
          test lookahead against EBNF block exit branches
 void setOutputdirectory(java.io.File outputDirectoryFile)
          The directory to write the generated files to.
 void setPrint(boolean enable)
          Sets a flag to print out the grammar without actions
 void setProfile(boolean enable)
          Sets a flag to enable profiling
 void setReport(boolean enable)
          Sets a flag to enable report statistics
 void setTarget(java.io.File targetFile)
          The grammar file to process.
 void setTrace(boolean enable)
          If true, generate a recognizer that traces rule entry/exit.
 void setTraceLexer(boolean enable)
          Deprecated.  
 void setTraceParser(boolean enable)
          Deprecated.  
 void setVerbose(boolean enable)
          Sets a flag to enable verbose mode
private  java.lang.String[] splitRightHandSide(java.lang.String fileNames, java.lang.String pattern)
           
private  void validateAttributes()
           
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandline

private org.apache.tools.ant.types.CommandlineJava commandline

target

private java.io.File target
the file to process


outputDirectory

private java.io.File outputDirectory
where to output the result


libDirectory

private java.io.File libDirectory
location of token files


superGrammar

private java.io.File superGrammar
an optional super grammar file


depend

private boolean depend
depend


fork

private boolean fork
fork


messageFormatName

private java.lang.String messageFormatName
name of output style for messages


diagnostic

private boolean diagnostic
optional flag to print out a diagnostic file


trace

private boolean trace
optional flag to add methods


traceParser

private boolean traceParser
optional flag to add trace methods to the parser only


traceLexer

private boolean traceLexer
optional flag to add trace methods to the lexer only


workingdir

private java.io.File workingdir
working directory


bos

private java.io.ByteArrayOutputStream bos
captures ANTLR's output


debug

private boolean debug
The debug attribute


verbose

private boolean verbose
The verbose attribute


report

private boolean report
The report attribute


print

private boolean print
The print attribute


profile

private boolean profile
The profile attribute


nfa

private boolean nfa
The nfa attribute


dfa

private boolean dfa
The dfa attribute


make

private boolean make
The make attribute


multiThreaded

private boolean multiThreaded
multi threaded analysis


noMergeStopStates

private boolean noMergeStopStates
do not merge stop states


nocollapse

private boolean nocollapse
collapse incident edges into DFA states


noprune

private boolean noprune
test lookahead against EBNF block exit branches


dbgST

private boolean dbgST
put tags at start/stop of all templates in output


grammarTree

private boolean grammarTree
print AST


fileUtils

private org.apache.tools.ant.util.FileUtils fileUtils
Instance of a utility class to use for file operations.


conversiontimeout

private java.lang.String conversiontimeout
Whether to override the default conversion timeout with -Xconversiontimeout nnnn


maxinlinedfastates

private java.lang.String maxinlinedfastates
Set limit to max DFA states before table used rather than inlining with -Xmaxinlinedfastates m

Constructor Detail

ANTLR3

public ANTLR3()
Method Detail

setTarget

public void setTarget(java.io.File targetFile)
The grammar file to process.


setOutputdirectory

public void setOutputdirectory(java.io.File outputDirectoryFile)
The directory to write the generated files to.


getOutputdirectory

public java.io.File getOutputdirectory()
The directory to write the generated files to.

Returns:
output directory

setLibdirectory

public void setLibdirectory(java.io.File libDirectoryFile)
The token files output directory.


setMessageformat

public void setMessageformat(java.lang.String name)
The output style for messages.


setGlib

public void setGlib(java.io.File superGrammarFile)
Deprecated. 

Sets an optional super grammar file


setDebug

public void setDebug(boolean enable)
Sets a flag to enable ParseView debugging


setVerbose

public void setVerbose(boolean enable)
Sets a flag to enable verbose mode


setReport

public void setReport(boolean enable)
Sets a flag to enable report statistics


setPrint

public void setPrint(boolean enable)
Sets a flag to print out the grammar without actions


setProfile

public void setProfile(boolean enable)
Sets a flag to enable profiling


setNfa

public void setNfa(boolean enable)
Sets a flag to enable nfa generation


setDfa

public void setDfa(boolean enable)
Sets a flag to enable nfa generation


setMake

public void setMake(boolean enable)
Sets a flag to enable build only if generated files older than grammar


setMultithreaded

public void setMultithreaded(boolean enable)
Run the analysis multithreaded

Parameters:
enable -

setNoMergeStopStates

public void setNoMergeStopStates(boolean enable)
do not merge stop states

Parameters:
enable -

setNocollapse

public void setNocollapse(boolean enable)
collapse incident edges into DFA states

Parameters:
enable -

setNoprune

public void setNoprune(boolean enable)
test lookahead against EBNF block exit branches

Parameters:
enable -

setDbgST

public void setDbgST(boolean enable)
test lookahead against EBNF block exit branches

Parameters:
enable -

setConversiontimeout

public void setConversiontimeout(java.lang.String conversiontimeoutString)
Deprecated. 

override the default conversion timeout with -Xconversiontimeout nnnn

Parameters:
conversiontimeoutString -

setMaxInlineDFAStates

public void setMaxInlineDFAStates(java.lang.String maxinlinedfastatesString)
override the default limit before table used rather han inlining with -Xmaxinlinedfastates m

Parameters:
maxinlinedfastatesString -

setGrammartree

public void setGrammartree(boolean enable)
Set a flag to enable printing of the grammar tree


setDepend

public void setDepend(boolean s)
Deprecated. 

Set a flag to enable dependency checking by ANTLR itself The depend option is always used implicitely inside the antlr3 task


setDiagnostic

public void setDiagnostic(boolean enable)
Deprecated. 

Sets a flag to emit diagnostic text


setTrace

public void setTrace(boolean enable)
If true, generate a recognizer that traces rule entry/exit.


setTraceParser

public void setTraceParser(boolean enable)
Deprecated. 

If true, enables parser tracing.


setTraceLexer

public void setTraceLexer(boolean enable)
Deprecated. 

If true, enables lexer tracing.


setFork

public void setFork(boolean s)

setDir

public void setDir(java.io.File d)
The working directory of the process


createClasspath

public org.apache.tools.ant.types.Path createClasspath()
Adds a classpath to be set because a directory might be given for Antlr debug.


createJvmarg

public org.apache.tools.ant.types.Commandline.Argument createJvmarg()
Adds a new JVM argument.

Returns:
create a new JVM argument so that any argument can be passed to the JVM.
See Also:
setFork(boolean)

init

public void init()
          throws org.apache.tools.ant.BuildException
Adds the jars or directories containing Antlr and associates. This should make the forked JVM work without having to specify it directly.

Overrides:
init in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException

addClasspathEntry

protected void addClasspathEntry(java.lang.String resource,
                                 java.lang.String msg)
Search for the given resource and add the directory or archive that contains it to the classpath.

Doesn't work for archives in JDK 1.1 as the URL returned by getResource doesn't contain the name of the archive.


addAntlrJarsToClasspath

private boolean addAntlrJarsToClasspath(java.lang.String antlrLibDir,
                                        java.lang.String envVariable)
If the environment variable ANTLR_LIBDIR or ANTLR_HOME is defined and points to the installation directory of antlr3 then look for all antlr-*.jar and stringtemplate-*.jar files in the lib directory and add them to the classpath. This feature should make working with eclipse or netbeans projects a little bit easier. As wildcards are being used for the version part of the jar-archives it makes the task independent of new releases. Just let ANTLR_LIBDIR or ANTLR_HOME point to the new installation directory.


execute

public void execute()
             throws org.apache.tools.ant.BuildException
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException

populateAttributes

private void populateAttributes()
A refactored method for populating all the command line arguments based on the user-specified attributes.


validateAttributes

private void validateAttributes()
                         throws org.apache.tools.ant.BuildException
Throws:
org.apache.tools.ant.BuildException

dependencyCheck

private boolean dependencyCheck()
                         throws org.apache.tools.ant.BuildException
Throws:
org.apache.tools.ant.BuildException

splitRightHandSide

private java.lang.String[] splitRightHandSide(java.lang.String fileNames,
                                              java.lang.String pattern)

run

private int run(java.lang.String[] command,
                java.io.OutputStream out,
                java.io.OutputStream err)
         throws java.io.IOException
execute in a forked VM

Throws:
java.io.IOException

Ant task for Antlr3.2