1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-07 01:54:26 +01:00

Merge remote-tracking branch 'arduino/ide-1.5.x' into ide-1.5.x

This commit is contained in:
Cristian Maglie 2013-11-11 12:42:20 +01:00
commit 95eced6c33
4 changed files with 53 additions and 63 deletions

View File

@ -87,7 +87,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
scrubComments(program); program = 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")) {
@ -242,24 +242,25 @@ public class PdePreprocessor {
*/ */
public String strip(String in) { public String strip(String in) {
// XXX: doesn't properly handle special single-quoted characters // XXX: doesn't properly handle special single-quoted characters
List<Pattern> patterns = new ArrayList<Pattern>();
// single-quoted character // single-quoted character
String p = "('.')"; patterns.add(Pattern.compile("('.')", Pattern.MULTILINE));
p += "|('\\\\\"')";
// double-quoted string
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
// single and multi-line comment // single and multi-line comment
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)"; patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
p += "|(//.*?$)|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)"; patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
// pre-processor directive // pre-processor directive
p += "|" + "(^\\s*#.*?$)"; patterns.add(Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE));
// double-quoted string
patterns.add(Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE));
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE); String code = in;
Matcher matcher = pattern.matcher(in); for (Pattern p : patterns) {
return matcher.replaceAll(" "); Matcher matcher = p.matcher(code);
code = matcher.replaceAll(" ");
}
return code;
} }
/** /**
@ -333,49 +334,16 @@ public class PdePreprocessor {
* Utility function used here and in the preprocessor. * Utility function used here and in the preprocessor.
*/ */
static public String scrubComments(String what) { static public String scrubComments(String what) {
char p[] = what.toCharArray(); List<Pattern> patterns = new ArrayList<Pattern>();
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
int index = 0; String result = what;
while (index < p.length) { for (Pattern p : patterns) {
// for any double slash comments, ignore until the end of the line result = p.matcher(result).replaceAll("");
if ((p[index] == '/') &&
(index < p.length - 1) &&
(p[index+1] == '/')) {
p[index++] = ' ';
p[index++] = ' ';
while ((index < p.length) &&
(p[index] != '\n')) {
p[index++] = ' ';
} }
// check to see if this is the start of a new multiline comment. return result;
// if it is, then make sure it's actually terminated somewhere.
} else if ((p[index] == '/') &&
(index < p.length - 1) &&
(p[index+1] == '*')) {
p[index++] = ' ';
p[index++] = ' ';
boolean endOfRainbow = false;
while (index < p.length - 1) {
if ((p[index] == '*') && (p[index+1] == '/')) {
p[index++] = ' ';
p[index++] = ' ';
endOfRainbow = true;
break;
} else {
// continue blanking this area
p[index++] = ' ';
}
}
if (!endOfRainbow) {
throw new RuntimeException(_("Missing the */ from the end of a " +
"/* comment */"));
}
} else { // any old character, move along
index++;
}
}
return new String(p);
} }
} }

View File

@ -0,0 +1,15 @@
#include <CapacitiveSensorDue.h>
/*
#include <WiFi.h>
*/
CapacitiveSensorDue cs_13_8 = CapacitiveSensorDue(13,8);
void setup()
{
Serial.begin(9600);
}
void loop()
{
long total1 = cs_13_8.read(30);
Serial.println(total1);
delay(100);
}

View File

@ -16,6 +16,16 @@ public class PdePreprocessorTest {
String actualOutput = new PdePreprocessor().strip(s); String actualOutput = new PdePreprocessor().strip(s);
String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.stripped.ino").getFile())); String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.stripped.ino").getFile()));
assertEquals(actualOutput, expectedOutput); assertEquals(expectedOutput, actualOutput);
}
@Test
public void testIncludeInsideMultilineComment() throws Exception {
String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("IncludeBetweenMultilineComment.ino").getFile()));
PdePreprocessor pdePreprocessor = new PdePreprocessor();
pdePreprocessor.writePrefix(s);
assertEquals(1, pdePreprocessor.getExtraImports().size());
assertEquals("CapacitiveSensorDue.h", pdePreprocessor.getExtraImports().get(0));
} }
} }

View File

@ -9,9 +9,6 @@
SoftwareSerial GPRS( 7, 8 ); SoftwareSerial GPRS( 7, 8 );
byte buffer[ 64 ]; byte buffer[ 64 ];
int count = 0, e = 0, count2 = 0, t = 0, q; int count = 0, e = 0, count2 = 0, t = 0, q;