|
52 | 52 | import processing.core.PConstants; |
53 | 53 | import processing.data.StringList; |
54 | 54 | import processing.data.XML; |
| 55 | +import processing.mode.java.pdex.SourceUtils; |
55 | 56 | import processing.mode.java.preproc.PdePreprocessor; |
56 | 57 | import processing.mode.java.preproc.PreprocessorResult; |
57 | 58 | import processing.mode.java.preproc.SurfaceInfo; |
@@ -280,27 +281,30 @@ public String preprocess(File srcFolder, |
280 | 281 | //System.out.println(java.getAbsolutePath()); |
281 | 282 | // System.out.println(bigCode); |
282 | 283 |
|
283 | | - if (msg.contains("expecting RCURLY")) { |
284 | | - //if (msg.equals("expecting RCURLY, found 'null'")) { |
285 | | - // This can be a problem since the error is sometimes listed as a line |
286 | | - // that's actually past the number of lines. For instance, it might |
287 | | - // report "line 15" of a 14 line program. Added code to highlightLine() |
288 | | - // inside Editor to deal with this situation (since that code is also |
289 | | - // useful for other similar situations). |
290 | | - throw new SketchException("Found one too many { characters " + |
291 | | - "without a } to match it.", |
292 | | - errorFile, errorLine, re.getColumn(), false); |
293 | | - } |
294 | | - |
295 | | - if (msg.contains("expecting LCURLY")) { |
296 | | - System.err.println(msg); |
297 | | - String suffix = "."; |
298 | | - String[] m = PApplet.match(msg, "found ('.*')"); |
299 | | - if (m != null) { |
300 | | - suffix = ", not " + m[1] + "."; |
| 284 | + if (msg.contains("expecting RCURLY") || msg.contains("expecting LCURLY")) { |
| 285 | + for (int i = 0; i < sketch.getCodeCount(); i++) { |
| 286 | + SketchCode sc = sketch.getCode(i); |
| 287 | + if (sc.isExtension("pde")) { |
| 288 | + String s = sc.getProgram(); |
| 289 | + int[] braceTest = SourceUtils.checkForMissingBraces( |
| 290 | + SourceUtils.scrubCommentsAndStrings(s) + "\n", 0, s.length()+1); |
| 291 | + if (braceTest[0] == 0) continue; |
| 292 | + |
| 293 | + // Completely ignoring the errorFile/errorLine given since it's |
| 294 | + // likely to be the wrong tab. For the same reason, I'm not showing |
| 295 | + // the result of PApplet.match(msg, "found ('.*')") on missing |
| 296 | + // LCURLY. |
| 297 | + throw new SketchException(braceTest[0] > 0 |
| 298 | + ? "Found one too many { characters without a } to match it." |
| 299 | + : "Found one too many } characters without a { to match it.", |
| 300 | + i, braceTest[1], braceTest[2], false); |
| 301 | + } |
301 | 302 | } |
302 | | - throw new SketchException("Was expecting a { character" + suffix, |
303 | | - errorFile, errorLine, re.getColumn(), false); |
| 303 | + // If we're still here, there's the right brackets, just not in the |
| 304 | + // right place. Passing on the original error. |
| 305 | + throw new SketchException( |
| 306 | + msg.replace("LCURLY", "{").replace("RCURLY", "}"), |
| 307 | + errorFile, errorLine, re.getColumn(), false); |
304 | 308 | } |
305 | 309 |
|
306 | 310 | if (msg.indexOf("expecting RBRACK") != -1) { |
|
0 commit comments