Browse Source

Documentation for the JavaCC task, changed the location where the

generated file will be placed if no directory has been specified.
Submitted by:	Adam Murdoch <adammurdoch@yahoo.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268046 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
63a3e9609b
3 changed files with 188 additions and 26 deletions
  1. +1
    -0
      docs/index.html
  2. +174
    -0
      docs/javacc.html
  3. +13
    -26
      src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java

+ 1
- 0
docs/index.html View File

@@ -4209,6 +4209,7 @@ it had been located at <code>htdocs/manual/ChangeLog.txt</code>.</p>
<ul>
<li><a href="#cab">Cab</a></li>
<li><a href="#ftp">FTP</a></li>
<li><a href="javacc.html">JavaCC</a></li>
<li><a href="jlink.html">Jlink</a></li>
<li><a href="junit.html">JUnit</a></li>
<li><a href="native2ascii.html">Native2Ascii</a></li>


+ 174
- 0
docs/javacc.html View File

@@ -0,0 +1,174 @@
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>JavaCC Task</title>
</head>

<body>

<h2><a name="javacc">JavaCC</a></h2>
<h3>Description</h3>
<p>
Invokes the <a HREF="http://www.metamata.com/javacc/">JavaCC</a> compiler
compiler on a grammar file.
</p>
<p>
To use the javacc task, set the <i>target</i> attribute to the name of the
grammar file to process. You also need to specify the directory containing
the JavaCC installation using the <i>javacchome</i> attribute, so that ant
can find the JavaCC classes. Optionally, you can also set the
<i>outputdirectory</i> to write the generated file to a specific directory.
Otherwise javacc writes the generated files to the directory containing
the grammar file.
</p>
<p>
This task only invokes JavaCC if the grammar file is newer than the generated
Java files. javacc assumes that the Java class name of the generated parser
is the same as the name of the grammar file, ignoring the .jj.
If this is not the case, the javacc task will still work, but it will always
generate the output files.
</p>

<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">target</td>
<td valign="top">The grammar file to process.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">javacchome</td>
<td valign="top">The directory containing the JavaCC distribution.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">outputdirectory</td>
<td valign="top">
The directory to write the generated files to. If not set, the files
are written to the directory containing the grammar file.
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">buildparser</td>
<td valign="top">Sets the BUILD_PARSER grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">buildtokenmanager</td>
<td valign="top">Sets the BUILD_TOKEN_MANAGER grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">cachetokens</td>
<td valign="top">Sets the CACHE_TOKENS grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">choiceambiguitycheck</td>
<td valign="top">Sets the CHOICE_AMBIGUITY_CHECK grammar option. This is an integer option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">commontokenaction</td>
<td valign="top">Sets the COMMON_TOKEN_ACTION grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debuglookahead</td>
<td valign="top">Sets the DEBUG_LOOKAHEAD grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debugparser</td>
<td valign="top">Sets the DEBUG_PARSER grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debugtokenmanager</td>
<td valign="top">Sets the DEBUG_TOKEN_MANAGER grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">errorreporting</td>
<td valign="top">Sets the ERROR_REPORTING grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">forcelacheck</td>
<td valign="top">Sets the FORCE_LA_CHECK grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">ignorecase</td>
<td valign="top">Sets the IGNORE_CASE grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">javaunicodeescape</td>
<td valign="top">Sets the JAVA_UNICODE_ESCAPE grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">lookahead</td>
<td valign="top">Sets the LOOKAHEAD grammar option. This is an integer option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">optimizetokenmanager</td>
<td valign="top">Sets the OPTIMIZE_TOKEN_MANAGER grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">otherambiguitycheck</td>
<td valign="top">Sets the OTHER_AMBIGUITY_CHECK grammar option. This is an integer option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">sanitycheck</td>
<td valign="top">Sets the SANITY_CHECK grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">static</td>
<td valign="top">Sets the STATIC grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">unicodeinput</td>
<td valign="top">Sets the UNICODE_INPUT grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">usercharstream</td>
<td valign="top">Sets the USER_CHAR_STREAM grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">usertokenmanager</td>
<td valign="top">Sets the USER_TOKEN_MANAGER grammar option. This is a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Example</h3>
<blockquote><pre>
&lt;javacc
target=&quot;src/Parser.jj&quot;
outputdirectory&quot;build/src&quot;
javacchome=&quot;c:/program files/JavaCC&quot;
static=&quot;true&quot;
/&gt;
</pre></blockquote>
<p>
This invokes JavaCC on grammar file src/Parser.jj, writing the generated
files to build/src. The grammar option STATIC is set to true when
invoking JavaCC.
</p>
<hr>


+ 13
- 26
src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java View File

@@ -216,23 +216,25 @@ public class JavaCC extends Task {
cmdl.createArgument().setValue("-"+name+":"+value.toString());
}

// load command line with required attributes
if (outputDirectory != null) {
if (!outputDirectory.isDirectory()) {
throw new BuildException("Outputdir not a directory.");
}
cmdl.createArgument().setValue(
"-OUTPUT_DIRECTORY:"+outputDirectory.getAbsolutePath());
}

// check the target is a file
if (target == null || !target.isFile()) {
throw new BuildException("Invalid target: " + target);
}

// use the directory containing the target as the output directory
if (outputDirectory == null) {
outputDirectory = new File(target.getParent());
}
else if (!outputDirectory.isDirectory()) {
throw new BuildException("Outputdir not a directory.");
}
cmdl.createArgument().setValue(
"-OUTPUT_DIRECTORY:"+outputDirectory.getAbsolutePath());

// determine if the generated java file is up-to-date
final File javaFile = getOutputJavaFile(outputDirectory, target);
if (javaFile.exists() && target.lastModified() < javaFile.lastModified()) {
project.log("Target is already built - skipping (" + target + ")");
log("Target is already built - skipping (" + target + ")", Project.MSG_VERBOSE);
return;
}
cmdl.createArgument().setValue(target.getAbsolutePath());
@@ -248,22 +250,7 @@ public class JavaCC extends Task {
arg.setValue("-mx140M");
arg.setValue("-Dinstall.root="+javaccHome.getAbsolutePath());

final Execute process =
new Execute(new LogStreamHandler(this,
Project.MSG_INFO,
Project.MSG_INFO),
null);
log(cmdl.toString(), Project.MSG_VERBOSE);
process.setCommandline(cmdl.getCommandline());

try {
if (process.execute() != 0) {
throw new BuildException("JavaCC failed.");
}
}
catch (IOException e) {
throw new BuildException("Failed to launch JavaCC: " + e);
}
Execute.runCommand(this, cmdl.getCommandline());
}

/**


Loading…
Cancel
Save