source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParserTokenManager.java@ 3967

Last change on this file since 3967 was 3967, checked in by bastiK, 13 years ago

MapCSS: an identifier literal at the right side of a declaration is now parsed as Keyword and not as String. This means 'color: "blue";' does not work any longer, but you have to write 'color: blue;'. This is useful for future extensions.

  • Property svn:eol-style set to native
File size: 19.2 KB
Line 
1/* Generated By:JavaCC: Do not edit this line. MapCSSParserTokenManager.java */
2package org.openstreetmap.josm.gui.mappaint.mapcss.parser;
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6import org.openstreetmap.josm.gui.mappaint.Keyword;
7import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
8import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
9import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
10import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
11import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
12import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
13import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.FunctionExpression;
14import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.LiteralExpression;
15import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.DescendentSelector;
16import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
17import org.openstreetmap.josm.tools.Pair;
18
19/** Token Manager. */
20public class MapCSSParserTokenManager implements MapCSSParserConstants
21{
22
23 /** Debug output. */
24 public java.io.PrintStream debugStream = System.out;
25 /** Set debug output. */
26 public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
27private final int jjStopStringLiteralDfa_0(int pos, long active0)
28{
29 switch (pos)
30 {
31 case 0:
32 if ((active0 & 0x2000000800L) != 0L)
33 return 14;
34 return -1;
35 default :
36 return -1;
37 }
38}
39private final int jjStartNfa_0(int pos, long active0)
40{
41 return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
42}
43private int jjStopAtPos(int pos, int kind)
44{
45 jjmatchedKind = kind;
46 jjmatchedPos = pos;
47 return pos + 1;
48}
49private int jjMoveStringLiteralDfa0_0()
50{
51 switch(curChar)
52 {
53 case 33:
54 return jjStopAtPos(0, 23);
55 case 36:
56 return jjStopAtPos(0, 35);
57 case 38:
58 return jjStopAtPos(0, 33);
59 case 40:
60 return jjStopAtPos(0, 16);
61 case 41:
62 return jjStopAtPos(0, 17);
63 case 42:
64 return jjStopAtPos(0, 10);
65 case 43:
66 return jjStopAtPos(0, 31);
67 case 44:
68 return jjStopAtPos(0, 28);
69 case 45:
70 return jjStopAtPos(0, 32);
71 case 47:
72 jjmatchedKind = 11;
73 return jjMoveStringLiteralDfa1_0(0x2000000000L);
74 case 58:
75 jjmatchedKind = 25;
76 return jjMoveStringLiteralDfa1_0(0x4000000L);
77 case 59:
78 return jjStopAtPos(0, 27);
79 case 60:
80 jjmatchedKind = 21;
81 return jjMoveStringLiteralDfa1_0(0x80000L);
82 case 61:
83 return jjStopAtPos(0, 22);
84 case 62:
85 jjmatchedKind = 20;
86 return jjMoveStringLiteralDfa1_0(0x40000L);
87 case 63:
88 return jjStopAtPos(0, 34);
89 case 91:
90 return jjStopAtPos(0, 14);
91 case 93:
92 return jjStopAtPos(0, 15);
93 case 94:
94 return jjStopAtPos(0, 36);
95 case 123:
96 return jjStopAtPos(0, 12);
97 case 124:
98 jjmatchedKind = 29;
99 return jjMoveStringLiteralDfa1_0(0x40000000L);
100 case 125:
101 return jjStopAtPos(0, 13);
102 case 126:
103 return jjStopAtPos(0, 24);
104 default :
105 return jjMoveNfa_0(0, 0);
106 }
107}
108private int jjMoveStringLiteralDfa1_0(long active0)
109{
110 try { curChar = input_stream.readChar(); }
111 catch(java.io.IOException e) {
112 jjStopStringLiteralDfa_0(0, active0);
113 return 1;
114 }
115 switch(curChar)
116 {
117 case 42:
118 if ((active0 & 0x2000000000L) != 0L)
119 return jjStopAtPos(1, 37);
120 break;
121 case 58:
122 if ((active0 & 0x4000000L) != 0L)
123 return jjStopAtPos(1, 26);
124 break;
125 case 61:
126 if ((active0 & 0x40000L) != 0L)
127 return jjStopAtPos(1, 18);
128 else if ((active0 & 0x80000L) != 0L)
129 return jjStopAtPos(1, 19);
130 break;
131 case 122:
132 if ((active0 & 0x40000000L) != 0L)
133 return jjStopAtPos(1, 30);
134 break;
135 default :
136 break;
137 }
138 return jjStartNfa_0(0, active0);
139}
140static final long[] jjbitVec0 = {
141 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
142};
143static final long[] jjbitVec2 = {
144 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
145};
146private int jjMoveNfa_0(int startState, int curPos)
147{
148 int startsAt = 0;
149 jjnewStateCnt = 30;
150 int i = 1;
151 jjstateSet[0] = startState;
152 int kind = 0x7fffffff;
153 for (;;)
154 {
155 if (++jjround == 0x7fffffff)
156 ReInitRounds();
157 if (curChar < 64)
158 {
159 long l = 1L << curChar;
160 do
161 {
162 switch(jjstateSet[--i])
163 {
164 case 14:
165 if ((0xffff7bff00000000L & l) != 0L)
166 jjCheckNAddStates(0, 2);
167 break;
168 case 0:
169 if ((0x3ff000000000000L & l) != 0L)
170 {
171 if (kind > 3)
172 kind = 3;
173 jjCheckNAddTwoStates(4, 5);
174 }
175 else if ((0x100003600L & l) != 0L)
176 {
177 if (kind > 9)
178 kind = 9;
179 jjCheckNAdd(29);
180 }
181 else if (curChar == 35)
182 jjstateSet[jjnewStateCnt++] = 22;
183 else if (curChar == 47)
184 jjAddStates(3, 4);
185 else if (curChar == 34)
186 jjCheckNAddStates(5, 7);
187 if ((0x3fe000000000000L & l) != 0L)
188 {
189 if (kind > 2)
190 kind = 2;
191 jjCheckNAdd(3);
192 }
193 break;
194 case 1:
195 if ((0x3ff200000000000L & l) == 0L)
196 break;
197 if (kind > 1)
198 kind = 1;
199 jjstateSet[jjnewStateCnt++] = 1;
200 break;
201 case 2:
202 if ((0x3fe000000000000L & l) == 0L)
203 break;
204 if (kind > 2)
205 kind = 2;
206 jjCheckNAdd(3);
207 break;
208 case 3:
209 if ((0x3ff000000000000L & l) == 0L)
210 break;
211 if (kind > 2)
212 kind = 2;
213 jjCheckNAdd(3);
214 break;
215 case 4:
216 if ((0x3ff000000000000L & l) == 0L)
217 break;
218 if (kind > 3)
219 kind = 3;
220 jjCheckNAddTwoStates(4, 5);
221 break;
222 case 5:
223 if (curChar == 46)
224 jjCheckNAdd(6);
225 break;
226 case 6:
227 if ((0x3ff000000000000L & l) == 0L)
228 break;
229 if (kind > 3)
230 kind = 3;
231 jjCheckNAdd(6);
232 break;
233 case 7:
234 case 11:
235 if (curChar == 34)
236 jjCheckNAddStates(5, 7);
237 break;
238 case 8:
239 if ((0xfffffffb00000000L & l) != 0L)
240 jjCheckNAddStates(5, 7);
241 break;
242 case 9:
243 if (curChar == 34 && kind > 4)
244 kind = 4;
245 break;
246 case 13:
247 if (curChar == 47)
248 jjAddStates(3, 4);
249 break;
250 case 15:
251 if ((0xffff7fff00000000L & l) != 0L)
252 jjCheckNAddStates(0, 2);
253 break;
254 case 16:
255 if (curChar == 47 && kind > 6)
256 kind = 6;
257 break;
258 case 19:
259 if (curChar == 47)
260 jjCheckNAddStates(0, 2);
261 break;
262 case 21:
263 if (curChar == 35)
264 jjstateSet[jjnewStateCnt++] = 22;
265 break;
266 case 22:
267 if ((0x3ff000000000000L & l) != 0L)
268 jjAddStates(8, 9);
269 break;
270 case 23:
271 if ((0x3ff000000000000L & l) != 0L)
272 jjstateSet[jjnewStateCnt++] = 24;
273 break;
274 case 24:
275 if ((0x3ff000000000000L & l) != 0L)
276 jjstateSet[jjnewStateCnt++] = 25;
277 break;
278 case 25:
279 if ((0x3ff000000000000L & l) != 0L)
280 jjstateSet[jjnewStateCnt++] = 26;
281 break;
282 case 26:
283 case 28:
284 if ((0x3ff000000000000L & l) != 0L)
285 jjCheckNAdd(27);
286 break;
287 case 27:
288 if ((0x3ff000000000000L & l) != 0L && kind > 8)
289 kind = 8;
290 break;
291 case 29:
292 if ((0x100003600L & l) == 0L)
293 break;
294 if (kind > 9)
295 kind = 9;
296 jjCheckNAdd(29);
297 break;
298 default : break;
299 }
300 } while(i != startsAt);
301 }
302 else if (curChar < 128)
303 {
304 long l = 1L << (curChar & 077);
305 do
306 {
307 switch(jjstateSet[--i])
308 {
309 case 14:
310 if ((0x7fffffffefffffffL & l) != 0L)
311 jjCheckNAddStates(0, 2);
312 else if (curChar == 92)
313 jjCheckNAddTwoStates(19, 18);
314 break;
315 case 0:
316 case 1:
317 if ((0x7fffffe87fffffeL & l) == 0L)
318 break;
319 if (kind > 1)
320 kind = 1;
321 jjCheckNAdd(1);
322 break;
323 case 8:
324 if ((0x7fffffffefffffffL & l) != 0L)
325 jjCheckNAddStates(5, 7);
326 break;
327 case 10:
328 if (curChar == 92)
329 jjAddStates(10, 11);
330 break;
331 case 12:
332 if (curChar == 92)
333 jjCheckNAddStates(5, 7);
334 break;
335 case 15:
336 if ((0x7fffffffefffffffL & l) != 0L)
337 jjCheckNAddStates(0, 2);
338 break;
339 case 17:
340 if (curChar == 92)
341 jjCheckNAddTwoStates(18, 19);
342 break;
343 case 18:
344 if (curChar == 92)
345 jjCheckNAddStates(0, 2);
346 break;
347 case 20:
348 if (curChar == 92)
349 jjCheckNAddTwoStates(19, 18);
350 break;
351 case 22:
352 if ((0x7e0000007eL & l) != 0L)
353 jjAddStates(8, 9);
354 break;
355 case 23:
356 if ((0x7e0000007eL & l) != 0L)
357 jjstateSet[jjnewStateCnt++] = 24;
358 break;
359 case 24:
360 if ((0x7e0000007eL & l) != 0L)
361 jjstateSet[jjnewStateCnt++] = 25;
362 break;
363 case 25:
364 if ((0x7e0000007eL & l) != 0L)
365 jjstateSet[jjnewStateCnt++] = 26;
366 break;
367 case 26:
368 case 28:
369 if ((0x7e0000007eL & l) != 0L)
370 jjCheckNAdd(27);
371 break;
372 case 27:
373 if ((0x7e0000007eL & l) != 0L && kind > 8)
374 kind = 8;
375 break;
376 default : break;
377 }
378 } while(i != startsAt);
379 }
380 else
381 {
382 int hiByte = (int)(curChar >> 8);
383 int i1 = hiByte >> 6;
384 long l1 = 1L << (hiByte & 077);
385 int i2 = (curChar & 0xff) >> 6;
386 long l2 = 1L << (curChar & 077);
387 do
388 {
389 switch(jjstateSet[--i])
390 {
391 case 14:
392 case 15:
393 if (jjCanMove_0(hiByte, i1, i2, l1, l2))
394 jjCheckNAddStates(0, 2);
395 break;
396 case 8:
397 if (jjCanMove_0(hiByte, i1, i2, l1, l2))
398 jjAddStates(5, 7);
399 break;
400 default : break;
401 }
402 } while(i != startsAt);
403 }
404 if (kind != 0x7fffffff)
405 {
406 jjmatchedKind = kind;
407 jjmatchedPos = curPos;
408 kind = 0x7fffffff;
409 }
410 ++curPos;
411 if ((i = jjnewStateCnt) == (startsAt = 30 - (jjnewStateCnt = startsAt)))
412 return curPos;
413 try { curChar = input_stream.readChar(); }
414 catch(java.io.IOException e) { return curPos; }
415 }
416}
417private int jjMoveStringLiteralDfa0_1()
418{
419 switch(curChar)
420 {
421 case 42:
422 return jjMoveStringLiteralDfa1_1(0x8000000000L);
423 default :
424 return 1;
425 }
426}
427private int jjMoveStringLiteralDfa1_1(long active0)
428{
429 try { curChar = input_stream.readChar(); }
430 catch(java.io.IOException e) {
431 return 1;
432 }
433 switch(curChar)
434 {
435 case 47:
436 if ((active0 & 0x8000000000L) != 0L)
437 return jjStopAtPos(1, 39);
438 break;
439 default :
440 return 2;
441 }
442 return 2;
443}
444static final int[] jjnextStates = {
445 15, 16, 17, 14, 20, 8, 9, 10, 23, 28, 11, 12,
446};
447private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
448{
449 switch(hiByte)
450 {
451 case 0:
452 return ((jjbitVec2[i2] & l2) != 0L);
453 default :
454 if ((jjbitVec0[i1] & l1) != 0L)
455 return true;
456 return false;
457 }
458}
459
460/** Token literal values. */
461public static final String[] jjstrLiteralImages = {
462"", null, null, null, null, null, null, null, null, null, "\52", "\57",
463"\173", "\175", "\133", "\135", "\50", "\51", "\76\75", "\74\75", "\76", "\74", "\75",
464"\41", "\176", "\72", "\72\72", "\73", "\54", "\174", "\174\172", "\53", "\55",
465"\46", "\77", "\44", "\136", "\57\52", null, "\52\57", null, };
466
467/** Lexer state names. */
468public static final String[] lexStateNames = {
469 "DEFAULT",
470 "COMMENT",
471};
472
473/** Lex State array. */
474public static final int[] jjnewLexState = {
475 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
476 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 0, -1,
477};
478static final long[] jjtoToken = {
479 0xffffffff5fL,
480};
481static final long[] jjtoSkip = {
482 0x10000000000L,
483};
484protected SimpleCharStream input_stream;
485private final int[] jjrounds = new int[30];
486private final int[] jjstateSet = new int[60];
487protected char curChar;
488/** Constructor. */
489public MapCSSParserTokenManager(SimpleCharStream stream){
490 if (SimpleCharStream.staticFlag)
491 throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
492 input_stream = stream;
493}
494
495/** Constructor. */
496public MapCSSParserTokenManager(SimpleCharStream stream, int lexState){
497 this(stream);
498 SwitchTo(lexState);
499}
500
501/** Reinitialise parser. */
502public void ReInit(SimpleCharStream stream)
503{
504 jjmatchedPos = jjnewStateCnt = 0;
505 curLexState = defaultLexState;
506 input_stream = stream;
507 ReInitRounds();
508}
509private void ReInitRounds()
510{
511 int i;
512 jjround = 0x80000001;
513 for (i = 30; i-- > 0;)
514 jjrounds[i] = 0x80000000;
515}
516
517/** Reinitialise parser. */
518public void ReInit(SimpleCharStream stream, int lexState)
519{
520 ReInit(stream);
521 SwitchTo(lexState);
522}
523
524/** Switch to specified lex state. */
525public void SwitchTo(int lexState)
526{
527 if (lexState >= 2 || lexState < 0)
528 throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
529 else
530 curLexState = lexState;
531}
532
533protected Token jjFillToken()
534{
535 final Token t;
536 final String curTokenImage;
537 final int beginLine;
538 final int endLine;
539 final int beginColumn;
540 final int endColumn;
541 String im = jjstrLiteralImages[jjmatchedKind];
542 curTokenImage = (im == null) ? input_stream.GetImage() : im;
543 beginLine = input_stream.getBeginLine();
544 beginColumn = input_stream.getBeginColumn();
545 endLine = input_stream.getEndLine();
546 endColumn = input_stream.getEndColumn();
547 t = Token.newToken(jjmatchedKind, curTokenImage);
548
549 t.beginLine = beginLine;
550 t.endLine = endLine;
551 t.beginColumn = beginColumn;
552 t.endColumn = endColumn;
553
554 return t;
555}
556
557int curLexState = 0;
558int defaultLexState = 0;
559int jjnewStateCnt;
560int jjround;
561int jjmatchedPos;
562int jjmatchedKind;
563
564/** Get the next Token. */
565public Token getNextToken()
566{
567 Token matchedToken;
568 int curPos = 0;
569
570 EOFLoop :
571 for (;;)
572 {
573 try
574 {
575 curChar = input_stream.BeginToken();
576 }
577 catch(java.io.IOException e)
578 {
579 jjmatchedKind = 0;
580 matchedToken = jjFillToken();
581 return matchedToken;
582 }
583
584 switch(curLexState)
585 {
586 case 0:
587 jjmatchedKind = 0x7fffffff;
588 jjmatchedPos = 0;
589 curPos = jjMoveStringLiteralDfa0_0();
590 if (jjmatchedPos == 0 && jjmatchedKind > 38)
591 {
592 jjmatchedKind = 38;
593 }
594 break;
595 case 1:
596 jjmatchedKind = 0x7fffffff;
597 jjmatchedPos = 0;
598 curPos = jjMoveStringLiteralDfa0_1();
599 if (jjmatchedPos == 0 && jjmatchedKind > 40)
600 {
601 jjmatchedKind = 40;
602 }
603 break;
604 }
605 if (jjmatchedKind != 0x7fffffff)
606 {
607 if (jjmatchedPos + 1 < curPos)
608 input_stream.backup(curPos - jjmatchedPos - 1);
609 if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
610 {
611 matchedToken = jjFillToken();
612 if (jjnewLexState[jjmatchedKind] != -1)
613 curLexState = jjnewLexState[jjmatchedKind];
614 return matchedToken;
615 }
616 else
617 {
618 if (jjnewLexState[jjmatchedKind] != -1)
619 curLexState = jjnewLexState[jjmatchedKind];
620 continue EOFLoop;
621 }
622 }
623 int error_line = input_stream.getEndLine();
624 int error_column = input_stream.getEndColumn();
625 String error_after = null;
626 boolean EOFSeen = false;
627 try { input_stream.readChar(); input_stream.backup(1); }
628 catch (java.io.IOException e1) {
629 EOFSeen = true;
630 error_after = curPos <= 1 ? "" : input_stream.GetImage();
631 if (curChar == '\n' || curChar == '\r') {
632 error_line++;
633 error_column = 0;
634 }
635 else
636 error_column++;
637 }
638 if (!EOFSeen) {
639 input_stream.backup(1);
640 error_after = curPos <= 1 ? "" : input_stream.GetImage();
641 }
642 throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
643 }
644}
645
646private void jjCheckNAdd(int state)
647{
648 if (jjrounds[state] != jjround)
649 {
650 jjstateSet[jjnewStateCnt++] = state;
651 jjrounds[state] = jjround;
652 }
653}
654private void jjAddStates(int start, int end)
655{
656 do {
657 jjstateSet[jjnewStateCnt++] = jjnextStates[start];
658 } while (start++ != end);
659}
660private void jjCheckNAddTwoStates(int state1, int state2)
661{
662 jjCheckNAdd(state1);
663 jjCheckNAdd(state2);
664}
665
666private void jjCheckNAddStates(int start, int end)
667{
668 do {
669 jjCheckNAdd(jjnextStates[start]);
670 } while (start++ != end);
671}
672
673}
Note: See TracBrowser for help on using the repository browser.