@@ -87,7 +87,7 @@ public int writePrefix(String program)
8787 // an OutOfMemoryError or NullPointerException will happen.
8888 // again, not gonna bother tracking this down, but here's a hack.
8989 // http://dev.processing.org/bugs/show_bug.cgi?id=16
90- scrubComments (program );
90+ program = scrubComments (program );
9191 // If there are errors, an exception is thrown and this fxn exits.
9292
9393 if (Preferences .getBoolean ("preproc.substitute_unicode" )) {
@@ -242,14 +242,17 @@ public int firstStatement(String in) {
242242 */
243243 public String strip (String in ) {
244244 // XXX: doesn't properly handle special single-quoted characters
245+ List <Pattern > patterns = new ArrayList <Pattern >();
245246 // single-quoted character
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 );
247+ patterns .add (Pattern .compile ("('.')" , Pattern .MULTILINE ));
248+ // single and multi-line comment
249+ patterns .add (Pattern .compile ("('\\ \\ \" ')" , Pattern .MULTILINE ));
250+ patterns .add (Pattern .compile ("(//.*?$)" , Pattern .MULTILINE ));
251+ patterns .add (Pattern .compile ("(/\\ *[^*]*(?:\\ *(?!/)[^*]*)*\\ */)" , Pattern .MULTILINE ));
252+ // pre-processor directive
253+ patterns .add (Pattern .compile ("(^\\ s*#.*?$)" , Pattern .MULTILINE ));
254+ // double-quoted string
255+ patterns .add (Pattern .compile ("(\" (?:[^\" \\ \\ ]|\\ \\ .)*\" )" , Pattern .MULTILINE ));
253256
254257 String code = in ;
255258 for (Pattern p : patterns ) {
@@ -259,7 +262,7 @@ public String strip(String in) {
259262
260263 return code ;
261264 }
262-
265+
263266 /**
264267 * Removes the contents of all top-level curly brace pairs {}.
265268 * @param in the String to collapse
0 commit comments