Skip to content

Commit bdf7eba

Browse files
author
Federico Fissore
committed
Fixed pre processor bug. Closes #1245
1 parent dace68f commit bdf7eba

File tree

4 files changed

+704
-4
lines changed

4 files changed

+704
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ public int writePrefix(String program)
112112
// }
113113

114114
prototypes = prototypes(program);
115-
115+
116116
// store # of prototypes so that line number reporting can be adjusted
117117
prototypeCount = prototypes.size();
118118

119119
// do this after the program gets re-combobulated
120120
this.program = program;
121-
121+
122122
return headerCount + prototypeCount;
123123
}
124124

@@ -244,7 +244,9 @@ public String strip(String in) {
244244
// XXX: doesn't properly handle special single-quoted characters
245245
// single-quoted character
246246
String p = "('.')";
247-
247+
248+
p += "|('\\\\\"')";
249+
248250
// double-quoted string
249251
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
250252

@@ -294,7 +296,7 @@ private String collapseBraces(String in) {
294296

295297
public ArrayList<String> prototypes(String in) {
296298
in = collapseBraces(strip(in));
297-
299+
298300
// XXX: doesn't handle ... varargs
299301
// XXX: doesn't handle function pointers
300302
Pattern prototypePattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*;)");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package processing.app.preproc;
2+
3+
import org.junit.Test;
4+
import processing.app.helpers.FileUtils;
5+
6+
import java.io.File;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class PdePreprocessorTest {
11+
12+
@Test
13+
public void testSourceWithQuoteAndDoubleQuotesEscapedAndFinalQuoteShouldNotRaiseException() throws Exception {
14+
String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.ino").getFile()));
15+
16+
String actualOutput = new PdePreprocessor().strip(s);
17+
String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.stripped.ino").getFile()));
18+
19+
assertEquals(actualOutput, expectedOutput);
20+
}
21+
}

0 commit comments

Comments
 (0)