[antlr-interest] Antlr Ant task question
Felix Dorner
felix_do at web.de
Mon Mar 31 08:12:49 PDT 2008
Hey,
I use the Antlr Ant task to generate grammars. First, thanks for this
great contribution. I have however a small improvement suggestion. As
far as I can see, there is one output dir option for all generated files
("outputdirectory"). This means that all .java and .token files go to
this directory. I'd suggest it would be more flexible, if one could
specify two output directories, one for the .java and another one for
the .tokens files. This arises from the following use case:
I use AntlrWorks to develop my grammars, that are in a directory
"grammars". AntlrWorks expects shared token files in the same directory
as the currently edited grammar. I also specify a package for my grammar
files. Within the Ant task I use the outputdir="src/my/package" option
to make the generated parsers _and_ the .tokens files go to the
corresponding package directory. Without moving back the .tokens file to
the "grammar" dir, AntlrWorks complains about unreferenced tokens. See
below for my ant task setup.
Felix.
<target name="AllureParser" depends="init">
<antlr3 grammar.name="Allure.g" />
<!-- move the generated .tokens file back to the grammar directory
antlr3 ant task should have support to specify different
directories for .token and .java artifacts... -->
<move todir="${src-gen}/${parserpackage}">
<fileset dir="${grammar}">
<include name="**/*.tokens"/>
</fileset>
</move>
</target>
<target name="AllureWalker" depends="AllureParser">
<antlr3 grammar.name="AllureWalker.g" />
</target>
<macrodef name="antlr3">
<attribute name="grammar.name"/>
<attribute name="package" default="${parserpackage}"/>
<sequential>
<echo message="antlr ${grammar}/@{grammar.name}" />
<antlr:antlr3
xmlns:antlr="antlib:org/apache/tools/ant/antlr"
target="${grammar}/@{grammar.name}"
outputdirectory="${src-gen}/${parserpackage}"
libdirectory="${grammar}"/>
</sequential>
</macrodef>
More information about the antlr-interest
mailing list