mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
PrePreprocess.scrubComments doesn't properly work: using RegExp from PrePreprocess.strip. Fixes #817
This commit is contained in:
parent
07f8c691b4
commit
05bf2b0be9
@ -334,49 +334,16 @@ public class PdePreprocessor {
|
|||||||
* Utility function used here and in the preprocessor.
|
* Utility function used here and in the preprocessor.
|
||||||
*/
|
*/
|
||||||
static public String scrubComments(String what) {
|
static public String scrubComments(String what) {
|
||||||
char p[] = what.toCharArray();
|
List<Pattern> patterns = new ArrayList<Pattern>();
|
||||||
|
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
|
||||||
|
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
|
||||||
|
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
|
||||||
|
|
||||||
int index = 0;
|
String result = what;
|
||||||
while (index < p.length) {
|
for (Pattern p : patterns) {
|
||||||
// for any double slash comments, ignore until the end of the line
|
result = p.matcher(result).replaceAll("");
|
||||||
if ((p[index] == '/') &&
|
|
||||||
(index < p.length - 1) &&
|
|
||||||
(p[index+1] == '/')) {
|
|
||||||
p[index++] = ' ';
|
|
||||||
p[index++] = ' ';
|
|
||||||
while ((index < p.length) &&
|
|
||||||
(p[index] != '\n')) {
|
|
||||||
p[index++] = ' ';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if this is the start of a new multiline comment.
|
return result;
|
||||||
// if it is, then make sure it's actually terminated somewhere.
|
|
||||||
} else if ((p[index] == '/') &&
|
|
||||||
(index < p.length - 1) &&
|
|
||||||
(p[index+1] == '*')) {
|
|
||||||
p[index++] = ' ';
|
|
||||||
p[index++] = ' ';
|
|
||||||
boolean endOfRainbow = false;
|
|
||||||
while (index < p.length - 1) {
|
|
||||||
if ((p[index] == '*') && (p[index+1] == '/')) {
|
|
||||||
p[index++] = ' ';
|
|
||||||
p[index++] = ' ';
|
|
||||||
endOfRainbow = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// continue blanking this area
|
|
||||||
p[index++] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!endOfRainbow) {
|
|
||||||
throw new RuntimeException(_("Missing the */ from the end of a " +
|
|
||||||
"/* comment */"));
|
|
||||||
}
|
|
||||||
} else { // any old character, move along
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new String(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user