FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make preprocessor scope-aware · hhdang/processing@2827174 · GitHub

Repository navigation

Commit 2827174

Browse files
committed
Make preprocessor scope-aware
- scope is taken into account when determining the sketch mode and looking for size() - error checker received some love and now understands JAVA mode Modes: - JAVA sketch contains "public class <sketchName> extends PApplet" in the global scope - ACTIVE sketch contains a method declaration in the global scope - STATIC sketch is everything else size() parsing: - JAVA sketches: no parsing - ACTIVE mode: if there is setup() in global scope, we look there for the first occurrence, no parsing otherwise - STATIC sketches: first occurrence of size() in global scope
1 parent 863d60d commit 2827174

2 files changed

Lines changed: 279 additions & 96 deletions

File tree

‎java/src/processing/mode/java/pdex/ErrorCheckerService.java‎

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class ErrorCheckerService implements Runnable {
132132
/**
133133
* Is the sketch running in static mode or active mode?
134134
*/
135-
public boolean staticMode = false;
135+
public PdePreprocessor.Mode mode = PdePreprocessor.Mode.ACTIVE;
136136

137137
/**
138138
* Compilation Unit for current sketch
@@ -1322,36 +1322,44 @@ protected String preprocessCode(String pdeCode) {
13221322
"DefaultClass" : editor.getSketch().getName();
13231323

13241324
// Check whether the code is being written in STATIC mode
1325-
// (no setup or draw function declarations) - append class
1326-
// declaration and void setup() declaration
1327-
Matcher matcher = SETUP_OR_DRAW_FUNCTION_DECL.matcher(sourceAlt);
1328-
staticMode = !matcher.find();
1325+
String uncommented = PdePreprocessor.scrubComments(sourceAlt);
1326+
1327+
mode = PdePreprocessor.parseMode(uncommented);
1328+
13291329
StringBuilder sb = new StringBuilder();
1330+
1331+
// Imports
13301332
sb.append(xqpreproc.prepareImports(programImports));
1331-
sb.append("public class " + className + " extends PApplet {\n");
1332-
if (staticMode) {
1333-
sb.append("public void setup() {\n");
1334-
}
1335-
sb.append(sourceAlt);
1336-
if (staticMode) {
1337-
sb.append("\nnoLoop();\n}");
1333+
1334+
// Header
1335+
if (mode != PdePreprocessor.Mode.JAVA) {
1336+
sb.append("public class " + className + " extends PApplet {\n");
1337+
if (mode == PdePreprocessor.Mode.STATIC) {
1338+
sb.append("public void setup() {\n");
1339+
}
13381340
}
1339-
sb.append("\n}");
1340-
sourceAlt = sb.toString();
13411341

1342-
int position = sourceAlt.indexOf("{") + 1;
1342+
// Grab the offset before adding contents of the editor
13431343
mainClassOffset = 1;
1344-
for (int i = 0; i <= position; i++) {
1345-
if (sourceAlt.charAt(i) == '\n') {
1344+
for (int i = 0; i < sb.length(); i++) {
1345+
if (sb.charAt(i) == '\n') {
13461346
mainClassOffset++;
13471347
}
13481348
}
1349-
if (staticMode) {
1350-
mainClassOffset++;
1349+
1350+
// Editor content
1351+
sb.append(sourceAlt);
1352+
1353+
// Footer
1354+
if (mode != PdePreprocessor.Mode.JAVA) {
1355+
if (mode == PdePreprocessor.Mode.STATIC) {
1356+
sb.append("\nnoLoop();\n}");
1357+
}
1358+
sb.append("\n}");
13511359
}
1352-
sourceAlt = substituteUnicode(sourceAlt);
1353-
sourceCode = sourceAlt;
1354-
return sourceAlt;
1360+
1361+
sourceCode = substituteUnicode(sb.toString());
1362+
return sourceCode;
13551363
}
13561364

13571365

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL