mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-22 08:22:04 +03:00
Revert "Removed dependencies from regex library oro.jar"
This reverts commit 2b4391052c
.
This commit is contained in:
@ -35,7 +35,7 @@ import processing.core.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.regex.*;
|
||||
import com.oroinc.text.regex.*;
|
||||
|
||||
|
||||
/**
|
||||
@ -49,17 +49,16 @@ public class PdePreprocessor {
|
||||
// we always write one header: WProgram.h
|
||||
public int headerCount = 1;
|
||||
|
||||
// the prototypes that are generated by the preprocessor
|
||||
List<String> prototypes;
|
||||
List prototypes;
|
||||
|
||||
// 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
|
||||
// off the . and anything after it to produce a package name consistently.
|
||||
List<String> programImports;
|
||||
ArrayList<String> programImports;
|
||||
|
||||
// imports just from the code folder, treated differently
|
||||
// than the others, since the imports are auto-generated.
|
||||
List<String> codeFolderImports;
|
||||
ArrayList<String> codeFolderImports;
|
||||
|
||||
String indent;
|
||||
|
||||
@ -80,14 +79,6 @@ public class PdePreprocessor {
|
||||
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,
|
||||
String sketchName, String codeFolderPackages[]) throws FileNotFoundException {
|
||||
this.buildPath = buildPath;
|
||||
@ -102,7 +93,7 @@ public class PdePreprocessor {
|
||||
// an OutOfMemoryError or NullPointerException will happen.
|
||||
// again, not gonna bother tracking this down, but here's a hack.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=16
|
||||
Sketch.scrubComments(program);
|
||||
String scrubbed = Sketch.scrubComments(program);
|
||||
// If there are errors, an exception is thrown and this fxn exits.
|
||||
|
||||
if (Preferences.getBoolean("preproc.substitute_unicode")) {
|
||||
@ -126,7 +117,14 @@ public class PdePreprocessor {
|
||||
// }
|
||||
// }
|
||||
|
||||
prototypes = prototypes(program);
|
||||
prototypes = new ArrayList();
|
||||
|
||||
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
|
||||
prototypeCount = prototypes.size();
|
||||
@ -195,7 +193,7 @@ public class PdePreprocessor {
|
||||
}
|
||||
|
||||
// Write the pde program to the cpp file
|
||||
protected void writeProgram(PrintStream out, String program, List<String> prototypes) {
|
||||
protected void writeProgram(PrintStream out, String program, List prototypes) {
|
||||
int prototypeInsertionPoint = firstStatement(program);
|
||||
|
||||
out.print(program.substring(0, prototypeInsertionPoint));
|
||||
@ -218,7 +216,7 @@ public class PdePreprocessor {
|
||||
protected void writeFooter(PrintStream out) throws java.lang.Exception {}
|
||||
|
||||
|
||||
public List<String> getExtraImports() {
|
||||
public ArrayList<String> getExtraImports() {
|
||||
return programImports;
|
||||
}
|
||||
|
||||
@ -231,23 +229,31 @@ public class PdePreprocessor {
|
||||
* or a pre-processor directive.
|
||||
*/
|
||||
public int firstStatement(String in) {
|
||||
// whitespace
|
||||
String p = "\\s+";
|
||||
PatternMatcherInput input = new PatternMatcherInput(in);
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
Pattern pattern = null;
|
||||
|
||||
// multi-line and single-line comment
|
||||
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
|
||||
p += "|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)|(//.*?$)";
|
||||
|
||||
// pre-processor directive
|
||||
p += "|(#(?:\\\\\\n|.)*)";
|
||||
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
|
||||
try {
|
||||
pattern = compiler.compile(
|
||||
// XXX: doesn't properly handle special single-quoted characters
|
||||
// whitespace
|
||||
"\\s+" + "|" +
|
||||
// multi-line comment
|
||||
"(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)" + "|" +
|
||||
// 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;
|
||||
while (matcher.find()) {
|
||||
if (matcher.start()!=i)
|
||||
break;
|
||||
i = matcher.end();
|
||||
while (matcher.matchesPrefix(input, pattern)) {
|
||||
i = matcher.getMatch().endOffset(0);
|
||||
input.setCurrentOffset(i);
|
||||
}
|
||||
|
||||
return i;
|
||||
@ -259,24 +265,31 @@ public class PdePreprocessor {
|
||||
* @param in the String to strip
|
||||
* @return the stripped String
|
||||
*/
|
||||
public String strip(String in) {
|
||||
// XXX: doesn't properly handle special single-quoted characters
|
||||
// single-quoted character
|
||||
String p = "('.')";
|
||||
public String strip(String in) throws MalformedPatternException {
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
Pattern pattern = compiler.compile(
|
||||
// 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));
|
||||
}
|
||||
|
||||
// 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(" ");
|
||||
return in;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,17 +324,21 @@ public class PdePreprocessor {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public ArrayList<String> prototypes(String in) {
|
||||
public List prototypes(String in) throws MalformedPatternException {
|
||||
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 function pointers
|
||||
Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
||||
Pattern pattern = compiler.compile(
|
||||
"[\\w\\[\\]\\*]+\\s+[\\[\\]\\*\\w\\s]+\\([,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
||||
List matches = new ArrayList();
|
||||
|
||||
ArrayList<String> matches = new ArrayList<String>();
|
||||
Matcher matcher = pattern.matcher(in);
|
||||
while (matcher.find())
|
||||
matches.add(matcher.group(0) + ";");
|
||||
while (matcher.contains(input, pattern)) {
|
||||
matches.add(matcher.getMatch().group(0) + ";");
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
Reference in New Issue
Block a user