1 | /* Generated By:JavaCC: Do not edit this line. MapCSSParser.java */
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss.parser;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
|
---|
9 | import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
|
---|
10 | import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
|
---|
11 | import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
|
---|
12 | import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
|
---|
14 | import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.FunctionExpression;
|
---|
15 | import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.LiteralExpression;
|
---|
16 | import org.openstreetmap.josm.tools.Pair;
|
---|
17 |
|
---|
18 | public class MapCSSParser implements MapCSSParserConstants {
|
---|
19 |
|
---|
20 | /*************
|
---|
21 | * Parser definitions
|
---|
22 | *
|
---|
23 | * rule
|
---|
24 | * _______________________|______________________________
|
---|
25 | * | |
|
---|
26 | * selector declaration
|
---|
27 | * _________|___________________ _________|____________
|
---|
28 | * | | | |
|
---|
29 | *
|
---|
30 | * way|z11-12[highway=residential] { color: red; width: 3 }
|
---|
31 | *
|
---|
32 | * |_____||___________________| |_________|
|
---|
33 | * | | |
|
---|
34 | * zoom condition instruction
|
---|
35 | *
|
---|
36 | * more general:
|
---|
37 | *
|
---|
38 | * way|z13-[a=b][c=d]::subpart, way|z-3[u=v]:closed::subpart2 { p1 : val; p2 : val; }
|
---|
39 | *
|
---|
40 | * 'val' can be a literal, or an expression like "prop(width, default) + 0.8".
|
---|
41 | *
|
---|
42 | */
|
---|
43 | final public int uint() throws ParseException {
|
---|
44 | Token i;
|
---|
45 | i = jj_consume_token(UINT);
|
---|
46 | {if (true) return Integer.parseInt(i.image);}
|
---|
47 | throw new Error("Missing return statement in function");
|
---|
48 | }
|
---|
49 |
|
---|
50 | final public float ufloat() throws ParseException {
|
---|
51 | Token f;
|
---|
52 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
53 | case UFLOAT:
|
---|
54 | f = jj_consume_token(UFLOAT);
|
---|
55 | break;
|
---|
56 | case UINT:
|
---|
57 | f = jj_consume_token(UINT);
|
---|
58 | break;
|
---|
59 | default:
|
---|
60 | jj_la1[0] = jj_gen;
|
---|
61 | jj_consume_token(-1);
|
---|
62 | throw new ParseException();
|
---|
63 | }
|
---|
64 | {if (true) return Float.parseFloat(f.image);}
|
---|
65 | throw new Error("Missing return statement in function");
|
---|
66 | }
|
---|
67 |
|
---|
68 | final public String string() throws ParseException {
|
---|
69 | Token t;
|
---|
70 | t = jj_consume_token(STRING);
|
---|
71 | {if (true) return t.image.substring(1, t.image.length() - 1).replace("\\\"", "\"").replace("\\\\", "\\");}
|
---|
72 | throw new Error("Missing return statement in function");
|
---|
73 | }
|
---|
74 |
|
---|
75 | final public String string_or_ident() throws ParseException {
|
---|
76 | Token t;
|
---|
77 | String s;
|
---|
78 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
79 | case IDENT:
|
---|
80 | t = jj_consume_token(IDENT);
|
---|
81 | {if (true) return t.image;}
|
---|
82 | break;
|
---|
83 | case STRING:
|
---|
84 | s = string();
|
---|
85 | {if (true) return s;}
|
---|
86 | break;
|
---|
87 | default:
|
---|
88 | jj_la1[1] = jj_gen;
|
---|
89 | jj_consume_token(-1);
|
---|
90 | throw new ParseException();
|
---|
91 | }
|
---|
92 | throw new Error("Missing return statement in function");
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * white-space
|
---|
97 | */
|
---|
98 | final public void s() throws ParseException {
|
---|
99 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
100 | case S:
|
---|
101 | jj_consume_token(S);
|
---|
102 | break;
|
---|
103 | default:
|
---|
104 | jj_la1[2] = jj_gen;
|
---|
105 | ;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * mix of white-space and comments
|
---|
111 | */
|
---|
112 | final public void w() throws ParseException {
|
---|
113 | label_1:
|
---|
114 | while (true) {
|
---|
115 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
116 | case S:
|
---|
117 | case COMMENT_START:
|
---|
118 | ;
|
---|
119 | break;
|
---|
120 | default:
|
---|
121 | jj_la1[3] = jj_gen;
|
---|
122 | break label_1;
|
---|
123 | }
|
---|
124 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
125 | case S:
|
---|
126 | jj_consume_token(S);
|
---|
127 | break;
|
---|
128 | case COMMENT_START:
|
---|
129 | jj_consume_token(COMMENT_START);
|
---|
130 | jj_consume_token(COMMENT_END);
|
---|
131 | break;
|
---|
132 | default:
|
---|
133 | jj_la1[4] = jj_gen;
|
---|
134 | jj_consume_token(-1);
|
---|
135 | throw new ParseException();
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * comma delimited list of floats (at least 2, all >= 0)
|
---|
142 | */
|
---|
143 | final public List<Float> float_array() throws ParseException {
|
---|
144 | float f;
|
---|
145 | List<Float> fs = new ArrayList<Float>();
|
---|
146 | f = ufloat();
|
---|
147 | fs.add(f);
|
---|
148 | label_2:
|
---|
149 | while (true) {
|
---|
150 | jj_consume_token(COMMA);
|
---|
151 | s();
|
---|
152 | f = ufloat();
|
---|
153 | fs.add(f);
|
---|
154 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
155 | case COMMA:
|
---|
156 | ;
|
---|
157 | break;
|
---|
158 | default:
|
---|
159 | jj_la1[5] = jj_gen;
|
---|
160 | break label_2;
|
---|
161 | }
|
---|
162 | }
|
---|
163 | {if (true) return fs;}
|
---|
164 | throw new Error("Missing return statement in function");
|
---|
165 | }
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * root
|
---|
169 | */
|
---|
170 | final public void sheet(MapCSSStyleSource sheet) throws ParseException {
|
---|
171 | MapCSSRule r;
|
---|
172 | Token com = null;
|
---|
173 | w();
|
---|
174 | label_3:
|
---|
175 | while (true) {
|
---|
176 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
177 | case IDENT:
|
---|
178 | case STAR:
|
---|
179 | ;
|
---|
180 | break;
|
---|
181 | default:
|
---|
182 | jj_la1[6] = jj_gen;
|
---|
183 | break label_3;
|
---|
184 | }
|
---|
185 | r = rule();
|
---|
186 | sheet.rules.add(r);
|
---|
187 | w();
|
---|
188 | }
|
---|
189 | jj_consume_token(0);
|
---|
190 | }
|
---|
191 |
|
---|
192 | final public MapCSSRule rule() throws ParseException {
|
---|
193 | List<Selector> selectors = new ArrayList<Selector>();
|
---|
194 | Selector sel;
|
---|
195 | List<Instruction> decl;
|
---|
196 | sel = selector();
|
---|
197 | selectors.add(sel);
|
---|
198 | w();
|
---|
199 | label_4:
|
---|
200 | while (true) {
|
---|
201 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
202 | case COMMA:
|
---|
203 | ;
|
---|
204 | break;
|
---|
205 | default:
|
---|
206 | jj_la1[7] = jj_gen;
|
---|
207 | break label_4;
|
---|
208 | }
|
---|
209 | jj_consume_token(COMMA);
|
---|
210 | w();
|
---|
211 | sel = selector();
|
---|
212 | selectors.add(sel);
|
---|
213 | w();
|
---|
214 | }
|
---|
215 | decl = declaration();
|
---|
216 | {if (true) return new MapCSSRule(selectors, decl);}
|
---|
217 | throw new Error("Missing return statement in function");
|
---|
218 | }
|
---|
219 |
|
---|
220 | final public Selector selector() throws ParseException {
|
---|
221 | Token base;
|
---|
222 | Condition c;
|
---|
223 | Pair<Integer, Integer> r = null;
|
---|
224 | List<Condition> conditions = new ArrayList<Condition>();
|
---|
225 | String sub = null;
|
---|
226 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
227 | case IDENT:
|
---|
228 | base = jj_consume_token(IDENT);
|
---|
229 | break;
|
---|
230 | case STAR:
|
---|
231 | base = jj_consume_token(STAR);
|
---|
232 | break;
|
---|
233 | default:
|
---|
234 | jj_la1[8] = jj_gen;
|
---|
235 | jj_consume_token(-1);
|
---|
236 | throw new ParseException();
|
---|
237 | }
|
---|
238 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
239 | case PIPE_Z:
|
---|
240 | r = zoom();
|
---|
241 | break;
|
---|
242 | default:
|
---|
243 | jj_la1[9] = jj_gen;
|
---|
244 | ;
|
---|
245 | }
|
---|
246 | label_5:
|
---|
247 | while (true) {
|
---|
248 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
249 | case LSQUARE:
|
---|
250 | case COLON:
|
---|
251 | ;
|
---|
252 | break;
|
---|
253 | default:
|
---|
254 | jj_la1[10] = jj_gen;
|
---|
255 | break label_5;
|
---|
256 | }
|
---|
257 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
258 | case LSQUARE:
|
---|
259 | c = condition();
|
---|
260 | break;
|
---|
261 | case COLON:
|
---|
262 | c = pseudoclass();
|
---|
263 | break;
|
---|
264 | default:
|
---|
265 | jj_la1[11] = jj_gen;
|
---|
266 | jj_consume_token(-1);
|
---|
267 | throw new ParseException();
|
---|
268 | }
|
---|
269 | conditions.add(c);
|
---|
270 | }
|
---|
271 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
272 | case DCOLON:
|
---|
273 | sub = subpart();
|
---|
274 | break;
|
---|
275 | default:
|
---|
276 | jj_la1[12] = jj_gen;
|
---|
277 | ;
|
---|
278 | }
|
---|
279 | {if (true) return new Selector(base.image, r, conditions, sub);}
|
---|
280 | throw new Error("Missing return statement in function");
|
---|
281 | }
|
---|
282 |
|
---|
283 | final public Pair<Integer, Integer> zoom() throws ParseException {
|
---|
284 | Integer min = 0;
|
---|
285 | Integer max = Integer.MAX_VALUE;
|
---|
286 | jj_consume_token(PIPE_Z);
|
---|
287 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
288 | case MINUS:
|
---|
289 | jj_consume_token(MINUS);
|
---|
290 | max = uint();
|
---|
291 | break;
|
---|
292 | case UINT:
|
---|
293 | min = uint();
|
---|
294 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
295 | case MINUS:
|
---|
296 | jj_consume_token(MINUS);
|
---|
297 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
298 | case UINT:
|
---|
299 | max = uint();
|
---|
300 | break;
|
---|
301 | default:
|
---|
302 | jj_la1[13] = jj_gen;
|
---|
303 | ;
|
---|
304 | }
|
---|
305 | break;
|
---|
306 | default:
|
---|
307 | jj_la1[14] = jj_gen;
|
---|
308 | ;
|
---|
309 | }
|
---|
310 | break;
|
---|
311 | default:
|
---|
312 | jj_la1[15] = jj_gen;
|
---|
313 | jj_consume_token(-1);
|
---|
314 | throw new ParseException();
|
---|
315 | }
|
---|
316 | {if (true) return new Pair<Integer, Integer>(min, max);}
|
---|
317 | throw new Error("Missing return statement in function");
|
---|
318 | }
|
---|
319 |
|
---|
320 | final public Condition condition() throws ParseException {
|
---|
321 | Condition c;
|
---|
322 | Expression e;
|
---|
323 | jj_consume_token(LSQUARE);
|
---|
324 | if (jj_2_1(2)) {
|
---|
325 | c = simple_key_condition();
|
---|
326 | jj_consume_token(RSQUARE);
|
---|
327 | {if (true) return c;}
|
---|
328 | } else if (jj_2_2(3)) {
|
---|
329 | c = simple_key_value_condition();
|
---|
330 | } else {
|
---|
331 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
332 | case IDENT:
|
---|
333 | case UINT:
|
---|
334 | case UFLOAT:
|
---|
335 | case STRING:
|
---|
336 | case HEXCOLOR:
|
---|
337 | case LPAR:
|
---|
338 | case PLUS:
|
---|
339 | case MINUS:
|
---|
340 | e = expression();
|
---|
341 | c = new Condition.ExpressionCondition(e);
|
---|
342 | break;
|
---|
343 | default:
|
---|
344 | jj_la1[16] = jj_gen;
|
---|
345 | jj_consume_token(-1);
|
---|
346 | throw new ParseException();
|
---|
347 | }
|
---|
348 | }
|
---|
349 | jj_consume_token(RSQUARE);
|
---|
350 | {if (true) return c;}
|
---|
351 | throw new Error("Missing return statement in function");
|
---|
352 | }
|
---|
353 |
|
---|
354 | final public Condition simple_key_condition() throws ParseException {
|
---|
355 | boolean not = false;
|
---|
356 | String key;
|
---|
357 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
358 | case EXCLAMATION:
|
---|
359 | jj_consume_token(EXCLAMATION);
|
---|
360 | not = true;
|
---|
361 | break;
|
---|
362 | default:
|
---|
363 | jj_la1[17] = jj_gen;
|
---|
364 | ;
|
---|
365 | }
|
---|
366 | key = string_or_ident();
|
---|
367 | {if (true) return new Condition.KeyCondition(key, not);}
|
---|
368 | throw new Error("Missing return statement in function");
|
---|
369 | }
|
---|
370 |
|
---|
371 | final public Condition simple_key_value_condition() throws ParseException {
|
---|
372 | boolean not = false;
|
---|
373 | String key;
|
---|
374 | String val;
|
---|
375 | key = string_or_ident();
|
---|
376 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
377 | case EXCLAMATION_EQUAL:
|
---|
378 | jj_consume_token(EXCLAMATION_EQUAL);
|
---|
379 | not = true;
|
---|
380 | break;
|
---|
381 | case EQUAL:
|
---|
382 | jj_consume_token(EQUAL);
|
---|
383 | break;
|
---|
384 | default:
|
---|
385 | jj_la1[18] = jj_gen;
|
---|
386 | jj_consume_token(-1);
|
---|
387 | throw new ParseException();
|
---|
388 | }
|
---|
389 | val = string_or_ident();
|
---|
390 | {if (true) return new Condition.KeyValueCondition(key, val, not ? Condition.Op.NEQ : Condition.Op.EQ);}
|
---|
391 | throw new Error("Missing return statement in function");
|
---|
392 | }
|
---|
393 |
|
---|
394 | final public Condition pseudoclass() throws ParseException {
|
---|
395 | Token t;
|
---|
396 | boolean not = false;
|
---|
397 | jj_consume_token(COLON);
|
---|
398 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
399 | case EXCLAMATION:
|
---|
400 | jj_consume_token(EXCLAMATION);
|
---|
401 | not = true;
|
---|
402 | break;
|
---|
403 | default:
|
---|
404 | jj_la1[19] = jj_gen;
|
---|
405 | ;
|
---|
406 | }
|
---|
407 | t = jj_consume_token(IDENT);
|
---|
408 | {if (true) return new Condition.PseudoClassCondition(t.image, not);}
|
---|
409 | throw new Error("Missing return statement in function");
|
---|
410 | }
|
---|
411 |
|
---|
412 | final public String subpart() throws ParseException {
|
---|
413 | Token t;
|
---|
414 | jj_consume_token(DCOLON);
|
---|
415 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
416 | case IDENT:
|
---|
417 | t = jj_consume_token(IDENT);
|
---|
418 | break;
|
---|
419 | case STAR:
|
---|
420 | t = jj_consume_token(STAR);
|
---|
421 | break;
|
---|
422 | default:
|
---|
423 | jj_la1[20] = jj_gen;
|
---|
424 | jj_consume_token(-1);
|
---|
425 | throw new ParseException();
|
---|
426 | }
|
---|
427 | {if (true) return t.image;}
|
---|
428 | throw new Error("Missing return statement in function");
|
---|
429 | }
|
---|
430 |
|
---|
431 | final public List<Instruction> declaration() throws ParseException {
|
---|
432 | List<Instruction> ins = new ArrayList<Instruction>();
|
---|
433 | Instruction i;
|
---|
434 | jj_consume_token(LBRACE);
|
---|
435 | w();
|
---|
436 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
437 | case RBRACE:
|
---|
438 | jj_consume_token(RBRACE);
|
---|
439 | {if (true) return ins;}
|
---|
440 | break;
|
---|
441 | default:
|
---|
442 | jj_la1[21] = jj_gen;
|
---|
443 | ;
|
---|
444 | }
|
---|
445 | try {
|
---|
446 | i = instruction();
|
---|
447 | if (i != null) ins.add(i);
|
---|
448 | label_6:
|
---|
449 | while (true) {
|
---|
450 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
451 | case SEMICOLON:
|
---|
452 | ;
|
---|
453 | break;
|
---|
454 | default:
|
---|
455 | jj_la1[22] = jj_gen;
|
---|
456 | break label_6;
|
---|
457 | }
|
---|
458 | jj_consume_token(SEMICOLON);
|
---|
459 | w();
|
---|
460 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
461 | case RBRACE:
|
---|
462 | jj_consume_token(RBRACE);
|
---|
463 | {if (true) return ins;}
|
---|
464 | break;
|
---|
465 | default:
|
---|
466 | jj_la1[23] = jj_gen;
|
---|
467 | ;
|
---|
468 | }
|
---|
469 | i = instruction();
|
---|
470 | if (i != null) ins.add(i);
|
---|
471 | }
|
---|
472 | jj_consume_token(RBRACE);
|
---|
473 | {if (true) return ins;}
|
---|
474 | } catch (ParseException ex) {
|
---|
475 | error_skipto(RBRACE);
|
---|
476 | {if (true) return ins;}
|
---|
477 | }
|
---|
478 | throw new Error("Missing return statement in function");
|
---|
479 | }
|
---|
480 |
|
---|
481 | final public Instruction instruction() throws ParseException {
|
---|
482 | Token key;
|
---|
483 | Object val;
|
---|
484 | key = jj_consume_token(IDENT);
|
---|
485 | w();
|
---|
486 | jj_consume_token(COLON);
|
---|
487 | w();
|
---|
488 | if (jj_2_3(2)) {
|
---|
489 | val = float_array();
|
---|
490 | w();
|
---|
491 | } else {
|
---|
492 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
493 | case IDENT:
|
---|
494 | case UINT:
|
---|
495 | case UFLOAT:
|
---|
496 | case STRING:
|
---|
497 | case HEXCOLOR:
|
---|
498 | case LPAR:
|
---|
499 | case PLUS:
|
---|
500 | case MINUS:
|
---|
501 | val = expression();
|
---|
502 | break;
|
---|
503 | default:
|
---|
504 | jj_la1[24] = jj_gen;
|
---|
505 | jj_consume_token(-1);
|
---|
506 | throw new ParseException();
|
---|
507 | }
|
---|
508 | }
|
---|
509 | if (val instanceof LiteralExpression)
|
---|
510 | {if (true) return new Instruction.AssignmentInstruction(key.image, ((LiteralExpression) val).evaluate(null));}
|
---|
511 | else
|
---|
512 | {if (true) return new Instruction.AssignmentInstruction(key.image, val);}
|
---|
513 | throw new Error("Missing return statement in function");
|
---|
514 | }
|
---|
515 |
|
---|
516 | final public Expression expression() throws ParseException {
|
---|
517 | List<Expression> args = new ArrayList<Expression>();
|
---|
518 | Expression e;
|
---|
519 | String op = null;
|
---|
520 | e = primary();
|
---|
521 | args.add(e);
|
---|
522 | w();
|
---|
523 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
524 | case STAR:
|
---|
525 | case SLASH:
|
---|
526 | case PIPE:
|
---|
527 | case PLUS:
|
---|
528 | case MINUS:
|
---|
529 | case AMPERSAND:
|
---|
530 | case QUESTION:
|
---|
531 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
532 | case PLUS:
|
---|
533 | label_7:
|
---|
534 | while (true) {
|
---|
535 | jj_consume_token(PLUS);
|
---|
536 | op = "plus";
|
---|
537 | w();
|
---|
538 | e = primary();
|
---|
539 | args.add(e);
|
---|
540 | w();
|
---|
541 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
542 | case PLUS:
|
---|
543 | ;
|
---|
544 | break;
|
---|
545 | default:
|
---|
546 | jj_la1[25] = jj_gen;
|
---|
547 | break label_7;
|
---|
548 | }
|
---|
549 | }
|
---|
550 | break;
|
---|
551 | case STAR:
|
---|
552 | label_8:
|
---|
553 | while (true) {
|
---|
554 | jj_consume_token(STAR);
|
---|
555 | op = "times";
|
---|
556 | w();
|
---|
557 | e = primary();
|
---|
558 | args.add(e);
|
---|
559 | w();
|
---|
560 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
561 | case STAR:
|
---|
562 | ;
|
---|
563 | break;
|
---|
564 | default:
|
---|
565 | jj_la1[26] = jj_gen;
|
---|
566 | break label_8;
|
---|
567 | }
|
---|
568 | }
|
---|
569 | break;
|
---|
570 | case MINUS:
|
---|
571 | label_9:
|
---|
572 | while (true) {
|
---|
573 | jj_consume_token(MINUS);
|
---|
574 | op = "minus";
|
---|
575 | w();
|
---|
576 | e = primary();
|
---|
577 | args.add(e);
|
---|
578 | w();
|
---|
579 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
580 | case MINUS:
|
---|
581 | ;
|
---|
582 | break;
|
---|
583 | default:
|
---|
584 | jj_la1[27] = jj_gen;
|
---|
585 | break label_9;
|
---|
586 | }
|
---|
587 | }
|
---|
588 | break;
|
---|
589 | case SLASH:
|
---|
590 | label_10:
|
---|
591 | while (true) {
|
---|
592 | jj_consume_token(SLASH);
|
---|
593 | op = "divided_by";
|
---|
594 | w();
|
---|
595 | e = primary();
|
---|
596 | args.add(e);
|
---|
597 | w();
|
---|
598 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
599 | case SLASH:
|
---|
600 | ;
|
---|
601 | break;
|
---|
602 | default:
|
---|
603 | jj_la1[28] = jj_gen;
|
---|
604 | break label_10;
|
---|
605 | }
|
---|
606 | }
|
---|
607 | break;
|
---|
608 | case AMPERSAND:
|
---|
609 | jj_consume_token(AMPERSAND);
|
---|
610 | jj_consume_token(AMPERSAND);
|
---|
611 | op = "and";
|
---|
612 | w();
|
---|
613 | e = primary();
|
---|
614 | args.add(e);
|
---|
615 | w();
|
---|
616 | break;
|
---|
617 | case PIPE:
|
---|
618 | jj_consume_token(PIPE);
|
---|
619 | jj_consume_token(PIPE);
|
---|
620 | op = "or";
|
---|
621 | w();
|
---|
622 | e = primary();
|
---|
623 | args.add(e);
|
---|
624 | w();
|
---|
625 | break;
|
---|
626 | case QUESTION:
|
---|
627 | jj_consume_token(QUESTION);
|
---|
628 | op = "cond";
|
---|
629 | w();
|
---|
630 | e = primary();
|
---|
631 | args.add(e);
|
---|
632 | w();
|
---|
633 | jj_consume_token(COLON);
|
---|
634 | w();
|
---|
635 | e = primary();
|
---|
636 | args.add(e);
|
---|
637 | w();
|
---|
638 | break;
|
---|
639 | default:
|
---|
640 | jj_la1[29] = jj_gen;
|
---|
641 | jj_consume_token(-1);
|
---|
642 | throw new ParseException();
|
---|
643 | }
|
---|
644 | break;
|
---|
645 | default:
|
---|
646 | jj_la1[30] = jj_gen;
|
---|
647 | ;
|
---|
648 | }
|
---|
649 | if (op == null)
|
---|
650 | {if (true) return args.get(0);}
|
---|
651 | {if (true) return new FunctionExpression(op, args);}
|
---|
652 | throw new Error("Missing return statement in function");
|
---|
653 | }
|
---|
654 |
|
---|
655 | final public Expression primary() throws ParseException {
|
---|
656 | Expression nested;
|
---|
657 | FunctionExpression fn;
|
---|
658 | Object lit;
|
---|
659 | if (jj_2_4(2)) {
|
---|
660 | // both function and identifier start with an identifier
|
---|
661 | fn = function();
|
---|
662 | {if (true) return fn;}
|
---|
663 | } else {
|
---|
664 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
665 | case IDENT:
|
---|
666 | case UINT:
|
---|
667 | case UFLOAT:
|
---|
668 | case STRING:
|
---|
669 | case HEXCOLOR:
|
---|
670 | case PLUS:
|
---|
671 | case MINUS:
|
---|
672 | lit = literal();
|
---|
673 | {if (true) return new LiteralExpression(lit);}
|
---|
674 | break;
|
---|
675 | case LPAR:
|
---|
676 | jj_consume_token(LPAR);
|
---|
677 | w();
|
---|
678 | nested = expression();
|
---|
679 | jj_consume_token(RPAR);
|
---|
680 | {if (true) return nested;}
|
---|
681 | break;
|
---|
682 | default:
|
---|
683 | jj_la1[31] = jj_gen;
|
---|
684 | jj_consume_token(-1);
|
---|
685 | throw new ParseException();
|
---|
686 | }
|
---|
687 | }
|
---|
688 | throw new Error("Missing return statement in function");
|
---|
689 | }
|
---|
690 |
|
---|
691 | final public FunctionExpression function() throws ParseException {
|
---|
692 | Token tmp;
|
---|
693 | Expression arg;
|
---|
694 | String name;
|
---|
695 | List<Expression> args = new ArrayList<Expression>();
|
---|
696 | tmp = jj_consume_token(IDENT);
|
---|
697 | name = tmp.image;
|
---|
698 | w();
|
---|
699 | jj_consume_token(LPAR);
|
---|
700 | w();
|
---|
701 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
702 | case IDENT:
|
---|
703 | case UINT:
|
---|
704 | case UFLOAT:
|
---|
705 | case STRING:
|
---|
706 | case HEXCOLOR:
|
---|
707 | case LPAR:
|
---|
708 | case PLUS:
|
---|
709 | case MINUS:
|
---|
710 | arg = expression();
|
---|
711 | args.add(arg);
|
---|
712 | label_11:
|
---|
713 | while (true) {
|
---|
714 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
715 | case COMMA:
|
---|
716 | ;
|
---|
717 | break;
|
---|
718 | default:
|
---|
719 | jj_la1[32] = jj_gen;
|
---|
720 | break label_11;
|
---|
721 | }
|
---|
722 | jj_consume_token(COMMA);
|
---|
723 | w();
|
---|
724 | arg = expression();
|
---|
725 | args.add(arg);
|
---|
726 | }
|
---|
727 | break;
|
---|
728 | default:
|
---|
729 | jj_la1[33] = jj_gen;
|
---|
730 | ;
|
---|
731 | }
|
---|
732 | jj_consume_token(RPAR);
|
---|
733 | {if (true) return new FunctionExpression(name, args);}
|
---|
734 | throw new Error("Missing return statement in function");
|
---|
735 | }
|
---|
736 |
|
---|
737 | final public Object literal() throws ParseException {
|
---|
738 | Object val;
|
---|
739 | Token t;
|
---|
740 | float f;
|
---|
741 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
---|
742 | case IDENT:
|
---|
743 | case STRING:
|
---|
744 | val = string_or_ident();
|
---|
745 | {if (true) return val;}
|
---|
746 | break;
|
---|
747 | case PLUS:
|
---|
748 | jj_consume_token(PLUS);
|
---|
749 | f = ufloat();
|
---|
750 | {if (true) return new Instruction.RelativeFloat(f);}
|
---|
751 | break;
|
---|
752 | case MINUS:
|
---|
753 | jj_consume_token(MINUS);
|
---|
754 | f = ufloat();
|
---|
755 | {if (true) return -f;}
|
---|
756 | break;
|
---|
757 | case UINT:
|
---|
758 | case UFLOAT:
|
---|
759 | f = ufloat();
|
---|
760 | {if (true) return f;}
|
---|
761 | break;
|
---|
762 | case HEXCOLOR:
|
---|
763 | t = jj_consume_token(HEXCOLOR);
|
---|
764 | String clr = t.image.substring(1);
|
---|
765 | if (clr.length() == 3) {
|
---|
766 | clr = new String(new char[] {clr.charAt(0),clr.charAt(0),clr.charAt(1),clr.charAt(1),clr.charAt(2),clr.charAt(2)});
|
---|
767 | }
|
---|
768 | if (clr.length() != 6)
|
---|
769 | {if (true) throw new AssertionError();}
|
---|
770 | {if (true) return new Color(Integer.parseInt(clr, 16));}
|
---|
771 | break;
|
---|
772 | default:
|
---|
773 | jj_la1[34] = jj_gen;
|
---|
774 | jj_consume_token(-1);
|
---|
775 | throw new ParseException();
|
---|
776 | }
|
---|
777 | throw new Error("Missing return statement in function");
|
---|
778 | }
|
---|
779 |
|
---|
780 | void error_skipto(int kind) throws ParseException {
|
---|
781 | ParseException e = generateParseException();
|
---|
782 | System.err.println(e);
|
---|
783 | Token t;
|
---|
784 | do {
|
---|
785 | t = getNextToken();
|
---|
786 | } while (t.kind != kind);
|
---|
787 | }
|
---|
788 |
|
---|
789 | private boolean jj_2_1(int xla) {
|
---|
790 | jj_la = xla; jj_lastpos = jj_scanpos = token;
|
---|
791 | try { return !jj_3_1(); }
|
---|
792 | catch(LookaheadSuccess ls) { return true; }
|
---|
793 | finally { jj_save(0, xla); }
|
---|
794 | }
|
---|
795 |
|
---|
796 | private boolean jj_2_2(int xla) {
|
---|
797 | jj_la = xla; jj_lastpos = jj_scanpos = token;
|
---|
798 | try { return !jj_3_2(); }
|
---|
799 | catch(LookaheadSuccess ls) { return true; }
|
---|
800 | finally { jj_save(1, xla); }
|
---|
801 | }
|
---|
802 |
|
---|
803 | private boolean jj_2_3(int xla) {
|
---|
804 | jj_la = xla; jj_lastpos = jj_scanpos = token;
|
---|
805 | try { return !jj_3_3(); }
|
---|
806 | catch(LookaheadSuccess ls) { return true; }
|
---|
807 | finally { jj_save(2, xla); }
|
---|
808 | }
|
---|
809 |
|
---|
810 | private boolean jj_2_4(int xla) {
|
---|
811 | jj_la = xla; jj_lastpos = jj_scanpos = token;
|
---|
812 | try { return !jj_3_4(); }
|
---|
813 | catch(LookaheadSuccess ls) { return true; }
|
---|
814 | finally { jj_save(3, xla); }
|
---|
815 | }
|
---|
816 |
|
---|
817 | private boolean jj_3R_13() {
|
---|
818 | if (jj_3R_17()) return true;
|
---|
819 | Token xsp;
|
---|
820 | xsp = jj_scanpos;
|
---|
821 | if (jj_3R_18()) {
|
---|
822 | jj_scanpos = xsp;
|
---|
823 | if (jj_scan_token(16)) return true;
|
---|
824 | }
|
---|
825 | if (jj_3R_17()) return true;
|
---|
826 | return false;
|
---|
827 | }
|
---|
828 |
|
---|
829 | private boolean jj_3R_20() {
|
---|
830 | if (jj_scan_token(COMMA)) return true;
|
---|
831 | return false;
|
---|
832 | }
|
---|
833 |
|
---|
834 | private boolean jj_3R_16() {
|
---|
835 | if (jj_scan_token(EXCLAMATION)) return true;
|
---|
836 | return false;
|
---|
837 | }
|
---|
838 |
|
---|
839 | private boolean jj_3R_25() {
|
---|
840 | if (jj_scan_token(STRING)) return true;
|
---|
841 | return false;
|
---|
842 | }
|
---|
843 |
|
---|
844 | private boolean jj_3R_12() {
|
---|
845 | Token xsp;
|
---|
846 | xsp = jj_scanpos;
|
---|
847 | if (jj_3R_16()) jj_scanpos = xsp;
|
---|
848 | if (jj_3R_17()) return true;
|
---|
849 | return false;
|
---|
850 | }
|
---|
851 |
|
---|
852 | private boolean jj_3R_14() {
|
---|
853 | if (jj_3R_19()) return true;
|
---|
854 | Token xsp;
|
---|
855 | if (jj_3R_20()) return true;
|
---|
856 | while (true) {
|
---|
857 | xsp = jj_scanpos;
|
---|
858 | if (jj_3R_20()) { jj_scanpos = xsp; break; }
|
---|
859 | }
|
---|
860 | return false;
|
---|
861 | }
|
---|
862 |
|
---|
863 | private boolean jj_3R_23() {
|
---|
864 | if (jj_3R_25()) return true;
|
---|
865 | return false;
|
---|
866 | }
|
---|
867 |
|
---|
868 | private boolean jj_3R_15() {
|
---|
869 | if (jj_scan_token(IDENT)) return true;
|
---|
870 | if (jj_3R_21()) return true;
|
---|
871 | if (jj_scan_token(LPAR)) return true;
|
---|
872 | return false;
|
---|
873 | }
|
---|
874 |
|
---|
875 | private boolean jj_3R_26() {
|
---|
876 | if (jj_scan_token(COMMENT_START)) return true;
|
---|
877 | return false;
|
---|
878 | }
|
---|
879 |
|
---|
880 | private boolean jj_3R_19() {
|
---|
881 | Token xsp;
|
---|
882 | xsp = jj_scanpos;
|
---|
883 | if (jj_scan_token(3)) {
|
---|
884 | jj_scanpos = xsp;
|
---|
885 | if (jj_scan_token(2)) return true;
|
---|
886 | }
|
---|
887 | return false;
|
---|
888 | }
|
---|
889 |
|
---|
890 | private boolean jj_3_2() {
|
---|
891 | if (jj_3R_13()) return true;
|
---|
892 | return false;
|
---|
893 | }
|
---|
894 |
|
---|
895 | private boolean jj_3R_24() {
|
---|
896 | Token xsp;
|
---|
897 | xsp = jj_scanpos;
|
---|
898 | if (jj_scan_token(7)) {
|
---|
899 | jj_scanpos = xsp;
|
---|
900 | if (jj_3R_26()) return true;
|
---|
901 | }
|
---|
902 | return false;
|
---|
903 | }
|
---|
904 |
|
---|
905 | private boolean jj_3R_21() {
|
---|
906 | Token xsp;
|
---|
907 | while (true) {
|
---|
908 | xsp = jj_scanpos;
|
---|
909 | if (jj_3R_24()) { jj_scanpos = xsp; break; }
|
---|
910 | }
|
---|
911 | return false;
|
---|
912 | }
|
---|
913 |
|
---|
914 | private boolean jj_3_1() {
|
---|
915 | if (jj_3R_12()) return true;
|
---|
916 | if (jj_scan_token(RSQUARE)) return true;
|
---|
917 | return false;
|
---|
918 | }
|
---|
919 |
|
---|
920 | private boolean jj_3_3() {
|
---|
921 | if (jj_3R_14()) return true;
|
---|
922 | return false;
|
---|
923 | }
|
---|
924 |
|
---|
925 | private boolean jj_3_4() {
|
---|
926 | if (jj_3R_15()) return true;
|
---|
927 | return false;
|
---|
928 | }
|
---|
929 |
|
---|
930 | private boolean jj_3R_18() {
|
---|
931 | if (jj_scan_token(EXCLAMATION_EQUAL)) return true;
|
---|
932 | return false;
|
---|
933 | }
|
---|
934 |
|
---|
935 | private boolean jj_3R_17() {
|
---|
936 | Token xsp;
|
---|
937 | xsp = jj_scanpos;
|
---|
938 | if (jj_3R_22()) {
|
---|
939 | jj_scanpos = xsp;
|
---|
940 | if (jj_3R_23()) return true;
|
---|
941 | }
|
---|
942 | return false;
|
---|
943 | }
|
---|
944 |
|
---|
945 | private boolean jj_3R_22() {
|
---|
946 | if (jj_scan_token(IDENT)) return true;
|
---|
947 | return false;
|
---|
948 | }
|
---|
949 |
|
---|
950 | /** Generated Token Manager. */
|
---|
951 | public MapCSSParserTokenManager token_source;
|
---|
952 | SimpleCharStream jj_input_stream;
|
---|
953 | /** Current token. */
|
---|
954 | public Token token;
|
---|
955 | /** Next token. */
|
---|
956 | public Token jj_nt;
|
---|
957 | private int jj_ntk;
|
---|
958 | private Token jj_scanpos, jj_lastpos;
|
---|
959 | private int jj_la;
|
---|
960 | private int jj_gen;
|
---|
961 | final private int[] jj_la1 = new int[35];
|
---|
962 | static private int[] jj_la1_0;
|
---|
963 | static private int[] jj_la1_1;
|
---|
964 | static {
|
---|
965 | jj_la1_init_0();
|
---|
966 | jj_la1_init_1();
|
---|
967 | }
|
---|
968 | private static void jj_la1_init_0() {
|
---|
969 | jj_la1_0 = new int[] {0xc,0x12,0x80,0x20000080,0x20000080,0x400000,0x102,0x400000,0x102,0x1000000,0x81000,0x81000,0x100000,0x4,0x4000000,0x4000004,0x600405e,0x20000,0x50000,0x20000,0x102,0x800,0x200000,0x800,0x600405e,0x2000000,0x100,0x4000000,0x200,0x1e800300,0x1e800300,0x600405e,0x400000,0x600405e,0x600005e,};
|
---|
970 | }
|
---|
971 | private static void jj_la1_init_1() {
|
---|
972 | jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
|
---|
973 | }
|
---|
974 | final private JJCalls[] jj_2_rtns = new JJCalls[4];
|
---|
975 | private boolean jj_rescan = false;
|
---|
976 | private int jj_gc = 0;
|
---|
977 |
|
---|
978 | /** Constructor with InputStream. */
|
---|
979 | public MapCSSParser(java.io.InputStream stream) {
|
---|
980 | this(stream, null);
|
---|
981 | }
|
---|
982 | /** Constructor with InputStream and supplied encoding */
|
---|
983 | public MapCSSParser(java.io.InputStream stream, String encoding) {
|
---|
984 | try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
|
---|
985 | token_source = new MapCSSParserTokenManager(jj_input_stream);
|
---|
986 | token = new Token();
|
---|
987 | jj_ntk = -1;
|
---|
988 | jj_gen = 0;
|
---|
989 | for (int i = 0; i < 35; i++) jj_la1[i] = -1;
|
---|
990 | for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
---|
991 | }
|
---|
992 |
|
---|
993 | /** Reinitialise. */
|
---|
994 | public void ReInit(java.io.InputStream stream) {
|
---|
995 | ReInit(stream, null);
|
---|
996 | }
|
---|
997 | /** Reinitialise. */
|
---|
998 | public void ReInit(java.io.InputStream stream, String encoding) {
|
---|
999 | try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
|
---|
1000 | token_source.ReInit(jj_input_stream);
|
---|
1001 | token = new Token();
|
---|
1002 | jj_ntk = -1;
|
---|
1003 | jj_gen = 0;
|
---|
1004 | for (int i = 0; i < 35; i++) jj_la1[i] = -1;
|
---|
1005 | for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | /** Constructor. */
|
---|
1009 | public MapCSSParser(java.io.Reader stream) {
|
---|
1010 | jj_input_stream = new SimpleCharStream(stream, 1, 1);
|
---|
1011 | token_source = new MapCSSParserTokenManager(jj_input_stream);
|
---|
1012 | token = new Token();
|
---|
1013 | jj_ntk = -1;
|
---|
1014 | jj_gen = 0;
|
---|
1015 | for (int i = 0; i < 35; i++) jj_la1[i] = -1;
|
---|
1016 | for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | /** Reinitialise. */
|
---|
1020 | public void ReInit(java.io.Reader stream) {
|
---|
1021 | jj_input_stream.ReInit(stream, 1, 1);
|
---|
1022 | token_source.ReInit(jj_input_stream);
|
---|
1023 | token = new Token();
|
---|
1024 | jj_ntk = -1;
|
---|
1025 | jj_gen = 0;
|
---|
1026 | for (int i = 0; i < 35; i++) jj_la1[i] = -1;
|
---|
1027 | for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | /** Constructor with generated Token Manager. */
|
---|
1031 | public MapCSSParser(MapCSSParserTokenManager tm) {
|
---|
1032 | token_source = tm;
|
---|
1033 | token = new Token();
|
---|
1034 | jj_ntk = -1;
|
---|
1035 | jj_gen = 0;
|
---|
1036 | for (int i = 0; i < 35; i++) jj_la1[i] = -1;
|
---|
1037 | for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | /** Reinitialise. */
|
---|
1041 | public void ReInit(MapCSSParserTokenManager tm) {
|
---|
1042 | token_source = tm;
|
---|
1043 | token = new Token();
|
---|
1044 | jj_ntk = -1;
|
---|
1045 | jj_gen = 0;
|
---|
1046 | for (int i = 0; i < 35; i++) jj_la1[i] = -1;
|
---|
1047 | for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
---|
1048 | }
|
---|
1049 |
|
---|
1050 | private Token jj_consume_token(int kind) throws ParseException {
|
---|
1051 | Token oldToken;
|
---|
1052 | if ((oldToken = token).next != null) token = token.next;
|
---|
1053 | else token = token.next = token_source.getNextToken();
|
---|
1054 | jj_ntk = -1;
|
---|
1055 | if (token.kind == kind) {
|
---|
1056 | jj_gen++;
|
---|
1057 | if (++jj_gc > 100) {
|
---|
1058 | jj_gc = 0;
|
---|
1059 | for (int i = 0; i < jj_2_rtns.length; i++) {
|
---|
1060 | JJCalls c = jj_2_rtns[i];
|
---|
1061 | while (c != null) {
|
---|
1062 | if (c.gen < jj_gen) c.first = null;
|
---|
1063 | c = c.next;
|
---|
1064 | }
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 | return token;
|
---|
1068 | }
|
---|
1069 | token = oldToken;
|
---|
1070 | jj_kind = kind;
|
---|
1071 | throw generateParseException();
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | static private final class LookaheadSuccess extends java.lang.Error { }
|
---|
1075 | final private LookaheadSuccess jj_ls = new LookaheadSuccess();
|
---|
1076 | private boolean jj_scan_token(int kind) {
|
---|
1077 | if (jj_scanpos == jj_lastpos) {
|
---|
1078 | jj_la--;
|
---|
1079 | if (jj_scanpos.next == null) {
|
---|
1080 | jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
|
---|
1081 | } else {
|
---|
1082 | jj_lastpos = jj_scanpos = jj_scanpos.next;
|
---|
1083 | }
|
---|
1084 | } else {
|
---|
1085 | jj_scanpos = jj_scanpos.next;
|
---|
1086 | }
|
---|
1087 | if (jj_rescan) {
|
---|
1088 | int i = 0; Token tok = token;
|
---|
1089 | while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
|
---|
1090 | if (tok != null) jj_add_error_token(kind, i);
|
---|
1091 | }
|
---|
1092 | if (jj_scanpos.kind != kind) return true;
|
---|
1093 | if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
|
---|
1094 | return false;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 |
|
---|
1098 | /** Get the next Token. */
|
---|
1099 | final public Token getNextToken() {
|
---|
1100 | if (token.next != null) token = token.next;
|
---|
1101 | else token = token.next = token_source.getNextToken();
|
---|
1102 | jj_ntk = -1;
|
---|
1103 | jj_gen++;
|
---|
1104 | return token;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | /** Get the specific Token. */
|
---|
1108 | final public Token getToken(int index) {
|
---|
1109 | Token t = token;
|
---|
1110 | for (int i = 0; i < index; i++) {
|
---|
1111 | if (t.next != null) t = t.next;
|
---|
1112 | else t = t.next = token_source.getNextToken();
|
---|
1113 | }
|
---|
1114 | return t;
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | private int jj_ntk() {
|
---|
1118 | if ((jj_nt=token.next) == null)
|
---|
1119 | return (jj_ntk = (token.next=token_source.getNextToken()).kind);
|
---|
1120 | else
|
---|
1121 | return (jj_ntk = jj_nt.kind);
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | private java.util.List jj_expentries = new java.util.ArrayList();
|
---|
1125 | private int[] jj_expentry;
|
---|
1126 | private int jj_kind = -1;
|
---|
1127 | private int[] jj_lasttokens = new int[100];
|
---|
1128 | private int jj_endpos;
|
---|
1129 |
|
---|
1130 | private void jj_add_error_token(int kind, int pos) {
|
---|
1131 | if (pos >= 100) return;
|
---|
1132 | if (pos == jj_endpos + 1) {
|
---|
1133 | jj_lasttokens[jj_endpos++] = kind;
|
---|
1134 | } else if (jj_endpos != 0) {
|
---|
1135 | jj_expentry = new int[jj_endpos];
|
---|
1136 | for (int i = 0; i < jj_endpos; i++) {
|
---|
1137 | jj_expentry[i] = jj_lasttokens[i];
|
---|
1138 | }
|
---|
1139 | jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) {
|
---|
1140 | int[] oldentry = (int[])(it.next());
|
---|
1141 | if (oldentry.length == jj_expentry.length) {
|
---|
1142 | for (int i = 0; i < jj_expentry.length; i++) {
|
---|
1143 | if (oldentry[i] != jj_expentry[i]) {
|
---|
1144 | continue jj_entries_loop;
|
---|
1145 | }
|
---|
1146 | }
|
---|
1147 | jj_expentries.add(jj_expentry);
|
---|
1148 | break jj_entries_loop;
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 | if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
|
---|
1152 | }
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 | /** Generate ParseException. */
|
---|
1156 | public ParseException generateParseException() {
|
---|
1157 | jj_expentries.clear();
|
---|
1158 | boolean[] la1tokens = new boolean[33];
|
---|
1159 | if (jj_kind >= 0) {
|
---|
1160 | la1tokens[jj_kind] = true;
|
---|
1161 | jj_kind = -1;
|
---|
1162 | }
|
---|
1163 | for (int i = 0; i < 35; i++) {
|
---|
1164 | if (jj_la1[i] == jj_gen) {
|
---|
1165 | for (int j = 0; j < 32; j++) {
|
---|
1166 | if ((jj_la1_0[i] & (1<<j)) != 0) {
|
---|
1167 | la1tokens[j] = true;
|
---|
1168 | }
|
---|
1169 | if ((jj_la1_1[i] & (1<<j)) != 0) {
|
---|
1170 | la1tokens[32+j] = true;
|
---|
1171 | }
|
---|
1172 | }
|
---|
1173 | }
|
---|
1174 | }
|
---|
1175 | for (int i = 0; i < 33; i++) {
|
---|
1176 | if (la1tokens[i]) {
|
---|
1177 | jj_expentry = new int[1];
|
---|
1178 | jj_expentry[0] = i;
|
---|
1179 | jj_expentries.add(jj_expentry);
|
---|
1180 | }
|
---|
1181 | }
|
---|
1182 | jj_endpos = 0;
|
---|
1183 | jj_rescan_token();
|
---|
1184 | jj_add_error_token(0, 0);
|
---|
1185 | int[][] exptokseq = new int[jj_expentries.size()][];
|
---|
1186 | for (int i = 0; i < jj_expentries.size(); i++) {
|
---|
1187 | exptokseq[i] = (int[])jj_expentries.get(i);
|
---|
1188 | }
|
---|
1189 | return new ParseException(token, exptokseq, tokenImage);
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | /** Enable tracing. */
|
---|
1193 | final public void enable_tracing() {
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | /** Disable tracing. */
|
---|
1197 | final public void disable_tracing() {
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | private void jj_rescan_token() {
|
---|
1201 | jj_rescan = true;
|
---|
1202 | for (int i = 0; i < 4; i++) {
|
---|
1203 | try {
|
---|
1204 | JJCalls p = jj_2_rtns[i];
|
---|
1205 | do {
|
---|
1206 | if (p.gen > jj_gen) {
|
---|
1207 | jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
|
---|
1208 | switch (i) {
|
---|
1209 | case 0: jj_3_1(); break;
|
---|
1210 | case 1: jj_3_2(); break;
|
---|
1211 | case 2: jj_3_3(); break;
|
---|
1212 | case 3: jj_3_4(); break;
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 | p = p.next;
|
---|
1216 | } while (p != null);
|
---|
1217 | } catch(LookaheadSuccess ls) { }
|
---|
1218 | }
|
---|
1219 | jj_rescan = false;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | private void jj_save(int index, int xla) {
|
---|
1223 | JJCalls p = jj_2_rtns[index];
|
---|
1224 | while (p.gen > jj_gen) {
|
---|
1225 | if (p.next == null) { p = p.next = new JJCalls(); break; }
|
---|
1226 | p = p.next;
|
---|
1227 | }
|
---|
1228 | p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | static final class JJCalls {
|
---|
1232 | int gen;
|
---|
1233 | Token first;
|
---|
1234 | int arg;
|
---|
1235 | JJCalls next;
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | }
|
---|