ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "External Lists" <external-li...@ManagedObjects.com>
Subject Re: Taskdefs for JJTree and JavaCC?
Date Fri, 05 May 2000 17:07:05 GMT
> Has anyone made task definitions for jjtree and javacc? I use these tools
all
> the time and would rather not use exec if someone has already made a full
> fledged taskdef for each.

Just one for javacc.  Feel free to improve on it.

File taskdefs/JavaCC.java:

package taskdefs;

import COM.sun.labs.javacc.*;
import org.apache.tools.ant.*;
import java.io.*;
import java.util.StringTokenizer;

public class JavaCC extends Task {

    private File srcFile;
    private String [] options = new String[0];

    public void setSrc( String fileName ) {
        srcFile = project.resolveFile( fileName );
    }

    public void setOptions( String _options ) {

       StringTokenizer st = new StringTokenizer( _options, "," );

       options = new String[ st.countTokens() ];
       for (int i = 0; st.hasMoreTokens(); i++)
         options[i] = st.nextToken();
    }

   public void execute() throws BuildException {

      try {
         Options.JavaCCInit();

         for (int i = 0; i < options.length; i++)
            Options.setCmdLineOption( options[i] );

         JavaCCParser parser = new JavaCCParser( new
FileReader( srcFile ) );

         System.out.println("Generating parser for: " + srcFile );
         JavaCCGlobals.fileName = JavaCCGlobals.origFileName =
srcFile.toString();
         JavaCCGlobals.jjtreeGenerated =
JavaCCGlobals.isGeneratedBy("JJTree", srcFile.toString());
         JavaCCGlobals.jjcovGenerated = JavaCCGlobals.isGeneratedBy("JJCov",
srcFile.toString());
         JavaCCGlobals.toolNames =
JavaCCGlobals.getToolNames(srcFile.toString());
         parser.javacc_input();
         JavaCCGlobals.setOutputDir(); // Set the output directory
         Semanticize.start();
         ParseGen.start();
         LexGen.start();
         OtherFilesGen.start();

         if ((JavaCCErrors.get_error_count() == 0) &&
(Options.B("BUILD_PARSER") || Options.B("BUILD_TOKEN_MANAGER"))) {
            if (JavaCCErrors.get_warning_count() > 0) {
               System.out.println("Parser generated with 0 errors and "
                                  + JavaCCErrors.get_warning_count() + "
warnings.");
            }
            // System.exit(0);
         }
         else {
            String msg = "Detected " + JavaCCErrors.get_error_count() + "
errors and "
                               + JavaCCErrors.get_warning_count() + "
warnings.";
            throw new BuildException( msg );
         }
      }
      catch (MetaParseException e) {
         String msg = "Detected " + JavaCCErrors.get_error_count() + "
errors and "
                            + JavaCCErrors.get_warning_count() + "
warnings.";
         throw new BuildException( msg );
      }
      catch (ParseException e) {
         String msg = "Detected " + (JavaCCErrors.get_error_count()+1) + "
errors and "
                            + JavaCCErrors.get_warning_count() + "
warnings.";
         throw new BuildException( msg );
      }
      catch (FileNotFoundException e) {
         throw new BuildException( "Unable to open source file " + srcFile +
"." );
      }
   }
}



Mime
View raw message