Skip to content

Commit 84e9d70

Browse files
author
Federico Fissore
committed
Preprocessor regexp: "." now matches even line terminators. Closes #1653
1 parent e6698e4 commit 84e9d70

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public String strip(String in) {
257257
// pre-processor directive
258258
p += "|" + "(^\\s*#.*?$)";
259259

260-
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
260+
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE | Pattern.DOTALL);
261261
Matcher matcher = pattern.matcher(in);
262262
return matcher.replaceAll(" ");
263263
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const char *foo = "\
2+
hello \
3+
world\n";
4+
5+
//" delete this comment line and the IDE parser will crash
6+
7+
void setup()
8+
{
9+
}
10+
11+
void loop()
12+
{
13+
}
14+
/*
15+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
16+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
17+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
18+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
19+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
20+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
21+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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ff line change
@@ -0,0 +1,12 @@
1+
const char *foo = ;
2+
3+
4+
5+
void setup()
6+
{
7+
}
8+
9+
void loop()
10+
{
11+
}
12+

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

+14
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,18 @@ public void testCharWithEscapedDoubleQuote() throws Exception {
9393
assertEquals("Wire.h", pdePreprocessor.getExtraImports().get(1));
9494
}
9595

96+
@Test
97+
public void testLineContinuations() throws Exception {
98+
String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.ino").getFile()));
99+
100+
PdePreprocessor pdePreprocessor = new PdePreprocessor();
101+
String actualOutput = pdePreprocessor.strip(s);
102+
String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.stripped.ino").getFile()));
103+
104+
assertEquals(expectedOutput, actualOutput);
105+
106+
pdePreprocessor.writePrefix(s);
107+
assertEquals(0, pdePreprocessor.getExtraImports().size());
108+
}
109+
96110
}

0 commit comments

Comments
 (0)