mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
Reapplying Christian's regex patch.
Revert "Revert "Removed dependencies from regex library oro.jar"" This reverts commit ed7795ef8dc89e2afa8c9a994c2f1ad4771f459c.
This commit is contained in:
parent
4c26e071c8
commit
fa4d058297
@ -43,7 +43,7 @@
|
|||||||
excludes="**/tools/format/**"
|
excludes="**/tools/format/**"
|
||||||
encoding="UTF-8"
|
encoding="UTF-8"
|
||||||
includeAntRuntime="false"
|
includeAntRuntime="false"
|
||||||
classpath="../core/core.jar; ${env.JAVA_HOME}/lib/tools.jar; lib/ant.jar; lib/ant-launcher.jar; lib/apple.jar; lib/ecj.jar; lib/jna.jar; lib/oro.jar; lib/RXTXcomm.jar" />
|
classpath="../core/core.jar; ${env.JAVA_HOME}/lib/tools.jar; lib/ant.jar; lib/ant-launcher.jar; lib/apple.jar; lib/ecj.jar; lib/jna.jar; lib/RXTXcomm.jar" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="build" depends="compile" description="Build PDE">
|
<target name="build" depends="compile" description="Build PDE">
|
||||||
|
BIN
app/lib/oro.jar
BIN
app/lib/oro.jar
Binary file not shown.
@ -35,7 +35,7 @@ import processing.core.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import com.oroinc.text.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,16 +49,17 @@ public class PdePreprocessor {
|
|||||||
// we always write one header: WProgram.h
|
// we always write one header: WProgram.h
|
||||||
public int headerCount = 1;
|
public int headerCount = 1;
|
||||||
|
|
||||||
List prototypes;
|
// the prototypes that are generated by the preprocessor
|
||||||
|
List<String> prototypes;
|
||||||
|
|
||||||
// these ones have the .* at the end, since a class name might be at the end
|
// these ones have the .* at the end, since a class name might be at the end
|
||||||
// instead of .* which would make trouble other classes using this can lop
|
// instead of .* which would make trouble other classes using this can lop
|
||||||
// off the . and anything after it to produce a package name consistently.
|
// off the . and anything after it to produce a package name consistently.
|
||||||
ArrayList<String> programImports;
|
List<String> programImports;
|
||||||
|
|
||||||
// imports just from the code folder, treated differently
|
// imports just from the code folder, treated differently
|
||||||
// than the others, since the imports are auto-generated.
|
// than the others, since the imports are auto-generated.
|
||||||
ArrayList<String> codeFolderImports;
|
List<String> codeFolderImports;
|
||||||
|
|
||||||
String indent;
|
String indent;
|
||||||
|
|
||||||
@ -79,6 +80,14 @@ public class PdePreprocessor {
|
|||||||
indent = new String(indentChars);
|
indent = new String(indentChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes out the head of the c++ code generated for a sketch.
|
||||||
|
* Called from processing.app.Sketch.
|
||||||
|
* @param program the concatenated code from all tabs containing pde-files
|
||||||
|
* @param buildPath the path into which the processed pde-code is to be written
|
||||||
|
* @param name the name of the sketch
|
||||||
|
* @param codeFolderPackages unused param (leftover from processing)
|
||||||
|
*/
|
||||||
public int writePrefix(String program, String buildPath,
|
public int writePrefix(String program, String buildPath,
|
||||||
String sketchName, String codeFolderPackages[]) throws FileNotFoundException {
|
String sketchName, String codeFolderPackages[]) throws FileNotFoundException {
|
||||||
this.buildPath = buildPath;
|
this.buildPath = buildPath;
|
||||||
@ -93,7 +102,7 @@ public class PdePreprocessor {
|
|||||||
// an OutOfMemoryError or NullPointerException will happen.
|
// an OutOfMemoryError or NullPointerException will happen.
|
||||||
// again, not gonna bother tracking this down, but here's a hack.
|
// again, not gonna bother tracking this down, but here's a hack.
|
||||||
// http://dev.processing.org/bugs/show_bug.cgi?id=16
|
// http://dev.processing.org/bugs/show_bug.cgi?id=16
|
||||||
String scrubbed = Sketch.scrubComments(program);
|
Sketch.scrubComments(program);
|
||||||
// If there are errors, an exception is thrown and this fxn exits.
|
// If there are errors, an exception is thrown and this fxn exits.
|
||||||
|
|
||||||
if (Preferences.getBoolean("preproc.substitute_unicode")) {
|
if (Preferences.getBoolean("preproc.substitute_unicode")) {
|
||||||
@ -117,14 +126,7 @@ public class PdePreprocessor {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
prototypes = new ArrayList();
|
prototypes = prototypes(program);
|
||||||
|
|
||||||
try {
|
|
||||||
prototypes = prototypes(program);
|
|
||||||
} catch (MalformedPatternException e) {
|
|
||||||
System.out.println("Internal error while pre-processing; " +
|
|
||||||
"not generating function prototypes.\n\n" + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// store # of prototypes so that line number reporting can be adjusted
|
// store # of prototypes so that line number reporting can be adjusted
|
||||||
prototypeCount = prototypes.size();
|
prototypeCount = prototypes.size();
|
||||||
@ -193,7 +195,7 @@ public class PdePreprocessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the pde program to the cpp file
|
// Write the pde program to the cpp file
|
||||||
protected void writeProgram(PrintStream out, String program, List prototypes) {
|
protected void writeProgram(PrintStream out, String program, List<String> prototypes) {
|
||||||
int prototypeInsertionPoint = firstStatement(program);
|
int prototypeInsertionPoint = firstStatement(program);
|
||||||
|
|
||||||
out.print(program.substring(0, prototypeInsertionPoint));
|
out.print(program.substring(0, prototypeInsertionPoint));
|
||||||
@ -216,7 +218,7 @@ public class PdePreprocessor {
|
|||||||
protected void writeFooter(PrintStream out) throws java.lang.Exception {}
|
protected void writeFooter(PrintStream out) throws java.lang.Exception {}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<String> getExtraImports() {
|
public List<String> getExtraImports() {
|
||||||
return programImports;
|
return programImports;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,31 +231,23 @@ public class PdePreprocessor {
|
|||||||
* or a pre-processor directive.
|
* or a pre-processor directive.
|
||||||
*/
|
*/
|
||||||
public int firstStatement(String in) {
|
public int firstStatement(String in) {
|
||||||
PatternMatcherInput input = new PatternMatcherInput(in);
|
// whitespace
|
||||||
PatternCompiler compiler = new Perl5Compiler();
|
String p = "\\s+";
|
||||||
PatternMatcher matcher = new Perl5Matcher();
|
|
||||||
Pattern pattern = null;
|
|
||||||
|
|
||||||
try {
|
// multi-line and single-line comment
|
||||||
pattern = compiler.compile(
|
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
|
||||||
// XXX: doesn't properly handle special single-quoted characters
|
p += "|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)|(//.*?$)";
|
||||||
// whitespace
|
|
||||||
"\\s+" + "|" +
|
// pre-processor directive
|
||||||
// multi-line comment
|
p += "|(#(?:\\\\\\n|.)*)";
|
||||||
"(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)" + "|" +
|
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
|
||||||
// single-line comment
|
|
||||||
"(//.*?$)" + "|" +
|
|
||||||
// pre-processor directive
|
|
||||||
"(#(?:\\\\\\n|.)*)",
|
|
||||||
Perl5Compiler.MULTILINE_MASK);
|
|
||||||
} catch (MalformedPatternException e) {
|
|
||||||
throw new RuntimeException("Internal error in firstStatement()", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Matcher matcher = pattern.matcher(in);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (matcher.matchesPrefix(input, pattern)) {
|
while (matcher.find()) {
|
||||||
i = matcher.getMatch().endOffset(0);
|
if (matcher.start()!=i)
|
||||||
input.setCurrentOffset(i);
|
break;
|
||||||
|
i = matcher.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
@ -265,31 +259,24 @@ public class PdePreprocessor {
|
|||||||
* @param in the String to strip
|
* @param in the String to strip
|
||||||
* @return the stripped String
|
* @return the stripped String
|
||||||
*/
|
*/
|
||||||
public String strip(String in) throws MalformedPatternException {
|
public String strip(String in) {
|
||||||
PatternCompiler compiler = new Perl5Compiler();
|
// XXX: doesn't properly handle special single-quoted characters
|
||||||
PatternMatcher matcher = new Perl5Matcher();
|
// single-quoted character
|
||||||
Pattern pattern = compiler.compile(
|
String p = "('.')";
|
||||||
// XXX: doesn't properly handle special single-quoted characters
|
|
||||||
// single-quoted character
|
|
||||||
"('.')" + "|" +
|
|
||||||
// double-quoted string
|
|
||||||
"(\"(?:[^\"\\\\]|\\\\.)*\")" + "|" +
|
|
||||||
// multi-line comment
|
|
||||||
"(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)" + "|" +
|
|
||||||
// single-line comment
|
|
||||||
"(//.*?$)" + "|" +
|
|
||||||
// pre-processor directive
|
|
||||||
"(^\\s*#.*?$)",
|
|
||||||
Perl5Compiler.MULTILINE_MASK);
|
|
||||||
|
|
||||||
while (matcher.contains(in, pattern)) {
|
|
||||||
MatchResult result = matcher.getMatch();
|
|
||||||
// XXX: should preserve newlines in the result so that line numbers of
|
|
||||||
// the stripped string correspond to those in the original source.
|
|
||||||
in = in.substring(0, result.beginOffset(0)) + " " + in.substring(result.endOffset(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
return in;
|
// double-quoted string
|
||||||
|
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
|
||||||
|
|
||||||
|
// single and multi-line comment
|
||||||
|
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
|
||||||
|
p += "|(//.*?$)|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)";
|
||||||
|
|
||||||
|
// pre-processor directive
|
||||||
|
p += "|" + "(^\\s*#.*?$)";
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
|
||||||
|
Matcher matcher = pattern.matcher(in);
|
||||||
|
return matcher.replaceAll(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,21 +311,17 @@ public class PdePreprocessor {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List prototypes(String in) throws MalformedPatternException {
|
public ArrayList<String> prototypes(String in) {
|
||||||
in = collapseBraces(strip(in));
|
in = collapseBraces(strip(in));
|
||||||
|
|
||||||
PatternMatcherInput input = new PatternMatcherInput(in);
|
|
||||||
PatternCompiler compiler = new Perl5Compiler();
|
|
||||||
PatternMatcher matcher = new Perl5Matcher();
|
|
||||||
// XXX: doesn't handle ... varargs
|
// XXX: doesn't handle ... varargs
|
||||||
// XXX: doesn't handle function pointers
|
// XXX: doesn't handle function pointers
|
||||||
Pattern pattern = compiler.compile(
|
Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
||||||
"[\\w\\[\\]\\*]+\\s+[\\[\\]\\*\\w\\s]+\\([,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
|
||||||
List matches = new ArrayList();
|
|
||||||
|
|
||||||
while (matcher.contains(input, pattern)) {
|
ArrayList<String> matches = new ArrayList<String>();
|
||||||
matches.add(matcher.getMatch().group(0) + ";");
|
Matcher matcher = pattern.matcher(in);
|
||||||
}
|
while (matcher.find())
|
||||||
|
matches.add(matcher.group(0) + ";");
|
||||||
|
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
<include name="app/pde.jar" />
|
<include name="app/pde.jar" />
|
||||||
<include name="app/lib/ecj.jar" />
|
<include name="app/lib/ecj.jar" />
|
||||||
<include name="app/lib/jna.jar" />
|
<include name="app/lib/jna.jar" />
|
||||||
<include name="app/lib/oro.jar" />
|
|
||||||
<include name="app/lib/RXTXcomm.jar" />
|
<include name="app/lib/RXTXcomm.jar" />
|
||||||
<include name="app/lib/ant.jar" />
|
<include name="app/lib/ant.jar" />
|
||||||
<include name="app/lib/ant-launcher.jar" />
|
<include name="app/lib/ant-launcher.jar" />
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
<!-- In 0149, removed /System/Library/Java from the CLASSPATH because
|
<!-- In 0149, removed /System/Library/Java from the CLASSPATH because
|
||||||
it can cause problems if users have installed weird files there.
|
it can cause problems if users have installed weird files there.
|
||||||
http://dev.processing.org/bugs/show_bug.cgi?id=1045 -->
|
http://dev.processing.org/bugs/show_bug.cgi?id=1045 -->
|
||||||
<string>$JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/oro.jar:$JAVAROOT/RXTXcomm.jar</string>
|
<string>$JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/RXTXcomm.jar</string>
|
||||||
|
|
||||||
<key>JVMArchs</key>
|
<key>JVMArchs</key>
|
||||||
<array>
|
<array>
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
<cp>lib/core.jar</cp>
|
<cp>lib/core.jar</cp>
|
||||||
<cp>lib/jna.jar</cp>
|
<cp>lib/jna.jar</cp>
|
||||||
<cp>lib/ecj.jar</cp>
|
<cp>lib/ecj.jar</cp>
|
||||||
<cp>lib/oro.jar</cp>
|
|
||||||
<cp>lib/RXTXcomm.jar</cp>
|
<cp>lib/RXTXcomm.jar</cp>
|
||||||
</classPath>
|
</classPath>
|
||||||
<jre>
|
<jre>
|
||||||
|
1
todo.txt
1
todo.txt
@ -105,7 +105,6 @@ Sketch.java
|
|||||||
PreProcessor.java
|
PreProcessor.java
|
||||||
- split write() into writeHeader() and write() as in Processing?
|
- split write() into writeHeader() and write() as in Processing?
|
||||||
- add getExtraImports() function instead of having Sketch grab them directly.
|
- add getExtraImports() function instead of having Sketch grab them directly.
|
||||||
- don't use oro.jar
|
|
||||||
|
|
||||||
Base.java
|
Base.java
|
||||||
- add keywords from libraries to the syntax coloring
|
- add keywords from libraries to the syntax coloring
|
||||||
|
Loading…
x
Reference in New Issue
Block a user