diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index 89993c43f..a30f36c52 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -257,7 +257,7 @@ public class PdePreprocessor { // pre-processor directive p += "|" + "(^\\s*#.*?$)"; - Pattern pattern = Pattern.compile(p, Pattern.MULTILINE); + Pattern pattern = Pattern.compile(p, Pattern.MULTILINE | Pattern.DOTALL); Matcher matcher = pattern.matcher(in); return matcher.replaceAll(" "); } diff --git a/app/test/processing/app/preproc/LineContinuations.ino b/app/test/processing/app/preproc/LineContinuations.ino new file mode 100644 index 000000000..8611603e0 --- /dev/null +++ b/app/test/processing/app/preproc/LineContinuations.ino @@ -0,0 +1,34 @@ +const char *foo = "\ +hello \ +world\n"; + +//" delete this comment line and the IDE parser will crash + +void setup() +{ +} + +void loop() +{ +} +/* +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +*/ diff --git a/app/test/processing/app/preproc/LineContinuations.stripped.ino b/app/test/processing/app/preproc/LineContinuations.stripped.ino new file mode 100644 index 000000000..ffe2ea529 --- /dev/null +++ b/app/test/processing/app/preproc/LineContinuations.stripped.ino @@ -0,0 +1,12 @@ +const char *foo = ; + + + +void setup() +{ +} + +void loop() +{ +} + diff --git a/app/test/processing/app/preproc/PdePreprocessorTest.java b/app/test/processing/app/preproc/PdePreprocessorTest.java index f8e0f900c..ba938a420 100644 --- a/app/test/processing/app/preproc/PdePreprocessorTest.java +++ b/app/test/processing/app/preproc/PdePreprocessorTest.java @@ -93,4 +93,18 @@ public class PdePreprocessorTest { assertEquals("Wire.h", pdePreprocessor.getExtraImports().get(1)); } + @Test + public void testLineContinuations() throws Exception { + String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.ino").getFile())); + + PdePreprocessor pdePreprocessor = new PdePreprocessor(); + String actualOutput = pdePreprocessor.strip(s); + String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.stripped.ino").getFile())); + + assertEquals(expectedOutput, actualOutput); + + pdePreprocessor.writePrefix(s); + assertEquals(0, pdePreprocessor.getExtraImports().size()); + } + } \ No newline at end of file