You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Michael Saunders <mi...@amtec.com> on 2000/05/04 15:40:27 UTC
Taskdefs for JJTree and JavaCC?
To all:
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.
Thanks,
Michael
Re: Taskdefs for JJTree and JavaCC?
Posted by External Lists <ex...@ManagedObjects.com>.
> 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 +
"." );
}
}
}