Fix exception in preprocessor

Trying to run sketch with setup() without a body would crash the
preprocessor. Now it gives correct error message.
This commit is contained in:
Jakub Valtar
2015-10-22 16:19:50 +02:00
parent 5706bd93b3
commit eddd963ca1

View File

@@ -299,13 +299,14 @@ public class PdePreprocessor {
MatchResult setupMatch = findInCurrentScope(VOID_SETUP_REGEX, uncommented);
if (setupMatch != null) {
int start = uncommented.indexOf("{", setupMatch.end());
// Find a closing brace
MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start);
if (match != null) {
searchArea = uncommented.substring(start + 1, match.end() - 1);
} else {
throw new SketchException("Found a { that's missing a matching }", false);
if (start >= 0) {
// Find a closing brace
MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start);
if (match != null) {
searchArea = uncommented.substring(start + 1, match.end() - 1);
} else {
throw new SketchException("Found a { that's missing a matching }", false);
}
}
}
break;