452d452d9c7f55baf54a563b3a0fd010f1ccf44c
[nit.git] / src / parser / lexer.nit
1 # Lexer and its tokens.
2 # This file was generated by SableCC (http://www.sablecc.org/).
3 package lexer
4
5 intrude import parser_nodes
6 private import tables
7
8 redef class Token
9 readable var _text: String
10
11 fun parser_index: Int is abstract
12
13 redef fun to_s: String do
14 return "'{_text}'"
15 end
16 end
17
18 redef class TEol
19 redef fun parser_index: Int
20 do
21 return 0
22 end
23
24 init init_tk(text: String, loc: Location)
25 do
26 _text = text
27 _location = loc
28 end
29 end
30
31 redef class TComment
32 redef fun parser_index: Int
33 do
34 return 1
35 end
36
37 init init_tk(text: String, loc: Location)
38 do
39 _text = text
40 _location = loc
41 end
42 end
43
44 redef class TKwmodule
45 redef fun parser_index: Int
46 do
47 return 2
48 end
49
50 init init_tk(text: String, loc: Location)
51 do
52 _text = text
53 _location = loc
54 end
55 end
56
57 redef class TKwimport
58 redef fun parser_index: Int
59 do
60 return 3
61 end
62
63 init init_tk(loc: Location)
64 do
65 _text = once "import"
66 _location = loc
67 end
68 end
69
70 redef class TKwclass
71 redef fun parser_index: Int
72 do
73 return 4
74 end
75
76 init init_tk(loc: Location)
77 do
78 _text = once "class"
79 _location = loc
80 end
81 end
82
83 redef class TKwabstract
84 redef fun parser_index: Int
85 do
86 return 5
87 end
88
89 init init_tk(loc: Location)
90 do
91 _text = once "abstract"
92 _location = loc
93 end
94 end
95
96 redef class TKwinterface
97 redef fun parser_index: Int
98 do
99 return 6
100 end
101
102 init init_tk(loc: Location)
103 do
104 _text = once "interface"
105 _location = loc
106 end
107 end
108
109 redef class TKwuniversal
110 redef fun parser_index: Int
111 do
112 return 7
113 end
114
115 init init_tk(loc: Location)
116 do
117 _text = once "universal"
118 _location = loc
119 end
120 end
121
122 redef class TKwspecial
123 redef fun parser_index: Int
124 do
125 return 8
126 end
127
128 init init_tk(loc: Location)
129 do
130 _text = once "special"
131 _location = loc
132 end
133 end
134
135 redef class TKwend
136 redef fun parser_index: Int
137 do
138 return 9
139 end
140
141 init init_tk(loc: Location)
142 do
143 _text = once "end"
144 _location = loc
145 end
146 end
147
148 redef class TKwmeth
149 redef fun parser_index: Int
150 do
151 return 10
152 end
153
154 init init_tk(loc: Location)
155 do
156 _text = once "fun"
157 _location = loc
158 end
159 end
160
161 redef class TKwtype
162 redef fun parser_index: Int
163 do
164 return 11
165 end
166
167 init init_tk(loc: Location)
168 do
169 _text = once "type"
170 _location = loc
171 end
172 end
173
174 redef class TKwinit
175 redef fun parser_index: Int
176 do
177 return 12
178 end
179
180 init init_tk(loc: Location)
181 do
182 _text = once "init"
183 _location = loc
184 end
185 end
186
187 redef class TKwredef
188 redef fun parser_index: Int
189 do
190 return 13
191 end
192
193 init init_tk(loc: Location)
194 do
195 _text = once "redef"
196 _location = loc
197 end
198 end
199
200 redef class TKwis
201 redef fun parser_index: Int
202 do
203 return 14
204 end
205
206 init init_tk(loc: Location)
207 do
208 _text = once "is"
209 _location = loc
210 end
211 end
212
213 redef class TKwdo
214 redef fun parser_index: Int
215 do
216 return 15
217 end
218
219 init init_tk(loc: Location)
220 do
221 _text = once "do"
222 _location = loc
223 end
224 end
225
226 redef class TKwreadable
227 redef fun parser_index: Int
228 do
229 return 16
230 end
231
232 init init_tk(loc: Location)
233 do
234 _text = once "readable"
235 _location = loc
236 end
237 end
238
239 redef class TKwwritable
240 redef fun parser_index: Int
241 do
242 return 17
243 end
244
245 init init_tk(loc: Location)
246 do
247 _text = once "writable"
248 _location = loc
249 end
250 end
251
252 redef class TKwvar
253 redef fun parser_index: Int
254 do
255 return 18
256 end
257
258 init init_tk(loc: Location)
259 do
260 _text = once "var"
261 _location = loc
262 end
263 end
264
265 redef class TKwintern
266 redef fun parser_index: Int
267 do
268 return 19
269 end
270
271 init init_tk(loc: Location)
272 do
273 _text = once "intern"
274 _location = loc
275 end
276 end
277
278 redef class TKwextern
279 redef fun parser_index: Int
280 do
281 return 20
282 end
283
284 init init_tk(loc: Location)
285 do
286 _text = once "extern"
287 _location = loc
288 end
289 end
290
291 redef class TKwprotected
292 redef fun parser_index: Int
293 do
294 return 21
295 end
296
297 init init_tk(loc: Location)
298 do
299 _text = once "protected"
300 _location = loc
301 end
302 end
303
304 redef class TKwprivate
305 redef fun parser_index: Int
306 do
307 return 22
308 end
309
310 init init_tk(loc: Location)
311 do
312 _text = once "private"
313 _location = loc
314 end
315 end
316
317 redef class TKwintrude
318 redef fun parser_index: Int
319 do
320 return 23
321 end
322
323 init init_tk(loc: Location)
324 do
325 _text = once "intrude"
326 _location = loc
327 end
328 end
329
330 redef class TKwif
331 redef fun parser_index: Int
332 do
333 return 24
334 end
335
336 init init_tk(loc: Location)
337 do
338 _text = once "if"
339 _location = loc
340 end
341 end
342
343 redef class TKwthen
344 redef fun parser_index: Int
345 do
346 return 25
347 end
348
349 init init_tk(loc: Location)
350 do
351 _text = once "then"
352 _location = loc
353 end
354 end
355
356 redef class TKwelse
357 redef fun parser_index: Int
358 do
359 return 26
360 end
361
362 init init_tk(loc: Location)
363 do
364 _text = once "else"
365 _location = loc
366 end
367 end
368
369 redef class TKwwhile
370 redef fun parser_index: Int
371 do
372 return 27
373 end
374
375 init init_tk(loc: Location)
376 do
377 _text = once "while"
378 _location = loc
379 end
380 end
381
382 redef class TKwloop
383 redef fun parser_index: Int
384 do
385 return 28
386 end
387
388 init init_tk(loc: Location)
389 do
390 _text = once "loop"
391 _location = loc
392 end
393 end
394
395 redef class TKwfor
396 redef fun parser_index: Int
397 do
398 return 29
399 end
400
401 init init_tk(loc: Location)
402 do
403 _text = once "for"
404 _location = loc
405 end
406 end
407
408 redef class TKwin
409 redef fun parser_index: Int
410 do
411 return 30
412 end
413
414 init init_tk(loc: Location)
415 do
416 _text = once "in"
417 _location = loc
418 end
419 end
420
421 redef class TKwand
422 redef fun parser_index: Int
423 do
424 return 31
425 end
426
427 init init_tk(loc: Location)
428 do
429 _text = once "and"
430 _location = loc
431 end
432 end
433
434 redef class TKwor
435 redef fun parser_index: Int
436 do
437 return 32
438 end
439
440 init init_tk(loc: Location)
441 do
442 _text = once "or"
443 _location = loc
444 end
445 end
446
447 redef class TKwnot
448 redef fun parser_index: Int
449 do
450 return 33
451 end
452
453 init init_tk(loc: Location)
454 do
455 _text = once "not"
456 _location = loc
457 end
458 end
459
460 redef class TKwreturn
461 redef fun parser_index: Int
462 do
463 return 34
464 end
465
466 init init_tk(loc: Location)
467 do
468 _text = once "return"
469 _location = loc
470 end
471 end
472
473 redef class TKwcontinue
474 redef fun parser_index: Int
475 do
476 return 35
477 end
478
479 init init_tk(loc: Location)
480 do
481 _text = once "continue"
482 _location = loc
483 end
484 end
485
486 redef class TKwbreak
487 redef fun parser_index: Int
488 do
489 return 36
490 end
491
492 init init_tk(loc: Location)
493 do
494 _text = once "break"
495 _location = loc
496 end
497 end
498
499 redef class TKwabort
500 redef fun parser_index: Int
501 do
502 return 37
503 end
504
505 init init_tk(loc: Location)
506 do
507 _text = once "abort"
508 _location = loc
509 end
510 end
511
512 redef class TKwassert
513 redef fun parser_index: Int
514 do
515 return 38
516 end
517
518 init init_tk(loc: Location)
519 do
520 _text = once "assert"
521 _location = loc
522 end
523 end
524
525 redef class TKwnew
526 redef fun parser_index: Int
527 do
528 return 39
529 end
530
531 init init_tk(loc: Location)
532 do
533 _text = once "new"
534 _location = loc
535 end
536 end
537
538 redef class TKwisa
539 redef fun parser_index: Int
540 do
541 return 40
542 end
543
544 init init_tk(loc: Location)
545 do
546 _text = once "isa"
547 _location = loc
548 end
549 end
550
551 redef class TKwonce
552 redef fun parser_index: Int
553 do
554 return 41
555 end
556
557 init init_tk(loc: Location)
558 do
559 _text = once "once"
560 _location = loc
561 end
562 end
563
564 redef class TKwsuper
565 redef fun parser_index: Int
566 do
567 return 42
568 end
569
570 init init_tk(loc: Location)
571 do
572 _text = once "super"
573 _location = loc
574 end
575 end
576
577 redef class TKwself
578 redef fun parser_index: Int
579 do
580 return 43
581 end
582
583 init init_tk(loc: Location)
584 do
585 _text = once "self"
586 _location = loc
587 end
588 end
589
590 redef class TKwtrue
591 redef fun parser_index: Int
592 do
593 return 44
594 end
595
596 init init_tk(loc: Location)
597 do
598 _text = once "true"
599 _location = loc
600 end
601 end
602
603 redef class TKwfalse
604 redef fun parser_index: Int
605 do
606 return 45
607 end
608
609 init init_tk(loc: Location)
610 do
611 _text = once "false"
612 _location = loc
613 end
614 end
615
616 redef class TKwnull
617 redef fun parser_index: Int
618 do
619 return 46
620 end
621
622 init init_tk(loc: Location)
623 do
624 _text = once "null"
625 _location = loc
626 end
627 end
628
629 redef class TKwas
630 redef fun parser_index: Int
631 do
632 return 47
633 end
634
635 init init_tk(loc: Location)
636 do
637 _text = once "as"
638 _location = loc
639 end
640 end
641
642 redef class TKwnullable
643 redef fun parser_index: Int
644 do
645 return 48
646 end
647
648 init init_tk(loc: Location)
649 do
650 _text = once "nullable"
651 _location = loc
652 end
653 end
654
655 redef class TKwisset
656 redef fun parser_index: Int
657 do
658 return 49
659 end
660
661 init init_tk(loc: Location)
662 do
663 _text = once "isset"
664 _location = loc
665 end
666 end
667
668 redef class TKwlabel
669 redef fun parser_index: Int
670 do
671 return 50
672 end
673
674 init init_tk(loc: Location)
675 do
676 _text = once "label"
677 _location = loc
678 end
679 end
680
681 redef class TOpar
682 redef fun parser_index: Int
683 do
684 return 51
685 end
686
687 init init_tk(loc: Location)
688 do
689 _text = once "("
690 _location = loc
691 end
692 end
693
694 redef class TCpar
695 redef fun parser_index: Int
696 do
697 return 52
698 end
699
700 init init_tk(loc: Location)
701 do
702 _text = once ")"
703 _location = loc
704 end
705 end
706
707 redef class TObra
708 redef fun parser_index: Int
709 do
710 return 53
711 end
712
713 init init_tk(loc: Location)
714 do
715 _text = once "["
716 _location = loc
717 end
718 end
719
720 redef class TCbra
721 redef fun parser_index: Int
722 do
723 return 54
724 end
725
726 init init_tk(loc: Location)
727 do
728 _text = once "]"
729 _location = loc
730 end
731 end
732
733 redef class TComma
734 redef fun parser_index: Int
735 do
736 return 55
737 end
738
739 init init_tk(loc: Location)
740 do
741 _text = once ","
742 _location = loc
743 end
744 end
745
746 redef class TColumn
747 redef fun parser_index: Int
748 do
749 return 56
750 end
751
752 init init_tk(loc: Location)
753 do
754 _text = once ":"
755 _location = loc
756 end
757 end
758
759 redef class TQuad
760 redef fun parser_index: Int
761 do
762 return 57
763 end
764
765 init init_tk(loc: Location)
766 do
767 _text = once "::"
768 _location = loc
769 end
770 end
771
772 redef class TAssign
773 redef fun parser_index: Int
774 do
775 return 58
776 end
777
778 init init_tk(loc: Location)
779 do
780 _text = once "="
781 _location = loc
782 end
783 end
784
785 redef class TPluseq
786 redef fun parser_index: Int
787 do
788 return 59
789 end
790
791 init init_tk(loc: Location)
792 do
793 _text = once "+="
794 _location = loc
795 end
796 end
797
798 redef class TMinuseq
799 redef fun parser_index: Int
800 do
801 return 60
802 end
803
804 init init_tk(loc: Location)
805 do
806 _text = once "-="
807 _location = loc
808 end
809 end
810
811 redef class TDotdotdot
812 redef fun parser_index: Int
813 do
814 return 61
815 end
816
817 init init_tk(loc: Location)
818 do
819 _text = once "..."
820 _location = loc
821 end
822 end
823
824 redef class TDotdot
825 redef fun parser_index: Int
826 do
827 return 62
828 end
829
830 init init_tk(loc: Location)
831 do
832 _text = once ".."
833 _location = loc
834 end
835 end
836
837 redef class TDot
838 redef fun parser_index: Int
839 do
840 return 63
841 end
842
843 init init_tk(loc: Location)
844 do
845 _text = once "."
846 _location = loc
847 end
848 end
849
850 redef class TPlus
851 redef fun parser_index: Int
852 do
853 return 64
854 end
855
856 init init_tk(loc: Location)
857 do
858 _text = once "+"
859 _location = loc
860 end
861 end
862
863 redef class TMinus
864 redef fun parser_index: Int
865 do
866 return 65
867 end
868
869 init init_tk(loc: Location)
870 do
871 _text = once "-"
872 _location = loc
873 end
874 end
875
876 redef class TStar
877 redef fun parser_index: Int
878 do
879 return 66
880 end
881
882 init init_tk(loc: Location)
883 do
884 _text = once "*"
885 _location = loc
886 end
887 end
888
889 redef class TSlash
890 redef fun parser_index: Int
891 do
892 return 67
893 end
894
895 init init_tk(loc: Location)
896 do
897 _text = once "/"
898 _location = loc
899 end
900 end
901
902 redef class TPercent
903 redef fun parser_index: Int
904 do
905 return 68
906 end
907
908 init init_tk(loc: Location)
909 do
910 _text = once "%"
911 _location = loc
912 end
913 end
914
915 redef class TEq
916 redef fun parser_index: Int
917 do
918 return 69
919 end
920
921 init init_tk(loc: Location)
922 do
923 _text = once "=="
924 _location = loc
925 end
926 end
927
928 redef class TNe
929 redef fun parser_index: Int
930 do
931 return 70
932 end
933
934 init init_tk(loc: Location)
935 do
936 _text = once "!="
937 _location = loc
938 end
939 end
940
941 redef class TLt
942 redef fun parser_index: Int
943 do
944 return 71
945 end
946
947 init init_tk(loc: Location)
948 do
949 _text = once "<"
950 _location = loc
951 end
952 end
953
954 redef class TLe
955 redef fun parser_index: Int
956 do
957 return 72
958 end
959
960 init init_tk(loc: Location)
961 do
962 _text = once "<="
963 _location = loc
964 end
965 end
966
967 redef class TLl
968 redef fun parser_index: Int
969 do
970 return 73
971 end
972
973 init init_tk(loc: Location)
974 do
975 _text = once "<<"
976 _location = loc
977 end
978 end
979
980 redef class TGt
981 redef fun parser_index: Int
982 do
983 return 74
984 end
985
986 init init_tk(loc: Location)
987 do
988 _text = once ">"
989 _location = loc
990 end
991 end
992
993 redef class TGe
994 redef fun parser_index: Int
995 do
996 return 75
997 end
998
999 init init_tk(loc: Location)
1000 do
1001 _text = once ">="
1002 _location = loc
1003 end
1004 end
1005
1006 redef class TGg
1007 redef fun parser_index: Int
1008 do
1009 return 76
1010 end
1011
1012 init init_tk(loc: Location)
1013 do
1014 _text = once ">>"
1015 _location = loc
1016 end
1017 end
1018
1019 redef class TStarship
1020 redef fun parser_index: Int
1021 do
1022 return 77
1023 end
1024
1025 init init_tk(loc: Location)
1026 do
1027 _text = once "<=>"
1028 _location = loc
1029 end
1030 end
1031
1032 redef class TBang
1033 redef fun parser_index: Int
1034 do
1035 return 78
1036 end
1037
1038 init init_tk(loc: Location)
1039 do
1040 _text = once "!"
1041 _location = loc
1042 end
1043 end
1044
1045 redef class TClassid
1046 redef fun parser_index: Int
1047 do
1048 return 79
1049 end
1050
1051 init init_tk(text: String, loc: Location)
1052 do
1053 _text = text
1054 _location = loc
1055 end
1056 end
1057
1058 redef class TId
1059 redef fun parser_index: Int
1060 do
1061 return 80
1062 end
1063
1064 init init_tk(text: String, loc: Location)
1065 do
1066 _text = text
1067 _location = loc
1068 end
1069 end
1070
1071 redef class TAttrid
1072 redef fun parser_index: Int
1073 do
1074 return 81
1075 end
1076
1077 init init_tk(text: String, loc: Location)
1078 do
1079 _text = text
1080 _location = loc
1081 end
1082 end
1083
1084 redef class TNumber
1085 redef fun parser_index: Int
1086 do
1087 return 82
1088 end
1089
1090 init init_tk(text: String, loc: Location)
1091 do
1092 _text = text
1093 _location = loc
1094 end
1095 end
1096
1097 redef class TFloat
1098 redef fun parser_index: Int
1099 do
1100 return 83
1101 end
1102
1103 init init_tk(text: String, loc: Location)
1104 do
1105 _text = text
1106 _location = loc
1107 end
1108 end
1109
1110 redef class TChar
1111 redef fun parser_index: Int
1112 do
1113 return 84
1114 end
1115
1116 init init_tk(text: String, loc: Location)
1117 do
1118 _text = text
1119 _location = loc
1120 end
1121 end
1122
1123 redef class TString
1124 redef fun parser_index: Int
1125 do
1126 return 85
1127 end
1128
1129 init init_tk(text: String, loc: Location)
1130 do
1131 _text = text
1132 _location = loc
1133 end
1134 end
1135
1136 redef class TStartString
1137 redef fun parser_index: Int
1138 do
1139 return 86
1140 end
1141
1142 init init_tk(text: String, loc: Location)
1143 do
1144 _text = text
1145 _location = loc
1146 end
1147 end
1148
1149 redef class TMidString
1150 redef fun parser_index: Int
1151 do
1152 return 87
1153 end
1154
1155 init init_tk(text: String, loc: Location)
1156 do
1157 _text = text
1158 _location = loc
1159 end
1160 end
1161
1162 redef class TEndString
1163 redef fun parser_index: Int
1164 do
1165 return 88
1166 end
1167
1168 init init_tk(text: String, loc: Location)
1169 do
1170 _text = text
1171 _location = loc
1172 end
1173 end
1174
1175
1176 redef class EOF
1177 redef fun parser_index: Int
1178 do
1179 return 89
1180 end
1181
1182 init(loc: Location)
1183 do
1184 _text = ""
1185 _location = loc
1186 end
1187 end
1188
1189 redef class AError
1190 readable var _message: String
1191
1192 init init_error(message: String, loc: Location)
1193 do
1194 init(loc)
1195 _message = message
1196 end
1197 end
1198
1199
1200 # The lexer extract NIT tokens from an input stream.
1201 # It is better user with the Parser
1202 class Lexer
1203 special TablesCapable
1204 # Last peeked token
1205 var _token: nullable Token
1206
1207 # Lexer current state
1208 var _state: Int = 0
1209
1210 # Name of the stream (as given to tokens)
1211 readable var _filename: String
1212
1213 # Input stream where character are read
1214 var _stream: IStream
1215
1216 # Pushback buffer to store unread character
1217 var _stream_buf: Buffer
1218
1219 # Number of character stored in the pushback buffer
1220 var _stream_pos: Int
1221
1222 # Current line number in the input stream
1223 var _line: Int = 0
1224
1225 # Current column in the input stream
1226 var _pos: Int = 0
1227
1228 # Was the last character a cariage-return?
1229 var _cr: Bool = false
1230
1231 # If the end of stream?
1232 var _eof: Bool = false
1233
1234 # Current working text read from the input stream
1235 var _text: Buffer
1236
1237 # Constante state values
1238 private fun state_initial: Int do return 0 end
1239
1240 # Create a new lexer for a stream (and a name)
1241 init(stream: IStream, fname: String)
1242 do
1243 _filename = fname
1244 _text = new Buffer
1245 _stream = stream
1246 _stream_pos = -1
1247 _stream_buf = new Buffer
1248 end
1249
1250 # Give the next token (but do not consume it)
1251 fun peek: Token
1252 do
1253 while _token == null do
1254 _token = get_token
1255 end
1256 return _token.as(not null)
1257 end
1258
1259 # Give and consume the next token
1260 fun next: Token
1261 do
1262 var result = _token
1263 while result == null do
1264 result = get_token
1265 end
1266 _token = null
1267 return result.as(not null)
1268 end
1269
1270 # Get a token, or null if it is discarded
1271 private fun get_token: nullable Token
1272 do
1273 var dfa_state = 0
1274
1275 var start_pos = _pos
1276 var start_line = _line
1277
1278 var accept_state = -1
1279 var accept_token = -1
1280 var accept_length = -1
1281 var accept_pos = -1
1282 var accept_line = -1
1283
1284 var text = _text
1285 text.clear
1286
1287 loop
1288 var c = get_char
1289
1290 if c != -1 then
1291 var cr = _cr
1292 var line = _line
1293 var pos = _pos
1294 if c == 10 then
1295 if cr then
1296 cr = false
1297 else
1298 line = line + 1
1299 pos = 0
1300 end
1301 else if c == 13 then
1302 line = line + 1
1303 pos = 0
1304 cr = true
1305 else
1306 pos = pos + 1
1307 cr = false
1308 end
1309
1310 text.add(c.ascii)
1311
1312 loop
1313 var old_state = dfa_state
1314 if dfa_state < -1 then
1315 old_state = -2 - dfa_state
1316 end
1317
1318 dfa_state = -1
1319
1320 var low = 0
1321 var high = lexer_goto(old_state, 0) - 1
1322
1323 if high >= 0 then
1324 while low <= high do
1325 var middle = (low + high) / 2
1326 var offset = middle * 3 + 1 # +1 because length is at 0
1327
1328 if c < lexer_goto(old_state, offset) then
1329 high = middle - 1
1330 else if c > lexer_goto(old_state, offset+1) then
1331 low = middle + 1
1332 else
1333 dfa_state = lexer_goto(old_state, offset+2)
1334 break
1335 end
1336 end
1337 end
1338 if dfa_state > -2 then break
1339 end
1340
1341 _cr = cr
1342 _line = line
1343 _pos = pos
1344 else
1345 dfa_state = -1
1346 end
1347
1348 if dfa_state >= 0 then
1349 var tok = lexer_accept(dfa_state)
1350 if tok != -1 then
1351 accept_state = dfa_state
1352 accept_token = tok
1353 accept_length = text.length
1354 accept_pos = _pos
1355 accept_line = _line
1356 end
1357 else
1358 if accept_state != -1 then
1359 var location = new Location(_filename, start_line + 1, accept_line + 1, start_pos + 1, accept_pos)
1360 _pos = accept_pos
1361 _line = accept_line
1362 push_back(accept_length)
1363 if accept_token == 0 then
1364 return null
1365 end
1366 if accept_token == 1 then
1367 var token_text = text.substring(0, accept_length)
1368 return new TEol.init_tk(token_text, location)
1369 end
1370 if accept_token == 2 then
1371 var token_text = text.substring(0, accept_length)
1372 return new TComment.init_tk(token_text, location)
1373 end
1374 if accept_token == 3 then
1375 var token_text = text.substring(0, accept_length)
1376 return new TKwmodule.init_tk(token_text, location)
1377 end
1378 if accept_token == 4 then
1379 return new TKwimport.init_tk(location)
1380 end
1381 if accept_token == 5 then
1382 return new TKwclass.init_tk(location)
1383 end
1384 if accept_token == 6 then
1385 return new TKwabstract.init_tk(location)
1386 end
1387 if accept_token == 7 then
1388 return new TKwinterface.init_tk(location)
1389 end
1390 if accept_token == 8 then
1391 return new TKwuniversal.init_tk(location)
1392 end
1393 if accept_token == 9 then
1394 return new TKwspecial.init_tk(location)
1395 end
1396 if accept_token == 10 then
1397 return new TKwend.init_tk(location)
1398 end
1399 if accept_token == 11 then
1400 return new TKwmeth.init_tk(location)
1401 end
1402 if accept_token == 12 then
1403 return new TKwtype.init_tk(location)
1404 end
1405 if accept_token == 13 then
1406 return new TKwinit.init_tk(location)
1407 end
1408 if accept_token == 14 then
1409 return new TKwredef.init_tk(location)
1410 end
1411 if accept_token == 15 then
1412 return new TKwis.init_tk(location)
1413 end
1414 if accept_token == 16 then
1415 return new TKwdo.init_tk(location)
1416 end
1417 if accept_token == 17 then
1418 return new TKwreadable.init_tk(location)
1419 end
1420 if accept_token == 18 then
1421 return new TKwwritable.init_tk(location)
1422 end
1423 if accept_token == 19 then
1424 return new TKwvar.init_tk(location)
1425 end
1426 if accept_token == 20 then
1427 return new TKwintern.init_tk(location)
1428 end
1429 if accept_token == 21 then
1430 return new TKwextern.init_tk(location)
1431 end
1432 if accept_token == 22 then
1433 return new TKwprotected.init_tk(location)
1434 end
1435 if accept_token == 23 then
1436 return new TKwprivate.init_tk(location)
1437 end
1438 if accept_token == 24 then
1439 return new TKwintrude.init_tk(location)
1440 end
1441 if accept_token == 25 then
1442 return new TKwif.init_tk(location)
1443 end
1444 if accept_token == 26 then
1445 return new TKwthen.init_tk(location)
1446 end
1447 if accept_token == 27 then
1448 return new TKwelse.init_tk(location)
1449 end
1450 if accept_token == 28 then
1451 return new TKwwhile.init_tk(location)
1452 end
1453 if accept_token == 29 then
1454 return new TKwloop.init_tk(location)
1455 end
1456 if accept_token == 30 then
1457 return new TKwfor.init_tk(location)
1458 end
1459 if accept_token == 31 then
1460 return new TKwin.init_tk(location)
1461 end
1462 if accept_token == 32 then
1463 return new TKwand.init_tk(location)
1464 end
1465 if accept_token == 33 then
1466 return new TKwor.init_tk(location)
1467 end
1468 if accept_token == 34 then
1469 return new TKwnot.init_tk(location)
1470 end
1471 if accept_token == 35 then
1472 return new TKwreturn.init_tk(location)
1473 end
1474 if accept_token == 36 then
1475 return new TKwcontinue.init_tk(location)
1476 end
1477 if accept_token == 37 then
1478 return new TKwbreak.init_tk(location)
1479 end
1480 if accept_token == 38 then
1481 return new TKwabort.init_tk(location)
1482 end
1483 if accept_token == 39 then
1484 return new TKwassert.init_tk(location)
1485 end
1486 if accept_token == 40 then
1487 return new TKwnew.init_tk(location)
1488 end
1489 if accept_token == 41 then
1490 return new TKwisa.init_tk(location)
1491 end
1492 if accept_token == 42 then
1493 return new TKwonce.init_tk(location)
1494 end
1495 if accept_token == 43 then
1496 return new TKwsuper.init_tk(location)
1497 end
1498 if accept_token == 44 then
1499 return new TKwself.init_tk(location)
1500 end
1501 if accept_token == 45 then
1502 return new TKwtrue.init_tk(location)
1503 end
1504 if accept_token == 46 then
1505 return new TKwfalse.init_tk(location)
1506 end
1507 if accept_token == 47 then
1508 return new TKwnull.init_tk(location)
1509 end
1510 if accept_token == 48 then
1511 return new TKwas.init_tk(location)
1512 end
1513 if accept_token == 49 then
1514 return new TKwnullable.init_tk(location)
1515 end
1516 if accept_token == 50 then
1517 return new TKwisset.init_tk(location)
1518 end
1519 if accept_token == 51 then
1520 return new TKwlabel.init_tk(location)
1521 end
1522 if accept_token == 52 then
1523 return new TOpar.init_tk(location)
1524 end
1525 if accept_token == 53 then
1526 return new TCpar.init_tk(location)
1527 end
1528 if accept_token == 54 then
1529 return new TObra.init_tk(location)
1530 end
1531 if accept_token == 55 then
1532 return new TCbra.init_tk(location)
1533 end
1534 if accept_token == 56 then
1535 return new TComma.init_tk(location)
1536 end
1537 if accept_token == 57 then
1538 return new TColumn.init_tk(location)
1539 end
1540 if accept_token == 58 then
1541 return new TQuad.init_tk(location)
1542 end
1543 if accept_token == 59 then
1544 return new TAssign.init_tk(location)
1545 end
1546 if accept_token == 60 then
1547 return new TPluseq.init_tk(location)
1548 end
1549 if accept_token == 61 then
1550 return new TMinuseq.init_tk(location)
1551 end
1552 if accept_token == 62 then
1553 return new TDotdotdot.init_tk(location)
1554 end
1555 if accept_token == 63 then
1556 return new TDotdot.init_tk(location)
1557 end
1558 if accept_token == 64 then
1559 return new TDot.init_tk(location)
1560 end
1561 if accept_token == 65 then
1562 return new TPlus.init_tk(location)
1563 end
1564 if accept_token == 66 then
1565 return new TMinus.init_tk(location)
1566 end
1567 if accept_token == 67 then
1568 return new TStar.init_tk(location)
1569 end
1570 if accept_token == 68 then
1571 return new TSlash.init_tk(location)
1572 end
1573 if accept_token == 69 then
1574 return new TPercent.init_tk(location)
1575 end
1576 if accept_token == 70 then
1577 return new TEq.init_tk(location)
1578 end
1579 if accept_token == 71 then
1580 return new TNe.init_tk(location)
1581 end
1582 if accept_token == 72 then
1583 return new TLt.init_tk(location)
1584 end
1585 if accept_token == 73 then
1586 return new TLe.init_tk(location)
1587 end
1588 if accept_token == 74 then
1589 return new TLl.init_tk(location)
1590 end
1591 if accept_token == 75 then
1592 return new TGt.init_tk(location)
1593 end
1594 if accept_token == 76 then
1595 return new TGe.init_tk(location)
1596 end
1597 if accept_token == 77 then
1598 return new TGg.init_tk(location)
1599 end
1600 if accept_token == 78 then
1601 return new TStarship.init_tk(location)
1602 end
1603 if accept_token == 79 then
1604 return new TBang.init_tk(location)
1605 end
1606 if accept_token == 80 then
1607 var token_text = text.substring(0, accept_length)
1608 return new TClassid.init_tk(token_text, location)
1609 end
1610 if accept_token == 81 then
1611 var token_text = text.substring(0, accept_length)
1612 return new TId.init_tk(token_text, location)
1613 end
1614 if accept_token == 82 then
1615 var token_text = text.substring(0, accept_length)
1616 return new TAttrid.init_tk(token_text, location)
1617 end
1618 if accept_token == 83 then
1619 var token_text = text.substring(0, accept_length)
1620 return new TNumber.init_tk(token_text, location)
1621 end
1622 if accept_token == 84 then
1623 var token_text = text.substring(0, accept_length)
1624 return new TFloat.init_tk(token_text, location)
1625 end
1626 if accept_token == 85 then
1627 var token_text = text.substring(0, accept_length)
1628 return new TChar.init_tk(token_text, location)
1629 end
1630 if accept_token == 86 then
1631 var token_text = text.substring(0, accept_length)
1632 return new TString.init_tk(token_text, location)
1633 end
1634 if accept_token == 87 then
1635 var token_text = text.substring(0, accept_length)
1636 return new TStartString.init_tk(token_text, location)
1637 end
1638 if accept_token == 88 then
1639 var token_text = text.substring(0, accept_length)
1640 return new TMidString.init_tk(token_text, location)
1641 end
1642 if accept_token == 89 then
1643 var token_text = text.substring(0, accept_length)
1644 return new TEndString.init_tk(token_text, location)
1645 end
1646 else
1647 var location = new Location(_filename, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1)
1648 if text.length > 0 then
1649 var token = new AError.init_error("Syntax error: unknown token {text}.", location)
1650 return token
1651 else
1652 var token = new EOF(location)
1653 return token
1654 end
1655 end
1656 end
1657 end
1658 end
1659
1660 # Read the next character.
1661 # The character is read from the stream of from the pushback buffer.
1662 private fun get_char: Int
1663 do
1664 if _eof then
1665 return -1
1666 end
1667
1668 var result: Int
1669
1670 var sp = _stream_pos
1671 if sp >= 0 then
1672 var res = _stream_buf[_stream_pos]
1673 _stream_pos = sp - 1
1674 result = res.ascii
1675 else
1676 result = _stream.read_char
1677 end
1678
1679 if result == -1 then
1680 _eof = true
1681 end
1682
1683 return result
1684 end
1685
1686 # Unread some characters.
1687 # Unread characters are stored in the pushback buffer.
1688 private fun push_back(accept_length: Int)
1689 do
1690 var length = _text.length
1691 var i = length - 1
1692 while i >= accept_length do
1693 _eof = false
1694 _stream_pos = _stream_pos + 1
1695 _stream_buf[_stream_pos] = _text[i]
1696 i = i - 1
1697 end
1698 end
1699 end
1700