update everything for new match() syntax

This commit is contained in:
benfry
2008-09-20 19:56:31 +00:00
parent 8994141bf7
commit 4421510476
6 changed files with 74 additions and 57 deletions
+45 -18
View File
@@ -34,8 +34,9 @@ import processing.app.debug.RunnerException;
public class Commander {
static final String helpArg = "--help";
static final String buildArg = "--build";
static final String preprocArg = "--preprocess";
static final String buildArg = "--build";
static final String runArg = "--run";
static final String sketchArg = "--sketch=";
static final String outputArg = "--output=";
static final String exportAppletArg = "--export-applet";
@@ -46,8 +47,9 @@ public class Commander {
static final int HELP = -1;
static final int PREPROCESS = 0;
static final int BUILD = 1;
static final int EXPORT_APPLET = 2;
static final int EXPORT_APPLICATION = 3;
static final int RUN = 2;
static final int EXPORT_APPLET = 3;
static final int EXPORT_APPLICATION = 4;
static public void main(String[] args) {
@@ -63,7 +65,8 @@ public class Commander {
public Commander(String[] args) {
String sketchPath = null;
String sketchFolder = null;
String pdePath = null; // path to the .pde file
String outputPath = null;
String preferencesPath = null;
int platformIndex = PApplet.platform; // default to this platform
@@ -91,15 +94,24 @@ public class Commander {
if (platformIndex == -1) {
complainAndQuit(platformStr + " should instead be " +
"'windows', 'macosx', or 'linux'.");
}
}
} else if (arg.startsWith(sketchArg)) {
sketchPath = arg.substring(sketchArg.length());
sketchFolder = arg.substring(sketchArg.length());
File sketchy = new File(sketchFolder);
File pdeFile = new File(sketchy, sketchy.getName() + ".pde");
pdePath = pdeFile.getAbsolutePath();
} else if (arg.startsWith(outputArg)) {
outputPath = arg.substring(outputArg.length());
}
}
if ((outputPath == null) &&
(mode == PREPROCESS || mode == BUILD || mode == RUN)) {
complainAndQuit("Output path must be specified when using " +
preprocArg + ", " + buildArg + ", or " + runArg + ".");
}
// run static initialization that grabs all the prefs
// (also pass in a prefs path if that was specified)
Preferences.init(preferencesPath);
@@ -108,13 +120,13 @@ public class Commander {
printCommandLine(System.out);
System.exit(0);
} else if (sketchPath == null) {
} else if (sketchFolder == null) {
complainAndQuit("No sketch path specified.");
} else if (outputPath.equals(sketchPath)) {
} else if (outputPath.equals(pdePath)) {
complainAndQuit("The sketch path and output path cannot be identical.");
} else if (!sketchPath.toLowerCase().endsWith(".pde")) {
} else if (!pdePath.toLowerCase().endsWith(".pde")) {
complainAndQuit("Sketch path must point to the main .pde file.");
} else {
@@ -122,7 +134,7 @@ public class Commander {
boolean success = false;
try {
sketch = new Sketch(null, sketchPath);
sketch = new Sketch(null, pdePath);
if (mode == PREPROCESS) {
success = sketch.preprocess(outputPath) != null;
@@ -133,18 +145,18 @@ public class Commander {
if (outputPath != null) {
success = sketch.exportApplet(outputPath);
} else {
String sketchFolder =
sketchPath.substring(0, sketchPath.lastIndexOf(File.separatorChar));
success = sketch.exportApplet(sketchFolder + "applet");
String target = sketchFolder + File.separatorChar + "applet";
success = sketch.exportApplet(target);
}
} else if (mode == EXPORT_APPLICATION) {
if (outputPath != null) {
success = sketch.exportApplication(outputPath, platformIndex);
} else {
String sketchFolder =
sketchPath.substring(0, sketchPath.lastIndexOf(File.separatorChar));
//String sketchFolder =
// pdePath.substring(0, pdePath.lastIndexOf(File.separatorChar));
outputPath =
sketchFolder + "application." + Base.getPlatformName(platformIndex);
sketchFolder + File.separatorChar +
"application." + Base.getPlatformName(platformIndex);
success = sketch.exportApplication(outputPath, platformIndex);
}
}
@@ -177,8 +189,23 @@ public class Commander {
static void printCommandLine(PrintStream out) {
out.println("Processing rocks the console.");
out.println("Processing " + Base.VERSION_NAME + " rocks the console.");
out.println();
// out.println("./processing )
out.println("--help Show this help text.");
out.println();
out.println("--sketch=<name> Specify the sketch folder (required)");
out.println("--output=<name> Specify the output folder (required and");
out.println(" cannot be the same as the sketch folder.)");
out.println();
out.println("--run Preprocess, compile, and run a sketch.");
out.println("--build Preprocess and compile a sketch into .class files.");
out.println("--preprocess Preprocess a sketch into .java files.");
out.println();
out.println("--export-applet Export an applet.");
out.println("--export-application Export an application.");
out.println("--platform Specify the platform (export to application only).");
out.println(" Should be one of 'windows', 'macosx', or 'linux'.");
out.println();
out.println("--preferences=<file> Specify a preferences file to use (optional).");
}
}
+6 -6
View File
@@ -118,7 +118,7 @@ public class Sketch {
//Base.addBuildFolderToClassPath();
folder = new File(new File(path).getParent());
//System.out.println("sketch dir is " + folder);
System.out.println("sketch dir is " + folder);
load();
}
@@ -1360,8 +1360,8 @@ public class Sketch {
String[] matches = PApplet.match(tsre.toString(), mess);
if (matches != null) {
int errorLine = Integer.parseInt(matches[0]) - 1;
int errorColumn = Integer.parseInt(matches[1]);
int errorLine = Integer.parseInt(matches[1]) - 1;
int errorColumn = Integer.parseInt(matches[2]);
int errorFile = 0;
for (int i = 1; i < codeCount; i++) {
@@ -1526,11 +1526,11 @@ public class Sketch {
if (matches != null) {
try {
wide = Integer.parseInt(matches[0]);
high = Integer.parseInt(matches[1]);
wide = Integer.parseInt(matches[1]);
high = Integer.parseInt(matches[2]);
// Adding back the trim() for 0136 to handle Bug #769
if (matches.length == 3) renderer = matches[2].trim();
if (matches.length == 4) renderer = matches[3].trim();
} catch (NumberFormatException e) {
// found a reference to size, but it didn't
+6 -13
View File
@@ -143,19 +143,12 @@ public class Compiler {
break;
}
// pieces[2] will contain "error" or "warning" (others?)
// (but all warnings currently suppressed.)
// if (pieces[2].equals("warning")) {
// System.out.println("nah, nevermind: " + pieces[3]);
// continue;
// }
// translate the java filename and line number into a un-preprocessed
// location inside a source file or tab in the environment.
String dotJavaFilename = pieces[0];
String dotJavaFilename = pieces[1];
// Line numbers are 1-indexed from javac
int dotJavaLineIndex = PApplet.parseInt(pieces[1]) - 1;
String errorMessage = pieces[3];
int dotJavaLineIndex = PApplet.parseInt(pieces[2]) - 1;
String errorMessage = pieces[4];
int codeIndex = 0; //-1;
int codeLine = -1;
@@ -273,11 +266,11 @@ public class Compiler {
"The method (\\S+\\(.*\\)) is undefined for the type (.*)";
parts = PApplet.match(errorMessage, undefined);
if (parts != null) {
if (parts[0].equals("framerate(int)") ||
parts[0].equals("push()")) {
if (parts[1].equals("framerate(int)") ||
parts[1].equals("push()")) {
handleCrustyCode(exception);
} else {
String mess = "The function " + parts[0] + " does not exist.";
String mess = "The function " + parts[1] + " does not exist.";
exception.setMessage(mess);
}
break;
@@ -240,26 +240,18 @@ public class PdePreprocessor {
String prefsLine = Preferences.get("preproc.imports");
defaultImports = PApplet.splitTokens(prefsLine, ", ");
// if this guy has his own imports, need to remove them
// just in case it's not an advanced mode sketch
// TODO not sure why [\\s\\A^] won't work for me, but if someone is a Java
// regexp guru, please fill me in. In the interim, using a hack by adding
// a space to the beginning of 'program' so that the matcher works.
//String importRegexp = "[\\s\\A](import\\s+)(\\S+)(\\s*;)";
//String importRegexp = "[\\s^](import\\s+)(\\S+)(\\s*;)";
String importRegexp = "\\s(import\\s+)(\\S+)(\\s*;)";
//java.util.Vector imports = new java.util.Vector();
String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)";
programImports = new ArrayList<String>();
do {
String[] pieces = PApplet.match(" " + program, importRegexp);
String[] pieces = PApplet.match(program, importRegexp);
// Stop the loop if we've removed all the importy lines
if (pieces == null) break;
String piece = pieces[0] + pieces[1] + pieces[2];
String piece = pieces[1] + pieces[2] + pieces[3];
int len = piece.length(); // how much to trim out
programImports.add(pieces[1]); // the package name
programImports.add(pieces[2]); // the package name
int idx = program.indexOf(piece);
// just remove altogether?
program = program.substring(0, idx) + program.substring(idx + len);
+8 -8
View File
@@ -102,26 +102,26 @@ public class BaseObject extends PShape {
return PApplet.parseFloat(PApplet.splitTokens(content.trim()));
*/
String[] pieces = PApplet.match(matrixStr, "\\s*(\\w+)\\((.*)\\)");
if (pieces.length != 2) {
if (pieces == null) {
System.err.println("Could not parse transform " + matrixStr);
return null;
}
float[] m = PApplet.parseFloat(PApplet.splitTokens(pieces[1]));
float[] m = PApplet.parseFloat(PApplet.splitTokens(pieces[2]));
if (pieces[0].equals("matrix")) {
if (pieces[1].equals("matrix")) {
return m;
} else if (pieces[0].equals("translate")) {
} else if (pieces[1].equals("translate")) {
float tx = m[0];
float ty = (m.length == 2) ? m[1] : m[0];
return new float[] { 1, 0, tx, 0, 1, ty };
} else if (pieces[0].equals("scale")) {
} else if (pieces[1].equals("scale")) {
float sx = m[0];
float sy = (m.length == 2) ? m[1] : m[0];
return new float[] { sx, 0, 0, 0, sy, 0 };
} else if (pieces[0].equals("rotate")) {
} else if (pieces[1].equals("rotate")) {
float angle = m[0];
if (m.length == 1) {
@@ -136,10 +136,10 @@ public class BaseObject extends PShape {
return mat.get(null);
}
} else if (pieces[0].equals("skewX")) {
} else if (pieces[1].equals("skewX")) {
return new float[] { 1, PApplet.tan(m[0]), 0, 0, 1, 0 };
} else if (pieces[0].equals("skewY")) {
} else if (pieces[1].equals("skewY")) {
return new float[] { 1, 0, 0, PApplet.tan(m[0]), 1, 0 };
}
return null;
+5
View File
@@ -36,6 +36,7 @@ X was a typo in the code
X add getting started to help menu
X http://processing.org/learning/gettingstarted/
X add "environment" to the help menu
X fix other instances of match() using the wrong array indices
cleanup
o how to grab the java2d object from PGraphics2D
@@ -50,10 +51,14 @@ o you wait for the images to download (size is zero until they're ready)
o MediaTracker blocking is prolly making jar download really slow
o http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1089914280
reference
_ do some edits on the "getting started" text
_ change references to help > getting started
_ add vida reference
_ make sure visualization not mentioned
_ update match(), write new reference for matchAll()
_ command line for casey