mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 01:50:44 +01:00
finish unicode preproc, more working on build()
This commit is contained in:
@@ -72,13 +72,11 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
// used when run without a vm ("expert" mode)
|
||||
"-bootclasspath",
|
||||
calcBootClassPath(),
|
||||
//System.getProperty("sun.boot.class.path") + additional,
|
||||
|
||||
// needed for macosx so that the classpath is set properly
|
||||
// also for windows because qtjava will most likely be here
|
||||
// and for linux, it just doesn't hurt
|
||||
"-classpath",
|
||||
//System.getProperty("java.class.path"),
|
||||
calcClassPath(includeFolder),
|
||||
|
||||
"-nowarn", // we're not currently interested in warnings
|
||||
|
||||
@@ -77,10 +77,7 @@ public class PdePreprocessor {
|
||||
*/
|
||||
public String write(String program, String buildPath,
|
||||
String name, String extraImports[]) throws java.lang.Exception {
|
||||
this.programReader = new StringReader(program);
|
||||
this.buildPath = buildPath;
|
||||
|
||||
if (PdePreferences.getBoolean("compiler.convert_unicode")) {
|
||||
if (PdePreferences.getBoolean("compiler.substitute_unicode")) {
|
||||
// check for non-ascii chars (these will be/must be in unicode format)
|
||||
char p[] = program.toCharArray();
|
||||
int unicodeCount = 0;
|
||||
@@ -109,11 +106,17 @@ public class PdePreprocessor {
|
||||
// add leading zeros, so that the length is 4
|
||||
for (int i = 0; i < 4 - str.length; i++) p2[index++] = '0';
|
||||
System.arraycopy(str, 0, p2, index, str.length);
|
||||
index += str.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
program = new String(p2, 0, index);
|
||||
}
|
||||
|
||||
// do this after the program gets re-combobulated
|
||||
this.programReader = new StringReader(program);
|
||||
this.buildPath = buildPath;
|
||||
|
||||
// create a lexer with the stream reader, and tell it to handle
|
||||
// hidden tokens (eg whitespace, comments) since we want to pass these
|
||||
// through so that the line numbers when the compiler reports errors
|
||||
|
||||
@@ -49,57 +49,24 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
Process process;
|
||||
OutputStream processOutput;
|
||||
boolean externalRuntime;
|
||||
String codeFolderPath;
|
||||
String externalPaths;
|
||||
//String codeFolderPath;
|
||||
//String externalPaths;
|
||||
String libraryPath;
|
||||
String classPath;
|
||||
|
||||
|
||||
public PdeRuntime(PdeEditor editor, String className,
|
||||
boolean externalRuntime,
|
||||
String codeFolderPath, String externalPaths) {
|
||||
String classPath, String libraryPath) {
|
||||
//String codeFolderPath, String externalPaths) {
|
||||
this.editor = editor;
|
||||
this.className = className;
|
||||
|
||||
this.externalRuntime = externalRuntime;
|
||||
this.codeFolderPath = codeFolderPath;
|
||||
this.externalPaths = externalPaths;
|
||||
}
|
||||
|
||||
|
||||
class SystemOutSiphon implements Runnable {
|
||||
InputStream input;
|
||||
Thread thread;
|
||||
|
||||
|
||||
public SystemOutSiphon(InputStream input) {
|
||||
this.input = input;
|
||||
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
byte boofer[] = new byte[1024];
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
//int count = input.available();
|
||||
//int offset = 0;
|
||||
int count = input.read(boofer, 0, boofer.length);
|
||||
if (count == -1) break;
|
||||
System.out.print(new String(boofer, 0, count));
|
||||
}
|
||||
|
||||
/*
|
||||
int c;
|
||||
while ((c = input.read()) != -1) {
|
||||
System.out.print((char) c);
|
||||
}
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
System.err.println("SystemOutSiphon error " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.classPath = classPath;
|
||||
this.libraryPath = libraryPath;
|
||||
//this.codeFolderPath = codeFolderPath;
|
||||
//this.externalPaths = externalPaths;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,9 +85,9 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
if (externalRuntime) {
|
||||
String command[] = new String[] {
|
||||
"java",
|
||||
"-Djava.library.path=" + codeFolderPath,
|
||||
"-Djava.library.path=" + libraryPath,
|
||||
"-cp",
|
||||
externalPaths,
|
||||
classPath,
|
||||
"BApplet",
|
||||
BApplet.EXTERNAL_FLAG + ((windowLocation != null) ?
|
||||
("e" +
|
||||
@@ -479,4 +446,42 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
//System.out.println("got it " + s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SystemOutSiphon implements Runnable {
|
||||
InputStream input;
|
||||
Thread thread;
|
||||
|
||||
|
||||
public SystemOutSiphon(InputStream input) {
|
||||
this.input = input;
|
||||
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
byte boofer[] = new byte[1024];
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
//int count = input.available();
|
||||
//int offset = 0;
|
||||
int count = input.read(boofer, 0, boofer.length);
|
||||
if (count == -1) break;
|
||||
System.out.print(new String(boofer, 0, count));
|
||||
}
|
||||
|
||||
/*
|
||||
int c;
|
||||
while ((c = input.read()) != -1) {
|
||||
System.out.print((char) c);
|
||||
}
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
System.err.println("SystemOutSiphon error " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ public class PdeSketch {
|
||||
int hiddenCount;
|
||||
PdeCode hidden[];
|
||||
|
||||
String classPath;
|
||||
String libraryPath;
|
||||
|
||||
|
||||
/**
|
||||
* path is location of the main .pde file, because this is also
|
||||
@@ -273,13 +276,14 @@ public class PdeSketch {
|
||||
// so that it can be included in the java.library.path
|
||||
String codeFolderPath = "";
|
||||
if (externalCode != null) {
|
||||
codeFolderPath = externalCode.getCanonicalPath();
|
||||
libraryPath = externalCode.getCanonicalPath();
|
||||
}
|
||||
|
||||
// create a runtime object
|
||||
runtime = new PdeRuntime(this, className,
|
||||
externalRuntime,
|
||||
codeFolderPath, externalPaths);
|
||||
libraryPath, classPath);
|
||||
//codeFolderPath, externalPaths);
|
||||
|
||||
// if programType is ADVANCED
|
||||
// or the code/ folder is not empty -> or just exists (simpler)
|
||||
@@ -350,20 +354,22 @@ public class PdeSketch {
|
||||
protected String build(String buildPath, String suggestedClassName)
|
||||
throws PdeException, Exception {
|
||||
|
||||
String classPath;
|
||||
String libraryPath;
|
||||
|
||||
boolean externalRuntime = false;
|
||||
//externalPaths = null;
|
||||
String additionalImports[] = null;
|
||||
String additionalClassPath = null;
|
||||
//String additionalClassPath = null;
|
||||
|
||||
// figure out the contents of the code folder to see if there
|
||||
// are files that need to be added to the imports
|
||||
File codeFolder = new File(sketchDir, "code");
|
||||
if (codeFolder.exists()) {
|
||||
externalRuntime = true;
|
||||
additionalClassPath = PdeCompiler.contentsToClassPath(codeFolder);
|
||||
classPath = PdeCompiler.contentsToClassPath(codeFolder);
|
||||
additionalImports = PdeCompiler.magicImports(additionalClassPath);
|
||||
} else {
|
||||
codeFolder = null;
|
||||
libraryPath = codeFolder.
|
||||
}
|
||||
|
||||
// first run preproc on the 'main' file, using the sugg class name
|
||||
@@ -372,53 +378,67 @@ public class PdeSketch {
|
||||
// if .pde, run preproc to buildpath
|
||||
// if no class def'd for the pde file, then complain
|
||||
|
||||
PdePreprocessor preprocessor = new PdePreprocessor();
|
||||
try {
|
||||
mainClassName =
|
||||
preprocessor.write(program, buildPath,
|
||||
suggestedClassName, externalImports);
|
||||
for (int i = 0; i < codeCount; i++) {
|
||||
PdePreprocessor preprocessor = new PdePreprocessor();
|
||||
try {
|
||||
String className =
|
||||
preprocessor.write(code[i].program, buildPath,
|
||||
(i == 0) ? suggestedClassName : null,
|
||||
additionalImports);
|
||||
if (className == null) {
|
||||
System.err.println("class could not be determined for " +
|
||||
code[i].name + " hopefully the error has " +
|
||||
"already been reported.");
|
||||
return null;
|
||||
} else {
|
||||
code[i].preprocName = className + ".java";
|
||||
}
|
||||
|
||||
} catch (antlr.RecognitionException re) {
|
||||
// this even returns a column
|
||||
throw new PdeException(re.getMessage(),
|
||||
re.getLine() - 1, re.getColumn());
|
||||
if (i == 0) { // check if the 'main' file is in java mode
|
||||
if (PdePreprocessor.programType == PdePreprocessor.JAVA) {
|
||||
externalRuntime = true; // we in advanced mode now, boy
|
||||
}
|
||||
}
|
||||
|
||||
} catch (antlr.TokenStreamRecognitionException tsre) {
|
||||
// while this seems to store line and column internally,
|
||||
// there doesn't seem to be a method to grab it..
|
||||
// so instead it's done using a regexp
|
||||
} catch (antlr.RecognitionException re) {
|
||||
// this even returns a column
|
||||
throw new PdeException(re.getMessage(),
|
||||
re.getLine() - 1, re.getColumn());
|
||||
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
// line 3:1: unexpected char: 0xA0
|
||||
String mess = "^line (\\d+):(\\d+):\\s";
|
||||
Pattern pattern = compiler.compile(mess);
|
||||
} catch (antlr.TokenStreamRecognitionException tsre) {
|
||||
// while this seems to store line and column internally,
|
||||
// there doesn't seem to be a method to grab it..
|
||||
// so instead it's done using a regexp
|
||||
|
||||
PatternMatcherInput input =
|
||||
new PatternMatcherInput(tsre.toString());
|
||||
if (matcher.contains(input, pattern)) {
|
||||
MatchResult result = matcher.getMatch();
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
// line 3:1: unexpected char: 0xA0
|
||||
String mess = "^line (\\d+):(\\d+):\\s";
|
||||
Pattern pattern = compiler.compile(mess);
|
||||
|
||||
int line = Integer.parseInt(result.group(1).toString());
|
||||
int column = Integer.parseInt(result.group(2).toString());
|
||||
throw new PdeException(tsre.getMessage(), line-1, column);
|
||||
PatternMatcherInput input =
|
||||
new PatternMatcherInput(tsre.toString());
|
||||
if (matcher.contains(input, pattern)) {
|
||||
MatchResult result = matcher.getMatch();
|
||||
|
||||
} else {
|
||||
throw new PdeException(tsre.toString());
|
||||
int line = Integer.parseInt(result.group(1).toString());
|
||||
int column = Integer.parseInt(result.group(2).toString());
|
||||
throw new PdeException(tsre.getMessage(), line-1, column);
|
||||
|
||||
} else {
|
||||
throw new PdeException(tsre.toString());
|
||||
}
|
||||
|
||||
} catch (PdeException pe) {
|
||||
throw pe;
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Uncaught exception type:" + ex.getClass());
|
||||
ex.printStackTrace();
|
||||
throw new PdeException(ex.toString());
|
||||
}
|
||||
|
||||
} catch (PdeException pe) {
|
||||
throw pe;
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Uncaught exception type:" + ex.getClass());
|
||||
ex.printStackTrace();
|
||||
throw new PdeException(ex.toString());
|
||||
}
|
||||
|
||||
if (PdePreprocessor.programType == PdePreprocessor.JAVA) {
|
||||
externalRuntime = true; // we in advanced mode now, boy
|
||||
}
|
||||
if (codeCount > 1) {
|
||||
externalRuntime = true;
|
||||
}
|
||||
@@ -912,6 +932,7 @@ public class PdeSketch {
|
||||
|
||||
class PdeCode {
|
||||
String name; // pretty name (no extension), not the full file name
|
||||
String preprocName; // name of .java file after preproc
|
||||
File file;
|
||||
int flavor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user