Skip to content

Commit ed7795e

Browse files
author
David A. Mellis
committed
Revert "Removed dependencies from regex library oro.jar"
This reverts commit 2b43910.
1 parent 2b43910 commit ed7795e

File tree

7 files changed

+76
-56
lines changed

7 files changed

+76
-56
lines changed

app/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
excludes="**/tools/format/**"
4444
encoding="UTF-8"
4545
includeAntRuntime="false"
46-
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" />
46+
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" />
4747
</target>
4848

4949
<target name="build" depends="compile" description="Build PDE">

app/lib/oro.jar

26.1 KB
Binary file not shown.

app/src/processing/app/preproc/PdePreprocessor.java

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Processing version Copyright (c) 2004-05 Ben Fry and Casey Reas
3535
import java.io.*;
3636
import java.util.*;
3737

38-
import java.util.regex.*;
38+
import com.oroinc.text.regex.*;
3939

4040

4141
/**
@@ -49,17 +49,16 @@ public class PdePreprocessor {
4949
// we always write one header: WProgram.h
5050
public int headerCount = 1;
5151

52-
// the prototypes that are generated by the preprocessor
53-
List<String> prototypes;
52+
List prototypes;
5453

5554
// these ones have the .* at the end, since a class name might be at the end
5655
// instead of .* which would make trouble other classes using this can lop
5756
// off the . and anything after it to produce a package name consistently.
58-
List<String> programImports;
57+
ArrayList<String> programImports;
5958

6059
// imports just from the code folder, treated differently
6160
// than the others, since the imports are auto-generated.
62-
List<String> codeFolderImports;
61+
ArrayList<String> codeFolderImports;
6362

6463
String indent;
6564

@@ -80,14 +79,6 @@ public PdePreprocessor() {
8079
indent = new String(indentChars);
8180
}
8281

83-
/**
84-
* Writes out the head of the c++ code generated for a sketch.
85-
* Called from processing.app.Sketch.
86-
* @param program the concatenated code from all tabs containing pde-files
87-
* @param buildPath the path into which the processed pde-code is to be written
88-
* @param name the name of the sketch
89-
* @param codeFolderPackages unused param (leftover from processing)
90-
*/
9182
public int writePrefix(String program, String buildPath,
9283
String sketchName, String codeFolderPackages[]) throws FileNotFoundException {
9384
this.buildPath = buildPath;
@@ -102,7 +93,7 @@ public int writePrefix(String program, String buildPath,
10293
// an OutOfMemoryError or NullPointerException will happen.
10394
// again, not gonna bother tracking this down, but here's a hack.
10495
// http://dev.processing.org/bugs/show_bug.cgi?id=16
105-
Sketch.scrubComments(program);
96+
String scrubbed = Sketch.scrubComments(program);
10697
// If there are errors, an exception is thrown and this fxn exits.
10798

10899
if (Preferences.getBoolean("preproc.substitute_unicode")) {
@@ -126,7 +117,14 @@ public int writePrefix(String program, String buildPath,
126117
// }
127118
// }
128119

129-
prototypes = prototypes(program);
120+
prototypes = new ArrayList();
121+
122+
try {
123+
prototypes = prototypes(program);
124+
} catch (MalformedPatternException e) {
125+
System.out.println("Internal error while pre-processing; " +
126+
"not generating function prototypes.\n\n" + e);
127+
}
130128

131129
// store # of prototypes so that line number reporting can be adjusted
132130
prototypeCount = prototypes.size();
@@ -195,7 +193,7 @@ public String write() throws java.lang.Exception {
195193
}
196194

197195
// Write the pde program to the cpp file
198-
protected void writeProgram(PrintStream out, String program, List<String> prototypes) {
196+
protected void writeProgram(PrintStream out, String program, List prototypes) {
199197
int prototypeInsertionPoint = firstStatement(program);
200198

201199
out.print(program.substring(0, prototypeInsertionPoint));
@@ -218,7 +216,7 @@ protected void writeProgram(PrintStream out, String program, List<String> protot
218216
protected void writeFooter(PrintStream out) throws java.lang.Exception {}
219217

220218

221-
public List<String> getExtraImports() {
219+
public ArrayList<String> getExtraImports() {
222220
return programImports;
223221
}
224222

@@ -231,23 +229,31 @@ public List<String> getExtraImports() {
231229
* or a pre-processor directive.
232230
*/
233231
public int firstStatement(String in) {
234-
// whitespace
235-
String p = "\\s+";
232+
PatternMatcherInput input = new PatternMatcherInput(in);
233+
PatternCompiler compiler = new Perl5Compiler();
234+
PatternMatcher matcher = new Perl5Matcher();
235+
Pattern pattern = null;
236236

237-
// multi-line and single-line comment
238-
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
239-
p += "|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)|(//.*?$)";
240-
241-
// pre-processor directive
242-
p += "|(#(?:\\\\\\n|.)*)";
243-
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
237+
try {
238+
pattern = compiler.compile(
239+
// XXX: doesn't properly handle special single-quoted characters
240+
// whitespace
241+
"\\s+" + "|" +
242+
// multi-line comment
243+
"(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)" + "|" +
244+
// single-line comment
245+
"(//.*?$)" + "|" +
246+
// pre-processor directive
247+
"(#(?:\\\\\\n|.)*)",
248+
Perl5Compiler.MULTILINE_MASK);
249+
} catch (MalformedPatternException e) {
250+
throw new RuntimeException("Internal error in firstStatement()", e);
251+
}
244252

245-
Matcher matcher = pattern.matcher(in);
246253
int i = 0;
247-
while (matcher.find()) {
248-
if (matcher.start()!=i)
249-
break;
250-
i = matcher.end();
254+
while (matcher.matchesPrefix(input, pattern)) {
255+
i = matcher.getMatch().endOffset(0);
256+
input.setCurrentOffset(i);
251257
}
252258

253259
return i;
@@ -259,24 +265,31 @@ public int firstStatement(String in) {
259265
* @param in the String to strip
260266
* @return the stripped String
261267
*/
262-
public String strip(String in) {
263-
// XXX: doesn't properly handle special single-quoted characters
264-
// single-quoted character
265-
String p = "('.')";
266-
267-
// double-quoted string
268-
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
269-
270-
// single and multi-line comment
271-
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
272-
p += "|(//.*?$)|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)";
268+
public String strip(String in) throws MalformedPatternException {
269+
PatternCompiler compiler = new Perl5Compiler();
270+
PatternMatcher matcher = new Perl5Matcher();
271+
Pattern pattern = compiler.compile(
272+
// XXX: doesn't properly handle special single-quoted characters
273+
// single-quoted character
274+
"('.')" + "|" +
275+
// double-quoted string
276+
"(\"(?:[^\"\\\\]|\\\\.)*\")" + "|" +
277+
// multi-line comment
278+
"(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)" + "|" +
279+
// single-line comment
280+
"(//.*?$)" + "|" +
281+
// pre-processor directive
282+
"(^\\s*#.*?$)",
283+
Perl5Compiler.MULTILINE_MASK);
284+
285+
while (matcher.contains(in, pattern)) {
286+
MatchResult result = matcher.getMatch();
287+
// XXX: should preserve newlines in the result so that line numbers of
288+
// the stripped string correspond to those in the original source.
289+
in = in.substring(0, result.beginOffset(0)) + " " + in.substring(result.endOffset(0));
290+
}
273291

274-
// pre-processor directive
275-
p += "|" + "(^\\s*#.*?$)";
276-
277-
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
278-
Matcher matcher = pattern.matcher(in);
279-
return matcher.replaceAll(" ");
292+
return in;
280293
}
281294

282295
/**
@@ -311,17 +324,21 @@ private String collapseBraces(String in) {
311324
return buffer.toString();
312325
}
313326

314-
public ArrayList<String> prototypes(String in) {
327+
public List prototypes(String in) throws MalformedPatternException {
315328
in = collapseBraces(strip(in));
316329

330+
PatternMatcherInput input = new PatternMatcherInput(in);
331+
PatternCompiler compiler = new Perl5Compiler();
332+
PatternMatcher matcher = new Perl5Matcher();
317333
// XXX: doesn't handle ... varargs
318334
// XXX: doesn't handle function pointers
319-
Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
335+
Pattern pattern = compiler.compile(
336+
"[\\w\\[\\]\\*]+\\s+[\\[\\]\\*\\w\\s]+\\([,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
337+
List matches = new ArrayList();
320338

321-
ArrayList<String> matches = new ArrayList<String>();
322-
Matcher matcher = pattern.matcher(in);
323-
while (matcher.find())
324-
matches.add(matcher.group(0) + ";");
339+
while (matcher.contains(input, pattern)) {
340+
matches.add(matcher.getMatch().group(0) + ";");
341+
}
325342

326343
return matches;
327344
}

build/build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<include name="app/pde.jar" />
2020
<include name="app/lib/ecj.jar" />
2121
<include name="app/lib/jna.jar" />
22+
<include name="app/lib/oro.jar" />
2223
<include name="app/lib/RXTXcomm.jar" />
2324
<include name="app/lib/ant.jar" />
2425
<include name="app/lib/ant-launcher.jar" />

build/macosx/template.app/Contents/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<!-- In 0149, removed /System/Library/Java from the CLASSPATH because
7373
it can cause problems if users have installed weird files there.
7474
http://dev.processing.org/bugs/show_bug.cgi?id=1045 -->
75-
<string>$JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/RXTXcomm.jar</string>
75+
<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>
7676

7777
<key>JVMArchs</key>
7878
<array>

build/windows/launcher/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<cp>lib/core.jar</cp>
2020
<cp>lib/jna.jar</cp>
2121
<cp>lib/ecj.jar</cp>
22+
<cp>lib/oro.jar</cp>
2223
<cp>lib/RXTXcomm.jar</cp>
2324
</classPath>
2425
<jre>

todo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Sketch.java
105105
PreProcessor.java
106106
- split write() into writeHeader() and write() as in Processing?
107107
- add getExtraImports() function instead of having Sketch grab them directly.
108+
- don't use oro.jar
108109

109110
Base.java
110111
- add keywords from libraries to the syntax coloring

0 commit comments

Comments
 (0)