JFlex can easily be integrated with the Ant build tool. To use JFlex with Ant, simply copy the lib/jflex-version.jar file to the $ANT_HOME/lib/ directory or explicitly set the path to it in the ant task definition (see example below).
The JFlex Ant Task invokes the JFlex lexical analyzer generator on a grammar file.
To use the JFlex task, the following line must be placed in the Ant build file:
<taskdef classname="jflex.anttask.JFlexTask" name="jflex" />
Or, setting the path to the JFlex jar explicitly:
<taskdef classname="jflex.anttask.JFlexTask" name="jflex" classpath="path-to-jflex.jar" />
The JFlex task requires the file attribute to be set to the source grammar file (*.flex). Unless the target directory is specified with the destdir option, the generated class will be saved to the same directory where the grammar file resides. Like javac, the JFlex task creates subdirectories in destdir according to the generated class package.
This task only invokes JFlex if the grammar file is newer than the generated files.
Attribute | Description | Required | Default |
file="file" | The grammar file to process. | Yes | |
destdir="dir" | The directory to write the generated files to. If not set, the files are written to the directory containing the grammar file. Note that unlike JFlex's "-d" command line option, destdir causes the generated file to be written to {destdir}/{package name}. This behaviour is similar to javac -d dir. | No | |
outdir="dir" | The directory to write the generated files to. If not set, the files are written to the directory containing the grammar file. This options works exactly like JFlex's "-d" command line option, it causes the output file to be written to dir regardless of the package name. | No | |
verbose | Display generation process messages. | No | "off" |
dump | Dump character classes, NFA and DFA tables. | No | "off" |
time or timeStatistics |
Display generation time statistics. | No | "off" |
nomin or skipMinimization |
Skip minimization step. | No | "off" |
skel="file" or skeleton="file" |
Use external skeleton file. | No | "off" |
dot or generateDot |
Write graphviz .dot files for the generated automata (alpha). | No | "off" |
nobak | Do not make a backup if the generated file exists. | No | "off" |
legacydot | Dot (.) metacharacter matches [^\n] instead of [^\n\r\u000B\u000C\u0085\u2028\u2029] | No | "off" |
noinputstreamctor | Don't include an InputStream constructor in the generated scanner | No | "true" |
unusedwarning | Warn about unused macro definitions in the lexer specification. | No | "true" |
<jflex file="src/parser/Parser.flex" destdir="build/generated/" />
JFlex generates the lexical analyzer for src/parser/Parser.flex and saves the result to build/generated/parser/, providing Parser.flex is declared to be in package parser.
<jflex file="src/parser/Parser.flex" destdir="build/generated/" /> <javac srcdir="build/generated/" destdir="build/classes/" />
The same as above plus compile generated classes to build/classes