1 using System;
2 using System.Lex;
3 using JsonTokens;
4
5
6
7 public class JsonLexer : System.Lex.Lexer
8 {
9 public JsonLexer(const ustring& content_, const string& fileName_, int fileIndex_) :
10 base(content_, fileName_, fileIndex_)
11 {
12 JsonClassMap.Init();
13 }
14 public JsonLexer(const uchar* start_, const uchar* end_, const string& fileName_, int fileIndex_) :
15 base(start_, end_, fileName_, fileIndex_)
16 {
17 JsonClassMap.Init();
18 }
19 public override int NextState(int state, uchar c)
20 {
21 int i = JsonClassMap.GetClass(c);
22 switch (state)
23 {
24 case 0:
25 {
26 switch (i)
27 {
28 case 2: case 3: case 4: case 5:
29 {
30 return 1;
31 }
32 case 7:
33 {
34 return 2;
35 }
36 case 10:
37 {
38 return 3;
39 }
40 case 12:
41 {
42 return 4;
43 }
44 case 16:
45 {
46 return 5;
47 }
48 case 20:
49 {
50 return 6;
51 }
52 case 22:
53 {
54 return 7;
55 }
56 case 23:
57 {
58 return 8;
59 }
60 case 24:
61 {
62 return 9;
63 }
64 case 25:
65 {
66 return 10;
67 }
68 case 26:
69 {
70 return 11;
71 }
72 case 27:
73 {
74 return 12;
75 }
76 case 28:
77 {
78 return 13;
79 }
80 default:
81 {
82 return -1;
83 }
84 }
85 return -1;
86 }
87 case 13:
88 {
89 System.Lex.Lexeme prevMatch = token.match;
90 token.match = lexeme;
91 int tokenId = GetTokenId(8);
92 if (tokenId == CONTINUE_TOKEN)
93 {
94 token.id = CONTINUE_TOKEN;
95 return -1;
96 }
97 else
98 {
99 if (tokenId != INVALID_TOKEN)
100 {
101 token.id = tokenId;
102 }
103 else
104 {
105 token.match = prevMatch;
106 }
107 }
108 return -1;
109 }
110 case 12:
111 {
112 System.Lex.Lexeme prevMatch = token.match;
113 token.match = lexeme;
114 int tokenId = GetTokenId(7);
115 if (tokenId == CONTINUE_TOKEN)
116 {
117 token.id = CONTINUE_TOKEN;
118 return -1;
119 }
120 else
121 {
122 if (tokenId != INVALID_TOKEN)
123 {
124 token.id = tokenId;
125 }
126 else
127 {
128 token.match = prevMatch;
129 }
130 }
131 return -1;
132 }
133 case 11:
134 {
135 System.Lex.Lexeme prevMatch = token.match;
136 token.match = lexeme;
137 int tokenId = GetTokenId(6);
138 if (tokenId == CONTINUE_TOKEN)
139 {
140 token.id = CONTINUE_TOKEN;
141 return -1;
142 }
143 else
144 {
145 if (tokenId != INVALID_TOKEN)
146 {
147 token.id = tokenId;
148 }
149 else
150 {
151 token.match = prevMatch;
152 }
153 }
154 return -1;
155 }
156 case 10:
157 {
158 System.Lex.Lexeme prevMatch = token.match;
159 token.match = lexeme;
160 int tokenId = GetTokenId(5);
161 if (tokenId == CONTINUE_TOKEN)
162 {
163 token.id = CONTINUE_TOKEN;
164 return -1;
165 }
166 else
167 {
168 if (tokenId != INVALID_TOKEN)
169 {
170 token.id = tokenId;
171 }
172 else
173 {
174 token.match = prevMatch;
175 }
176 }
177 return -1;
178 }
179 case 9:
180 {
181 System.Lex.Lexeme prevMatch = token.match;
182 token.match = lexeme;
183 int tokenId = GetTokenId(4);
184 if (tokenId == CONTINUE_TOKEN)
185 {
186 token.id = CONTINUE_TOKEN;
187 return -1;
188 }
189 else
190 {
191 if (tokenId != INVALID_TOKEN)
192 {
193 token.id = tokenId;
194 }
195 else
196 {
197 token.match = prevMatch;
198 }
199 }
200 return -1;
201 }
202 case 8:
203 {
204 System.Lex.Lexeme prevMatch = token.match;
205 token.match = lexeme;
206 int tokenId = GetTokenId(3);
207 if (tokenId == CONTINUE_TOKEN)
208 {
209 token.id = CONTINUE_TOKEN;
210 return -1;
211 }
212 else
213 {
214 if (tokenId != INVALID_TOKEN)
215 {
216 token.id = tokenId;
217 }
218 else
219 {
220 token.match = prevMatch;
221 }
222 }
223 return -1;
224 }
225 case 7:
226 {
227 System.Lex.Lexeme prevMatch = token.match;
228 token.match = lexeme;
229 int tokenId = GetTokenId(2);
230 if (tokenId == CONTINUE_TOKEN)
231 {
232 token.id = CONTINUE_TOKEN;
233 return -1;
234 }
235 else
236 {
237 if (tokenId != INVALID_TOKEN)
238 {
239 token.id = tokenId;
240 }
241 else
242 {
243 token.match = prevMatch;
244 }
245 }
246 switch (i)
247 {
248 case 22:
249 {
250 return 7;
251 }
252 case 17:
253 {
254 return 14;
255 }
256 case 18: case 19:
257 {
258 return 15;
259 }
260 default:
261 {
262 return -1;
263 }
264 }
265 return -1;
266 }
267 case 15:
268 {
269 switch (i)
270 {
271 case 20: case 21:
272 {
273 return 16;
274 }
275 case 22:
276 {
277 return 17;
278 }
279 default:
280 {
281 return -1;
282 }
283 }
284 return -1;
285 }
286 case 17:
287 {
288 System.Lex.Lexeme prevMatch = token.match;
289 token.match = lexeme;
290 int tokenId = GetTokenId(2);
291 if (tokenId == CONTINUE_TOKEN)
292 {
293 token.id = CONTINUE_TOKEN;
294 return -1;
295 }
296 else
297 {
298 if (tokenId != INVALID_TOKEN)
299 {
300 token.id = tokenId;
301 }
302 else
303 {
304 token.match = prevMatch;
305 }
306 }
307 switch (i)
308 {
309 case 22:
310 {
311 return 17;
312 }
313 default:
314 {
315 return -1;
316 }
317 }
318 return -1;
319 }
320 case 16:
321 {
322 switch (i)
323 {
324 case 22:
325 {
326 return 17;
327 }
328 default:
329 {
330 return -1;
331 }
332 }
333 return -1;
334 }
335 case 14:
336 {
337 switch (i)
338 {
339 case 22:
340 {
341 return 18;
342 }
343 default:
344 {
345 return -1;
346 }
347 }
348 return -1;
349 }
350 case 18:
351 {
352 System.Lex.Lexeme prevMatch = token.match;
353 token.match = lexeme;
354 int tokenId = GetTokenId(2);
355 if (tokenId == CONTINUE_TOKEN)
356 {
357 token.id = CONTINUE_TOKEN;
358 return -1;
359 }
360 else
361 {
362 if (tokenId != INVALID_TOKEN)
363 {
364 token.id = tokenId;
365 }
366 else
367 {
368 token.match = prevMatch;
369 }
370 }
371 switch (i)
372 {
373 case 18: case 19:
374 {
375 return 15;
376 }
377 case 22:
378 {
379 return 18;
380 }
381 default:
382 {
383 return -1;
384 }
385 }
386 return -1;
387 }
388 case 6:
389 {
390 switch (i)
391 {
392 case 22:
393 {
394 return 7;
395 }
396 default:
397 {
398 return -1;
399 }
400 }
401 return -1;
402 }
403 case 5:
404 {
405 switch (i)
406 {
407 case 29:
408 {
409 return 19;
410 }
411 default:
412 {
413 return -1;
414 }
415 }
416 return -1;
417 }
418 case 19:
419 {
420 switch (i)
421 {
422 case 30:
423 {
424 return 20;
425 }
426 default:
427 {
428 return -1;
429 }
430 }
431 return -1;
432 }
433 case 20:
434 {
435 switch (i)
436 {
437 case 31:
438 {
439 return 21;
440 }
441 default:
442 {
443 return -1;
444 }
445 }
446 return -1;
447 }
448 case 21:
449 {
450 switch (i)
451 {
452 case 18:
453 {
454 return 22;
455 }
456 default:
457 {
458 return -1;
459 }
460 }
461 return -1;
462 }
463 case 22:
464 {
465 System.Lex.Lexeme prevMatch = token.match;
466 token.match = lexeme;
467 int tokenId = GetTokenId(10);
468 if (tokenId == CONTINUE_TOKEN)
469 {
470 token.id = CONTINUE_TOKEN;
471 return -1;
472 }
473 else
474 {
475 if (tokenId != INVALID_TOKEN)
476 {
477 token.id = tokenId;
478 }
479 else
480 {
481 token.match = prevMatch;
482 }
483 }
484 return -1;
485 }
486 case 4:
487 {
488 switch (i)
489 {
490 case 11:
491 {
492 return 23;
493 }
494 default:
495 {
496 return -1;
497 }
498 }
499 return -1;
500 }
501 case 23:
502 {
503 switch (i)
504 {
505 case 13:
506 {
507 return 24;
508 }
509 default:
510 {
511 return -1;
512 }
513 }
514 return -1;
515 }
516 case 24:
517 {
518 switch (i)
519 {
520 case 18:
521 {
522 return 25;
523 }
524 default:
525 {
526 return -1;
527 }
528 }
529 return -1;
530 }
531 case 25:
532 {
533 System.Lex.Lexeme prevMatch = token.match;
534 token.match = lexeme;
535 int tokenId = GetTokenId(9);
536 if (tokenId == CONTINUE_TOKEN)
537 {
538 token.id = CONTINUE_TOKEN;
539 return -1;
540 }
541 else
542 {
543 if (tokenId != INVALID_TOKEN)
544 {
545 token.id = tokenId;
546 }
547 else
548 {
549 token.match = prevMatch;
550 }
551 }
552 return -1;
553 }
554 case 3:
555 {
556 switch (i)
557 {
558 case 13:
559 {
560 return 26;
561 }
562 default:
563 {
564 return -1;
565 }
566 }
567 return -1;
568 }
569 case 26:
570 {
571 switch (i)
572 {
573 case 30:
574 {
575 return 27;
576 }
577 default:
578 {
579 return -1;
580 }
581 }
582 return -1;
583 }
584 case 27:
585 {
586 switch (i)
587 {
588 case 30:
589 {
590 return 28;
591 }
592 default:
593 {
594 return -1;
595 }
596 }
597 return -1;
598 }
599 case 28:
600 {
601 System.Lex.Lexeme prevMatch = token.match;
602 token.match = lexeme;
603 int tokenId = GetTokenId(11);
604 if (tokenId == CONTINUE_TOKEN)
605 {
606 token.id = CONTINUE_TOKEN;
607 return -1;
608 }
609 else
610 {
611 if (tokenId != INVALID_TOKEN)
612 {
613 token.id = tokenId;
614 }
615 else
616 {
617 token.match = prevMatch;
618 }
619 }
620 return -1;
621 }
622 case 2:
623 {
624 switch (i)
625 {
626 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
627 {
628 return 29;
629 }
630 case 7:
631 {
632 return 30;
633 }
634 case 8:
635 {
636 return 31;
637 }
638 default:
639 {
640 return -1;
641 }
642 }
643 return -1;
644 }
645 case 31:
646 {
647 switch (i)
648 {
649 case 7: case 8: case 9: case 10: case 11: case 12: case 15: case 16:
650 {
651 return 32;
652 }
653 case 13:
654 {
655 return 33;
656 }
657 default:
658 {
659 return -1;
660 }
661 }
662 return -1;
663 }
664 case 33:
665 {
666 switch (i)
667 {
668 case 14: case 15: case 16: case 18: case 19: case 22: case 29:
669 {
670 return 34;
671 }
672 default:
673 {
674 return -1;
675 }
676 }
677 return -1;
678 }
679 case 34:
680 {
681 switch (i)
682 {
683 case 14: case 15: case 16: case 18: case 19: case 22: case 29:
684 {
685 return 35;
686 }
687 default:
688 {
689 return -1;
690 }
691 }
692 return -1;
693 }
694 case 35:
695 {
696 switch (i)
697 {
698 case 14: case 15: case 16: case 18: case 19: case 22: case 29:
699 {
700 return 36;
701 }
702 default:
703 {
704 return -1;
705 }
706 }
707 return -1;
708 }
709 case 36:
710 {
711 switch (i)
712 {
713 case 14: case 15: case 16: case 18: case 19: case 22: case 29:
714 {
715 return 37;
716 }
717 default:
718 {
719 return -1;
720 }
721 }
722 return -1;
723 }
724 case 37:
725 {
726 switch (i)
727 {
728 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
729 {
730 return 29;
731 }
732 case 7:
733 {
734 return 30;
735 }
736 case 8:
737 {
738 return 31;
739 }
740 default:
741 {
742 return -1;
743 }
744 }
745 return -1;
746 }
747 case 32:
748 {
749 switch (i)
750 {
751 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
752 {
753 return 29;
754 }
755 case 7:
756 {
757 return 30;
758 }
759 case 8:
760 {
761 return 31;
762 }
763 default:
764 {
765 return -1;
766 }
767 }
768 return -1;
769 }
770 case 30:
771 {
772 System.Lex.Lexeme prevMatch = token.match;
773 token.match = lexeme;
774 int tokenId = GetTokenId(1);
775 if (tokenId == CONTINUE_TOKEN)
776 {
777 token.id = CONTINUE_TOKEN;
778 return -1;
779 }
780 else
781 {
782 if (tokenId != INVALID_TOKEN)
783 {
784 token.id = tokenId;
785 }
786 else
787 {
788 token.match = prevMatch;
789 }
790 }
791 return -1;
792 }
793 case 29:
794 {
795 switch (i)
796 {
797 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
798 {
799 return 29;
800 }
801 case 7:
802 {
803 return 30;
804 }
805 case 8:
806 {
807 return 31;
808 }
809 default:
810 {
811 return -1;
812 }
813 }
814 return -1;
815 }
816 case 1:
817 {
818 System.Lex.Lexeme prevMatch = token.match;
819 token.match = lexeme;
820 int tokenId = GetTokenId(0);
821 if (tokenId == CONTINUE_TOKEN)
822 {
823 token.id = CONTINUE_TOKEN;
824 return -1;
825 }
826 else
827 {
828 if (tokenId != INVALID_TOKEN)
829 {
830 token.id = tokenId;
831 }
832 else
833 {
834 token.match = prevMatch;
835 }
836 }
837 switch (i)
838 {
839 case 2: case 3: case 4: case 5:
840 {
841 return 1;
842 }
843 default:
844 {
845 return -1;
846 }
847 }
848 return -1;
849 }
850 }
851 return -1;
852 }
853 private int GetTokenId(int statementIndex)
854 {
855 switch (statementIndex)
856 {
857 case 0:
858 {
859 Retract();
860 break;
861 }
862 case 1:
863 {
864 Retract();
865 return STRING;
866 break;
867 }
868 case 2:
869 {
870 Retract();
871 return NUMBER;
872 break;
873 }
874 case 3:
875 {
876 Retract();
877 return LBRACKET;
878 break;
879 }
880 case 4:
881 {
882 Retract();
883 return RBRACKET;
884 break;
885 }
886 case 5:
887 {
888 Retract();
889 return LBRACE;
890 break;
891 }
892 case 6:
893 {
894 Retract();
895 return RBRACE;
896 break;
897 }
898 case 7:
899 {
900 Retract();
901 return COMMA;
902 break;
903 }
904 case 8:
905 {
906 Retract();
907 return COLON;
908 break;
909 }
910 case 9:
911 {
912 Retract();
913 return TRUE;
914 break;
915 }
916 case 10:
917 {
918 Retract();
919 return FALSE;
920 break;
921 }
922 case 11:
923 {
924 Retract();
925 return NULL;
926 break;
927 }
928 }
929 return CONTINUE_TOKEN;
930 }
931 }