darkeye
YaBB Newbies
Offline
Posts: 3
Re: command-line?
Reply #6 - Jul 9th , 2005, 4:50pm
I tried to make the processing.app.preproc.PdePreprocessor class work on its own, as it seems that's the one actually generating a proper java source from a PDE file content. I wrote the following simple piece of code: import java.io.*; import processing.app.preproc.PdePreprocessor; public class Pde2Java { public static void main(String args[]) throws Exception { if (args.length != 1) { return; } String programName = args[0]; String buildPath = "/tmp/build"; String name = "name"; String codeFolderPackages[] = null; BufferedReader reader = new BufferedReader(new FileReader(programName)); StringWriter program = new StringWriter(); BufferedWriter writer = new BufferedWriter(program); String line; while ((line = reader.readLine()) != null) { writer.write(line); writer.newLine(); } writer.flush(); PdePreprocessor pp = new PdePreprocessor(); String ret; ret = pp.write(program.toString(), buildPath, name, codeFolderPackages); System.out.println("ret: " + ret); } } now the problem is, that if I try a simple sample with it, like the Directional sample from among the processing examples: // Directional // by REAS <http://reas.com> // Move the mouse the change the direction of the light. // Directional light comes from one direction and is stronger // when hitting a surface squarely and weaker if it hits at a // a gentle angle. After hitting a surface, a directional lights // scatters in all directions. // Created 28 April 2005 void setup() { size(200, 200, P3D); noStroke(); fill(204); } void draw() { noStroke(); background(0); float dirY = (mouseY/float(height) - 0.5) * 2.0; float dirX = (mouseX/float(width) - 0.5) * 2.0; directionalLight(204, 204, 204, -dirX, -dirY, -1); translate(20, height/2, 0); sphere(60); translate(120, 0, 0); sphere(60); } I get the following error: Exception in thread "main" line 24:3: unexpected token: float at processing.app.preproc.PdeRecognizer.primaryExpression(PdeRecognizer.java:1100) at processing.app.preproc.PdeRecognizer.postfixExpression(PdeRecognizer.java:3765) at processing.app.preproc.PdeRecognizer.unaryExpressionNotPlusMinus(PdeRecognizer.j ava:3730) at processing.app.preproc.PdeRecognizer.unaryExpression(PdeRecognizer.java:3640) at processing.app.preproc.PdeRecognizer.multiplicativeExpression(PdeRecognizer.java :3548) at processing.app.preproc.PdeRecognizer.additiveExpression(PdeRecognizer.java:3505) at processing.app.preproc.PdeRecognizer.shiftExpression(PdeRecognizer.java:3456) at processing.app.preproc.PdeRecognizer.relationalExpression(PdeRecognizer.java:338 5) at processing.app.preproc.PdeRecognizer.equalityExpression(PdeRecognizer.java:3342) at processing.app.preproc.PdeRecognizer.andExpression(PdeRecognizer.java:3313) at processing.app.preproc.PdeRecognizer.exclusiveOrExpression(PdeRecognizer.java:32 84) at processing.app.preproc.PdeRecognizer.inclusiveOrExpression(PdeRecognizer.java:32 55) at processing.app.preproc.PdeRecognizer.logicalAndExpression(PdeRecognizer.java:322 6) at processing.app.preproc.PdeRecognizer.logicalOrExpression(PdeRecognizer.java:3197 ) at processing.app.preproc.PdeRecognizer.conditionalExpression(PdeRecognizer.java:31 66) at processing.app.preproc.PdeRecognizer.assignmentExpression(PdeRecognizer.java:125 0) at processing.app.preproc.PdeRecognizer.expression(PdeRecognizer.java:854) at processing.app.preproc.PdeRecognizer.statement(PdeRecognizer.java:571) at processing.app.preproc.PdeRecognizer.compoundStatement(PdeRecognizer.java:2683) at processing.app.preproc.PdeRecognizer.field(PdeRecognizer.java:1795) at processing.app.preproc.PdeRecognizer.possiblyEmptyField(PdeRecognizer.java:175) at processing.app.preproc.PdeRecognizer.activeProgram(PdeRecognizer.java:207) at processing.app.preproc.PdeRecognizer.pdeProgram(PdeRecognizer.java:132) at processing.app.preproc.PdePreprocessor.write(PdePreprocessor.java:254) at Pde2Java.main(Unknown Source) also trying with other PDE inputs, basically it will fail on the first encounter of a primitive type, such as float, int, etc. I wonder why the if() statement at line 1010 in PdeRecognizer.java doesn't recognize the primitive type: } else if ((LA(1)==NUM_INT||LA(1)==CHAR_LITERAL||LA(1)==STRING_LITERAL||LA(1)==NUM_FLOAT|| LA(1)==NUM_LONG||LA(1)==NUM_DOUBLE||LA(1)==WEBCOLOR_LITERAL)) { I checked that when running processing 'normally', PdePreprocessor.write() gets the exact same input. so the only different can be is the context it runs in: maybe some global variables are changed when running inside the Editor? BTW, I looked at the Sketch and some other classes, especially Preferences. It seems that by quite bad design, all rely on the Editor, which is a GUI after all. Like one can't even load Preferences without referring to the Editor class.