Skip to content

Commit 12446a2

Browse files
author
Federico Fissore
committed
Test preproc
1 parent c4823cc commit 12446a2

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

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

+14-16
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,21 @@ public int firstStatement(String in) {
243243
public String strip(String in) {
244244
// XXX: doesn't properly handle special single-quoted characters
245245
// single-quoted character
246-
String p = "('.')";
247-
248-
p += "|('\\\\\"')";
249-
250-
// double-quoted string
251-
p += "|(\"(?:[^\"\\\\]|\\\\.)*\")";
252-
253-
// single and multi-line comment
254-
//p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)";
255-
p += "|(//.*?$)|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)";
256-
257-
// pre-processor directive
258-
p += "|" + "(^\\s*#.*?$)";
246+
Pattern[] patterns = new Pattern[6];
247+
patterns[5] = Pattern.compile("(\"(?:[^\"\\\\]|\\\\.)*\")", Pattern.MULTILINE);
248+
patterns[4] = Pattern.compile("(^\\s*#.*?$)", Pattern.MULTILINE);
249+
patterns[3] = Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE);
250+
patterns[2] = Pattern.compile("(//.*?$)", Pattern.MULTILINE);
251+
patterns[1] = Pattern.compile("('\\\\\"')", Pattern.MULTILINE);
252+
patterns[0] = Pattern.compile("('.')", Pattern.MULTILINE);
253+
254+
String code = in;
255+
for (Pattern p : patterns) {
256+
Matcher matcher = p.matcher(code);
257+
code = matcher.replaceAll(" ");
258+
}
259259

260-
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE);
261-
Matcher matcher = pattern.matcher(in);
262-
return matcher.replaceAll(" ");
260+
return code;
263261
}
264262

265263
/**

0 commit comments

Comments
 (0)