Skip to content

Commit 5dc9e53

Browse files
author
Federico Fissore
committed
Merge branch 'ide-1.5.x' into ide-1.5.x-jssc
2 parents ac5e1e2 + 07f8c69 commit 5dc9e53

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

app/src/processing/app/preproc/PdePreprocessor.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public int writePrefix(String program)
8787
// an OutOfMemoryError or NullPointerException will happen.
8888
// again, not gonna bother tracking this down, but here's a hack.
8989
// http://dev.processing.org/bugs/show_bug.cgi?id=16
90-
scrubComments(program);
90+
program = scrubComments(program);
9191
// If there are errors, an exception is thrown and this fxn exits.
9292

9393
if (Preferences.getBoolean("preproc.substitute_unicode")) {
@@ -242,26 +242,27 @@ public int firstStatement(String in) {
242242
*/
243243
public String strip(String in) {
244244
// XXX: doesn't properly handle special single-quoted characters
245+
List<Pattern> patterns = new ArrayList<Pattern>();
245246
// single-quoted character
246-
String p = "('.')";
247-
248-
p += "|('\\\\\"')";
249-
250-
// double-quoted string
251-
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
252-
247+
patterns.add(Pattern.compile("('.')", Pattern.MULTILINE));
253248
// single and multi-line comment
254-
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
255-
p += "|(//.*?$)|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)";
256-
249+
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
250+
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
251+
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
257252
// pre-processor directive
258-
p += "|" + "(^\\s*#.*?$)";
253+
patterns.add(Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE));
254+
// double-quoted string
255+
patterns.add(Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE));
259256

260-
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
261-
Matcher matcher = pattern.matcher(in);
262-
return matcher.replaceAll(" ");
257+
String code = in;
258+
for (Pattern p : patterns) {
259+
Matcher matcher = p.matcher(code);
260+
code = matcher.replaceAll(" ");
261+
}
262+
263+
return code;
263264
}
264-
265+
265266
/**
266267
* Removes the contents of all top-level curly brace pairs {}.
267268
* @param in the String to collapse
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <CapacitiveSensorDue.h>
2+
/*
3+
#include <WiFi.h>
4+
*/
5+
CapacitiveSensorDue cs_13_8 = CapacitiveSensorDue(13,8);
6+
void setup()
7+
{
8+
Serial.begin(9600);
9+
}
10+
void loop()
11+
{
12+
long total1 = cs_13_8.read(30);
13+
Serial.println(total1);
14+
delay(100);
15+
}

app/test/processing/app/preproc/PdePreprocessorTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ public void testSourceWithQuoteAndDoubleQuotesEscapedAndFinalQuoteShouldNotRaise
1818

1919
assertEquals(actualOutput, expectedOutput);
2020
}
21-
}
21+
22+
@Test
23+
public void testIncludeInsideMultilineComment() throws Exception {
24+
String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("IncludeBetweenMultilineComment.ino").getFile()));
25+
26+
PdePreprocessor pdePreprocessor = new PdePreprocessor();
27+
pdePreprocessor.writePrefix(s);
28+
assertEquals(1, pdePreprocessor.getExtraImports().size());
29+
assertEquals("CapacitiveSensorDue.h", pdePreprocessor.getExtraImports().get(0));
30+
}
31+
}

0 commit comments

Comments
 (0)