mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Merge remote-tracking branch 'arduino/ide-1.5.x' into ide-1.5.x
This commit is contained in:
commit
95eced6c33
@ -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,24 +242,25 @@ 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
|
||||
String p = "('.')";
|
||||
|
||||
p += "|('\\\\\"')";
|
||||
|
||||
// double-quoted string
|
||||
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
|
||||
|
||||
patterns.add(Pattern.compile("('.')", Pattern.MULTILINE));
|
||||
// single and multi-line comment
|
||||
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
|
||||
p += "|(//.*?$)|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)";
|
||||
|
||||
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
|
||||
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
|
||||
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
|
||||
// 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);
|
||||
Matcher matcher = pattern.matcher(in);
|
||||
return matcher.replaceAll(" ");
|
||||
String code = in;
|
||||
for (Pattern p : patterns) {
|
||||
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.
|
||||
*/
|
||||
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;
|
||||
while (index < p.length) {
|
||||
// for any double slash comments, ignore until the end of the line
|
||||
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.
|
||||
// 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++;
|
||||
}
|
||||
String result = what;
|
||||
for (Pattern p : patterns) {
|
||||
result = p.matcher(result).replaceAll("");
|
||||
}
|
||||
return new String(p);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -16,6 +16,16 @@ public class PdePreprocessorTest {
|
||||
String actualOutput = new PdePreprocessor().strip(s);
|
||||
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));
|
||||
}
|
||||
}
|
@ -9,9 +9,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SoftwareSerial GPRS( 7, 8 );
|
||||
byte buffer[ 64 ];
|
||||
int count = 0, e = 0, count2 = 0, t = 0, q;
|
||||
|
Loading…
x
Reference in New Issue
Block a user