1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-23 19:21:59 +03:00

PdePreprocessor.scubComments result used before looking for libraries. Fixes #1293

This commit is contained in:
Federico Fissore
2013-11-11 12:05:59 +01:00
parent 22dfa98202
commit 07f8c691b4
3 changed files with 38 additions and 10 deletions

View File

@ -87,7 +87,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
scrubComments(program);
program = scrubComments(program);
// If there are errors, an exception is thrown and this fxn exits.
if (Preferences.getBoolean("preproc.substitute_unicode")) {
@ -242,14 +242,17 @@ public class PdePreprocessor {
*/
public String strip(String in) {
// XXX: doesn't properly handle special single-quoted characters
List<Pattern> patterns = new ArrayList<Pattern>();
// single-quoted character
Pattern[] patterns = new Pattern[6];
patterns[5] = Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE);
patterns[4] = Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE);
patterns[3] = Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE);
patterns[2] = Pattern.compile("(//.*?$)", Pattern.MULTILINE);
patterns[1] = Pattern.compile("('\\\\\"')", Pattern.MULTILINE);
patterns[0] = Pattern.compile("('.')", Pattern.MULTILINE);
patterns.add(Pattern.compile("('.')", Pattern.MULTILINE));
// single and multi-line comment
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
// pre-processor directive
patterns.add(Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE));
// double-quoted string
patterns.add(Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE));
String code = in;
for (Pattern p : patterns) {
@ -259,7 +262,7 @@ public class PdePreprocessor {
return code;
}
/**
* Removes the contents of all top-level curly brace pairs {}.
* @param in the String to collapse