|
26 | 26 | import java.io.PrintWriter;
|
27 | 27 | //import java.io.Writer;
|
28 | 28 | import java.util.List;
|
29 |
| -import java.util.regex.MatchResult; |
30 |
| -import java.util.regex.Pattern; |
31 |
| - |
32 | 29 | import processing.app.*;
|
33 | 30 | import processing.core.PApplet;
|
34 |
| -import processing.data.StringList; |
35 | 31 | import processing.mode.java.preproc.PdePreprocessor;
|
36 |
| -//import processing.mode.java.preproc.PreprocessorResult; |
37 | 32 | import processing.mode.java.preproc.SurfaceInfo;
|
38 |
| -//import antlr.RecognitionException; |
39 |
| -//import antlr.TokenStreamException; |
40 | 33 |
|
41 | 34 |
|
42 | 35 | public class AndroidPreprocessor extends PdePreprocessor {
|
43 |
| - static private final Pattern VOID_SETUP_REGEX = |
44 |
| - Pattern.compile("(?:^|\\s|;)void\\s+setup\\s*\\(", Pattern.MULTILINE); |
45 |
| - static private final Pattern CLOSING_BRACE = Pattern.compile("\\}"); |
46 |
| - |
47 | 36 | protected Sketch sketch;
|
48 | 37 | protected String packageName;
|
49 | 38 |
|
@@ -83,84 +72,7 @@ public SurfaceInfo initSketchSize(String code) throws SketchException {
|
83 | 72 | sketchRenderer = surfaceInfo.getRenderer();*/
|
84 | 73 | return surfaceInfo;
|
85 | 74 | }
|
86 |
| - |
87 |
| - public String getRenderer(String code) { |
88 |
| - String uncommented = scrubComments(code); |
89 |
| - MatchResult setupMatch = findInCurrentScope(VOID_SETUP_REGEX, uncommented); |
90 |
| - String searchArea = null; |
91 |
| - if (setupMatch != null) { |
92 |
| - int start = uncommented.indexOf("{", setupMatch.end()); |
93 |
| - if (start >= 0) { |
94 |
| - // Find a closing brace |
95 |
| - MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start); |
96 |
| - if (match != null) { |
97 |
| - searchArea = uncommented.substring(start + 1, match.end() - 1); |
98 |
| - } else { |
99 |
| - return null; |
100 |
| - } |
101 |
| - } |
102 |
| - } |
103 |
| - String[] sizeContents = matchMethod("size", searchArea); |
104 |
| - String[] fullContents = matchMethod("fullScreen", searchArea); |
105 |
| - if (sizeContents != null) { |
106 |
| - StringList args = breakCommas(sizeContents[1]); |
107 |
| - return (args.size() >= 3) ? args.get(2).trim() : null; |
108 |
| - } |
109 |
| - if (fullContents != null) { |
110 |
| - StringList args = breakCommas(fullContents[1]); |
111 |
| - if (args.size() > 0) { // might have no args |
112 |
| - String args0 = args.get(0).trim(); |
113 |
| - if (args.size() == 1) { |
114 |
| - // could be either fullScreen(1) or fullScreen(P2D), figure out which |
115 |
| - if (args0.equals("SPAN") || PApplet.parseInt(args0, -1) != -1) { |
116 |
| - // it's the display parameter, not the renderer |
117 |
| - } else { |
118 |
| - return args0; |
119 |
| - } |
120 |
| - } else if (args.size() == 2) { |
121 |
| - return args0; |
122 |
| - } else { |
123 |
| - return null; |
124 |
| - } |
125 |
| - } |
126 |
| - } |
127 |
| - return null; |
128 |
| - } |
129 | 75 |
|
130 |
| - static private StringList breakCommas(String contents) { |
131 |
| - StringList outgoing = new StringList(); |
132 |
| - |
133 |
| - boolean insideQuote = false; |
134 |
| - // The current word being read |
135 |
| - StringBuilder current = new StringBuilder(); |
136 |
| - char[] chars = contents.toCharArray(); |
137 |
| - for (int i = 0; i < chars.length; i++) { |
138 |
| - char c = chars[i]; |
139 |
| - if (insideQuote) { |
140 |
| - current.append(c); |
141 |
| - if (c == '\"') { |
142 |
| - insideQuote = false; |
143 |
| - } |
144 |
| - } else { |
145 |
| - if (c == ',') { |
146 |
| - if (current.length() != 0) { |
147 |
| - outgoing.append(current.toString()); |
148 |
| - current.setLength(0); |
149 |
| - } |
150 |
| - } else { |
151 |
| - current.append(c); |
152 |
| - if (c == '\"') { |
153 |
| - insideQuote = true; |
154 |
| - } |
155 |
| - } |
156 |
| - } |
157 |
| - } |
158 |
| - if (current.length() != 0) { |
159 |
| - outgoing.append(current.toString()); |
160 |
| - } |
161 |
| - return outgoing; |
162 |
| - } |
163 |
| - |
164 | 76 |
|
165 | 77 | public String[] initSketchSmooth(String code) throws SketchException {
|
166 | 78 | String[] info = parseSketchSmooth(code, true);
|
|
0 commit comments