Grammatica can be run from Apache Ant. In order for Apache to find the Grammatica task, however, a simple task declaration is required. An example of such a task declaration is present in the figure below:
<taskdef name="grammatica" classname="net.percederberg.grammatica.ant.GrammaticaTask" classpath="grammatica-1.4.jar" />
Figure 1.
The Ant task declaration needed to make the
grammatica
task available.
The <grammatica>
task allows the following
attributes:
The grammar processing is defined in one or more subelements,
such as <csharp>
, <java>
,
or <validation>
. At least one such subelement
must be present, but multiple elements are also allowed.
The <csharp>
subelement controls the C#
source code generation. It allows the following attributes:
The <java>
subelement controls the Java
source code generation. It allows the following attributes:
dir
directory.
The <validation>
subelement allows for
different tests and validations of the grammar and/or data files.
It allows the following attributes:
A simple example of how to use the Grammatica Ant task is shown in the figure below.
<grammatica grammar="simple.grammar"> <java dir="src" package="com.test.simple" public="true" /> </grammatica>
Figure 2.
A piece of simple Ant code for using Grammatica create
a Java parser for simple.grammar
.