mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
PdePreprocessor.scubComments result used before looking for libraries. Fixes #1293
This commit is contained in:
@ -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,14 +242,17 @@ 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
|
||||||
Pattern[] patterns = new Pattern[6];
|
patterns.add(Pattern.compile("('.')", Pattern.MULTILINE));
|
||||||
patterns[5] = Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE);
|
// single and multi-line comment
|
||||||
patterns[4] = Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE);
|
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
|
||||||
patterns[3] = Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE);
|
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
|
||||||
patterns[2] = Pattern.compile("(//.*?$)", Pattern.MULTILINE);
|
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
|
||||||
patterns[1] = Pattern.compile("('\\\\\"')", Pattern.MULTILINE);
|
// pre-processor directive
|
||||||
patterns[0] = Pattern.compile("('.')", Pattern.MULTILINE);
|
patterns.add(Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE));
|
||||||
|
// double-quoted string
|
||||||
|
patterns.add(Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE));
|
||||||
|
|
||||||
String code = in;
|
String code = in;
|
||||||
for (Pattern p : patterns) {
|
for (Pattern p : patterns) {
|
||||||
@ -259,7 +262,7 @@ public class PdePreprocessor {
|
|||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the contents of all top-level curly brace pairs {}.
|
* Removes the contents of all top-level curly brace pairs {}.
|
||||||
* @param in the String to collapse
|
* @param in the String to collapse
|
||||||
|
@ -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);
|
||||||
|
}
|
@ -18,4 +18,14 @@ public class PdePreprocessorTest {
|
|||||||
|
|
||||||
assertEquals(actualOutput, expectedOutput);
|
assertEquals(actualOutput, expectedOutput);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@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));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user