From 84e9d70415cd16ba50a02010e93fb1670a442bc3 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Sun, 17 Nov 2013 22:12:07 +0100 Subject: [PATCH] Preprocessor regexp: "." now matches even line terminators. Closes #1653 --- .../app/preproc/PdePreprocessor.java | 2 +- .../app/preproc/LineContinuations.ino | 34 +++++++++++++++++++ .../preproc/LineContinuations.stripped.ino | 12 +++++++ .../app/preproc/PdePreprocessorTest.java | 14 ++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/test/processing/app/preproc/LineContinuations.ino create mode 100644 app/test/processing/app/preproc/LineContinuations.stripped.ino 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 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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x +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