ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jene Jasper <JJAS...@abz.nl>
Subject Patch JavaCC - KEEP_LINE_COLUMN, JJTree - OUTPUT_FILE and new tas kdef JJDoc
Date Wed, 02 Apr 2003 07:40:34 GMT
As mentioned yesterday, I have made some changes to the JavaCC and JJTree
taskdefs 
and added a new taskdef for JJDoc. I have included the patch.txt for the
changes.
But what is the best way to deliver the new files JJDoc.java and jjdoc.html
?
I could mail a zip containing this patch.txt and all files concerning.

Sincerely yours,

Jene.

============================================================================
=======
cvs -q diff -u -r ant_snapshot_20030401 

Index: docs/manual/optionaltasklist.html
===================================================================
RCS file: D:\usr\local\cvsroot/ant/docs/manual/optionaltasklist.html,v
retrieving revision 1.3
diff -u -r1.3 optionaltasklist.html
--- docs/manual/optionaltasklist.html	2003/04/01 17:13:53	1.3
+++ docs/manual/optionaltasklist.html	2003/04/01 17:30:10
@@ -36,6 +36,7 @@
 <a href="OptionalTasks/javah.html">Javah</a><br>
 <a href="OptionalTasks/jspc.html">JspC</a><br>
 <a href="OptionalTasks/jdepend.html">JDepend</a><br>
+<a href="OptionalTasks/jjdoc.html">JJDoc</a><br>
 <a href="OptionalTasks/jjtree.html">JJTree</a><br>
 <a href="OptionalTasks/jlink.html"><i>Jlink</i></a><br>
 <a href="OptionalTasks/jpcoverage.html">JProbe Coverage</a><br>

Index: docs/manual/tasksoverview.html
===================================================================
RCS file: D:\usr\local\cvsroot/ant/docs/manual/tasksoverview.html,v
retrieving revision 1.1
diff -u -r1.1 tasksoverview.html
--- docs/manual/tasksoverview.html	2003/03/01 16:17:31	1.1
+++ docs/manual/tasksoverview.html	2003/04/01 17:13:10
@@ -866,6 +866,16 @@
   </tr>
 
   <tr valign="top">
+    <td nowrap><a href="OptionalTasks/jjdoc.html">JJDoc</a></td>
+    <td><p>Invokes the <a href="http://www.webgain.com/products/java_cc/">
+     JJDoc</a> documentation generator for the JavaCC compiler-compiler. 
+     JJDoc takes a JavaCC parser specification and produces documentation
+     for the BNF grammar.  It can operate in three modes, determined by
+     command line options. This task only invokes JJDoc if the grammar file

+     is newer than the generated BNF grammar documentation.</p></td>
+  </tr>
+
+  <tr valign="top">
     <td nowrap><a href="OptionalTasks/jjtree.html">JJTree</a></td>
     <td><p>Invokes the <a href="http://www.webgain.com/products/java_cc/">
      JJTree</a> preprocessor for the JavaCC compiler-compiler. It inserts

Index: docs/manual/OptionalTasks/javacc.html
===================================================================
RCS file: D:\usr\local\cvsroot/ant/docs/manual/OptionalTasks/javacc.html,v
retrieving revision 1.1
diff -u -r1.1 javacc.html
--- docs/manual/OptionalTasks/javacc.html	2003/03/01 16:17:28	1.1
+++ docs/manual/OptionalTasks/javacc.html	2003/04/01 17:13:38
@@ -116,6 +116,11 @@
     <td valign="top" align="center">No</td>
   </tr>
   <tr>
+    <td valign="top">keeplinecolumn</td>
+    <td valign="top">Sets the KEEP_LINE_COLUMN 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>

cvs diff: tag ant_snapshot_20030401 is not in file
docs/manual/OptionalTasks/jjdoc.html

Index: docs/manual/OptionalTasks/jjtree.html
===================================================================
RCS file: D:\usr\local\cvsroot/ant/docs/manual/OptionalTasks/jjtree.html,v
retrieving revision 1.1
diff -u -r1.1 jjtree.html
--- docs/manual/OptionalTasks/jjtree.html	2003/03/01 16:17:29	1.1
+++ docs/manual/OptionalTasks/jjtree.html	2003/04/01 17:13:50
@@ -17,13 +17,16 @@
 at various places in the JavaCC source that it generates. The output of
 JJTree is run through JavaCC to create the parser.
 <p>To use the jjtree task, set the <i>target</i> attribute to the name
-of the jjtree grammar file to process. You also need to specify the
directory
+of the JJTree 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 jjtree
writes
-the generated JavaCC grammar file to the directory containing the JJTree
-grammar file.</p>
+to write the generated JavaCC grammar and node files to a specific
directory.
+Otherwise jjtree writes the generated JavaCC grammar and node files to the
directory
+containing the JJTree grammar file. As an extra option, you can also set
the
+<i>outputfile</i> to write the generated JavaCC grammar file to a specific
(directory and) file.
+Otherwise jjtree writes the generated JavaCC grammar file as the JJTree
+grammar file with a suffix .jj.</p>
 <p>This task only invokes JJTree if the grammar file is newer than the
 generated JavaCC file.</p>
 
@@ -57,8 +60,17 @@
 <tr>
 <td VALIGN=TOP>outputdirectory</td>
 
-<td VALIGN=TOP>The directory to write the generated file to. If not set,
-the files are written to the directory containing the grammar
file.&nbsp;</td>
+<td VALIGN=TOP>The directory to write the generated JavaCC grammar and node
files to.
+If not set, the files are written to the directory containing the grammar
file.&nbsp;</td>
+
+<td ALIGN=CENTER VALIGN=TOP>No</td>
+</tr>
+
+<tr>
+<td VALIGN=TOP>outputfile</td>
+
+<td VALIGN=TOP>The file to write the generated JavaCC grammar file to. If
not set,
+the file is written with the same name as the JJTree grammar file but with
a the suffix .jj.&nbsp;</td>
 
 <td ALIGN=CENTER VALIGN=TOP>No</td>
 </tr>

Index: src/main/org/apache/tools/ant/taskdefs/defaults.properties
===================================================================
RCS file:
D:\usr\local\cvsroot/ant/src/main/org/apache/tools/ant/taskdefs/defaults.pro
perties,v
retrieving revision 1.5
diff -u -r1.5 defaults.properties
--- src/main/org/apache/tools/ant/taskdefs/defaults.properties	2003/04/01
17:13:54	1.5
+++ src/main/org/apache/tools/ant/taskdefs/defaults.properties	2003/04/01
17:29:42
@@ -102,6 +102,7 @@
 ftp=org.apache.tools.ant.taskdefs.optional.net.FTP
 icontract=org.apache.tools.ant.taskdefs.optional.IContract
 javacc=org.apache.tools.ant.taskdefs.optional.javacc.JavaCC
+jjdoc=org.apache.tools.ant.taskdefs.optional.javacc.JJDoc
 jjtree=org.apache.tools.ant.taskdefs.optional.javacc.JJTree
 stcheckout=org.apache.tools.ant.taskdefs.optional.starteam.StarTeamCheckout
 stcheckin=org.apache.tools.ant.taskdefs.optional.starteam.StarTeamCheckin

cvs diff: tag ant_snapshot_20030401 is not in file
src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java

Index: src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java
===================================================================
RCS file:
D:\usr\local\cvsroot/ant/src/main/org/apache/tools/ant/taskdefs/optional/jav
acc/JJTree.java,v
retrieving revision 1.1
diff -u -r1.1 JJTree.java
--- src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java
2003/03/01 16:17:33	1.1
+++ src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java
2003/04/01 17:13:30
@@ -77,6 +77,7 @@
 public class JJTree extends Task {
 
     // keys to optional attributes
+    private static final String OUTPUT_FILE       = "OUTPUT_FILE";
     private static final String BUILD_NODE_FILES  = "BUILD_NODE_FILES";
     private static final String MULTI             = "MULTI";
     private static final String NODE_DEFAULT_VOID = "NODE_DEFAULT_VOID";
@@ -92,6 +93,10 @@
 
     private final Hashtable optionalAttrs = new Hashtable();
 
+    private String outputFile = null;
+
+    private static final String DEFAULT_SUFFIX = ".jj";
+
     // required attributes
     private File outputDirectory = null;
     private File target          = null;
@@ -178,7 +183,7 @@
     }
 
     /**
-     * The directory to write the generated file to.
+     * The directory to write the generated JavaCC grammar and node files
to.
      * If not set, the files are written to the directory
      * containing the grammar file.
      */
@@ -187,6 +192,15 @@
     }
 
     /**
+     * The outputfile to write the generated JavaCC grammar file to.
+     * If not set, the file is written with the same name as
+     * the JJTree grammar file with a suffix .jj.
+     */
+    public void setOutputfile(String outputFile) {
+        this.outputFile = outputFile;
+    }
+
+    /**
      * The jjtree grammar file to process.
      */
     public void setTarget(File target) {
@@ -217,30 +231,38 @@
 
         if (target == null || !target.isFile()) {
             throw new BuildException("Invalid target: " + target);
+        }
+
+        if (outputFile != null) {
+            cmdl.createArgument().setValue("-" + OUTPUT_FILE + ":" +
outputFile.replace('\\', '/'));
         }
-        
+
+        File javaFile;
+
         // use the directory containing the target as the output directory
         if (outputDirectory == null) {
-            outputDirectory = new File(target.getParent());
-        }        
-        if (!outputDirectory.isDirectory()) {
-            throw new BuildException("'outputdirectory' " + outputDirectory

-                + " is not a directory.");
-        }
-        // convert backslashes to slashes, otherwise jjtree will put this
as
-        // comments and this seems to confuse javacc
-        cmdl.createArgument().setValue("-OUTPUT_DIRECTORY:" 
-            + outputDirectory.getAbsolutePath().replace('\\', '/'));
-        
-        String targetName = target.getName();
-        final File javaFile = new File(outputDirectory,
-            targetName.substring(0, targetName.indexOf(".jjt")) + ".jj");
-        if (javaFile.exists() 
+            javaFile = new File(createOutputFileName(target, outputFile,
null));
+        } else {
+            if (!outputDirectory.isDirectory()) {
+                throw new BuildException("'outputdirectory' " +
outputDirectory
+                    + " is not a directory.");
+            }
+
+            // convert backslashes to slashes, otherwise jjtree will put
this as
+            // comments and this seems to confuse javacc
+            cmdl.createArgument().setValue("-OUTPUT_DIRECTORY:"
+                + outputDirectory.getAbsolutePath().replace('\\', '/'));
+
+            javaFile = new File(createOutputFileName(target, outputFile,
outputDirectory.getPath()));
+        }
+
+        if (javaFile.exists()
              && target.lastModified() < javaFile.lastModified()) {
             log("Target is already built - skipping (" + target + ")",
                 Project.MSG_VERBOSE);
             return;
         }
+
         cmdl.createArgument().setValue(target.getAbsolutePath());
 
         final Path classpath = cmdl.createClasspath(getProject());
@@ -266,6 +288,54 @@
             }
         } catch (IOException e) {
             throw new BuildException("Failed to launch JJTree", e);
+        }
+    }
+
+    private String createOutputFileName(File target, String
optionalOutputFile, String outputDirectory)
+    {
+        String jjtreeFile = target.getAbsolutePath().replace('\\','/');
+
+        if ((optionalOutputFile == null) || optionalOutputFile.equals(""))
+        {
+            int filePos = jjtreeFile.lastIndexOf("/");
+
+            if (filePos >= 0)
+            {
+                jjtreeFile = jjtreeFile.substring(filePos + 1);
+            }
+
+            int suffixPos = jjtreeFile.lastIndexOf('.');
+
+            if (suffixPos == -1)
+            {
+                optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX;
+            }
+            else
+            {
+                String currentSuffix = jjtreeFile.substring(suffixPos);
+
+                if (currentSuffix.equals(DEFAULT_SUFFIX))
+                {
+                    optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX;
+                }
+                else
+                {
+                    optionalOutputFile = jjtreeFile.substring(0, suffixPos)
+ DEFAULT_SUFFIX;
+                }
+            }
+        }
+        else
+        {
+            optionalOutputFile = optionalOutputFile.replace('\\','/');
+        }
+
+        if ((outputDirectory == null) || outputDirectory.equals(""))
+        {
+            return (getProject().getBaseDir() + "/" +
optionalOutputFile).replace('\\', '/');
+        }
+        else
+        {
+            return (outputDirectory + "/" +
optionalOutputFile).replace('\\', '/');
         }
     }
 }

Index: src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
===================================================================
RCS file:
D:\usr\local\cvsroot/ant/src/main/org/apache/tools/ant/taskdefs/optional/jav
acc/JavaCC.java,v
retrieving revision 1.1
diff -u -r1.1 JavaCC.java
--- src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
2003/03/01 16:17:34	1.1
+++ src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
2003/04/01 17:13:34
@@ -96,6 +96,7 @@
     private static final String SANITY_CHECK           = "SANITY_CHECK";
     private static final String FORCE_LA_CHECK         = "FORCE_LA_CHECK";
     private static final String CACHE_TOKENS           = "CACHE_TOKENS";
+    private static final String KEEP_LINE_COLUMN       =
"KEEP_LINE_COLUMN";
 
     private final Hashtable optionalAttrs = new Hashtable();
 
@@ -245,6 +246,13 @@
      */
     public void setCachetokens(boolean cacheTokens) {
         optionalAttrs.put(CACHE_TOKENS, new Boolean(cacheTokens));
+    }
+
+    /**
+     * Sets the KEEP_LINE_COLUMN grammar option.
+     */
+    public void setKeeplinecolumn(boolean keepLineColumn) {
+        optionalAttrs.put(KEEP_LINE_COLUMN, new Boolean(keepLineColumn));
     }
 
     /**

*****CVS exited normally with code 1*****
============================================================================
=======

>I have some patches coming up for JavaCC and JJTree concerning some missing
>parameters and also an enhancement for a JJDoc taskdef (code is finished,
>only cvs -diff left on a nightly snapshot).

>I could look into a patch for version 3.0 added support this coming
weekend.

>Jene Jasper.

On 01 Apr 2003, Tom Copeland <tom@infoether.com> wrote:

>> If possible we should support both (and I think there already is a
>> bugzilla report to that effect, including a patch IIRC).
> 
> I poked around Bugzilla for a bit and couldn't find anything.

I was wrong.  There is one for JDepend, which has similar problems
(changed directory structure in new release).

> Anyhow, sounds like you have this one under control...

Not really. 8-)  A patch that would enable the tasks to work with
either version would be appreciated.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message