Merge branch 'package2module' into wip
[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 TGt
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 TGe
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 TStarship
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 TBang
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 TClassid
1020 redef fun parser_index: Int
1021 do
1022 return 77
1023 end
1024
1025 init init_tk(text: String, loc: Location)
1026 do
1027 _text = text
1028 _location = loc
1029 end
1030 end
1031
1032 redef class TId
1033 redef fun parser_index: Int
1034 do
1035 return 78
1036 end
1037
1038 init init_tk(text: String, loc: Location)
1039 do
1040 _text = text
1041 _location = loc
1042 end
1043 end
1044
1045 redef class TAttrid
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 TNumber
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 TFloat
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 TChar
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 TString
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 TStartString
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 TMidString
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 TEndString
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
1150 redef class EOF
1151 redef fun parser_index: Int
1152 do
1153 return 87
1154 end
1155
1156 init(loc: Location)
1157 do
1158 _text = ""
1159 _location = loc
1160 end
1161 end
1162
1163 redef class AError
1164 readable var _message: String
1165
1166 init init_error(message: String, loc: Location)
1167 do
1168 init(loc)
1169 _message = message
1170 end
1171 end
1172
1173
1174 # The lexer extract NIT tokens from an input stream.
1175 # It is better user with the Parser
1176 class Lexer
1177 special TablesCapable
1178 # Last peeked token
1179 var _token: nullable Token
1180
1181 # Lexer current state
1182 var _state: Int = 0
1183
1184 # Name of the stream (as given to tokens)
1185 readable var _filename: String
1186
1187 # Input stream where character are read
1188 var _stream: IStream
1189
1190 # Pushback buffer to store unread character
1191 var _stream_buf: Buffer
1192
1193 # Number of character stored in the pushback buffer
1194 var _stream_pos: Int
1195
1196 # Current line number in the input stream
1197 var _line: Int = 0
1198
1199 # Current column in the input stream
1200 var _pos: Int = 0
1201
1202 # Was the last character a cariage-return?
1203 var _cr: Bool = false
1204
1205 # If the end of stream?
1206 var _eof: Bool = false
1207
1208 # Current working text read from the input stream
1209 var _text: Buffer
1210
1211 # Constante state values
1212 private fun state_initial: Int do return 0 end
1213
1214 # Create a new lexer for a stream (and a name)
1215 init(stream: IStream, fname: String)
1216 do
1217 _filename = fname
1218 _text = new Buffer
1219 _stream = stream
1220 _stream_pos = -1
1221 _stream_buf = new Buffer
1222 end
1223
1224 # Give the next token (but do not consume it)
1225 fun peek: Token
1226 do
1227 while _token == null do
1228 _token = get_token
1229 end
1230 return _token.as(not null)
1231 end
1232
1233 # Give and consume the next token
1234 fun next: Token
1235 do
1236 var result = _token
1237 while result == null do
1238 result = get_token
1239 end
1240 _token = null
1241 return result.as(not null)
1242 end
1243
1244 # Get a token, or null if it is discarded
1245 private fun get_token: nullable Token
1246 do
1247 var dfa_state = 0
1248
1249 var start_pos = _pos
1250 var start_line = _line
1251
1252 var accept_state = -1
1253 var accept_token = -1
1254 var accept_length = -1
1255 var accept_pos = -1
1256 var accept_line = -1
1257
1258 var text = _text
1259 text.clear
1260
1261 loop
1262 var c = get_char
1263
1264 if c != -1 then
1265 var cr = _cr
1266 var line = _line
1267 var pos = _pos
1268 if c == 10 then
1269 if cr then
1270 cr = false
1271 else
1272 line = line + 1
1273 pos = 0
1274 end
1275 else if c == 13 then
1276 line = line + 1
1277 pos = 0
1278 cr = true
1279 else
1280 pos = pos + 1
1281 cr = false
1282 end
1283
1284 text.add(c.ascii)
1285
1286 loop
1287 var old_state = dfa_state
1288 if dfa_state < -1 then
1289 old_state = -2 - dfa_state
1290 end
1291
1292 dfa_state = -1
1293
1294 var low = 0
1295 var high = lexer_goto(old_state, 0) - 1
1296
1297 if high >= 0 then
1298 while low <= high do
1299 var middle = (low + high) / 2
1300 var offset = middle * 3 + 1 # +1 because length is at 0
1301
1302 if c < lexer_goto(old_state, offset) then
1303 high = middle - 1
1304 else if c > lexer_goto(old_state, offset+1) then
1305 low = middle + 1
1306 else
1307 dfa_state = lexer_goto(old_state, offset+2)
1308 break
1309 end
1310 end
1311 end
1312 if dfa_state > -2 then break
1313 end
1314
1315 _cr = cr
1316 _line = line
1317 _pos = pos
1318 else
1319 dfa_state = -1
1320 end
1321
1322 if dfa_state >= 0 then
1323 var tok = lexer_accept(dfa_state)
1324 if tok != -1 then
1325 accept_state = dfa_state
1326 accept_token = tok
1327 accept_length = text.length
1328 accept_pos = _pos
1329 accept_line = _line
1330 end
1331 else
1332 if accept_state != -1 then
1333 var location = new Location(_filename, start_line + 1, accept_line + 1, start_pos + 1, accept_pos)
1334 _pos = accept_pos
1335 _line = accept_line
1336 push_back(accept_length)
1337 if accept_token == 0 then
1338 return null
1339 end
1340 if accept_token == 1 then
1341 var token_text = text.substring(0, accept_length)
1342 return new TEol.init_tk(token_text, location)
1343 end
1344 if accept_token == 2 then
1345 var token_text = text.substring(0, accept_length)
1346 return new TComment.init_tk(token_text, location)
1347 end
1348 if accept_token == 3 then
1349 var token_text = text.substring(0, accept_length)
1350 return new TKwmodule.init_tk(token_text, location)
1351 end
1352 if accept_token == 4 then
1353 return new TKwimport.init_tk(location)
1354 end
1355 if accept_token == 5 then
1356 return new TKwclass.init_tk(location)
1357 end
1358 if accept_token == 6 then
1359 return new TKwabstract.init_tk(location)
1360 end
1361 if accept_token == 7 then
1362 return new TKwinterface.init_tk(location)
1363 end
1364 if accept_token == 8 then
1365 return new TKwuniversal.init_tk(location)
1366 end
1367 if accept_token == 9 then
1368 return new TKwspecial.init_tk(location)
1369 end
1370 if accept_token == 10 then
1371 return new TKwend.init_tk(location)
1372 end
1373 if accept_token == 11 then
1374 return new TKwmeth.init_tk(location)
1375 end
1376 if accept_token == 12 then
1377 return new TKwtype.init_tk(location)
1378 end
1379 if accept_token == 13 then
1380 return new TKwinit.init_tk(location)
1381 end
1382 if accept_token == 14 then
1383 return new TKwredef.init_tk(location)
1384 end
1385 if accept_token == 15 then
1386 return new TKwis.init_tk(location)
1387 end
1388 if accept_token == 16 then
1389 return new TKwdo.init_tk(location)
1390 end
1391 if accept_token == 17 then
1392 return new TKwreadable.init_tk(location)
1393 end
1394 if accept_token == 18 then
1395 return new TKwwritable.init_tk(location)
1396 end
1397 if accept_token == 19 then
1398 return new TKwvar.init_tk(location)
1399 end
1400 if accept_token == 20 then
1401 return new TKwintern.init_tk(location)
1402 end
1403 if accept_token == 21 then
1404 return new TKwextern.init_tk(location)
1405 end
1406 if accept_token == 22 then
1407 return new TKwprotected.init_tk(location)
1408 end
1409 if accept_token == 23 then
1410 return new TKwprivate.init_tk(location)
1411 end
1412 if accept_token == 24 then
1413 return new TKwintrude.init_tk(location)
1414 end
1415 if accept_token == 25 then
1416 return new TKwif.init_tk(location)
1417 end
1418 if accept_token == 26 then
1419 return new TKwthen.init_tk(location)
1420 end
1421 if accept_token == 27 then
1422 return new TKwelse.init_tk(location)
1423 end
1424 if accept_token == 28 then
1425 return new TKwwhile.init_tk(location)
1426 end
1427 if accept_token == 29 then
1428 return new TKwloop.init_tk(location)
1429 end
1430 if accept_token == 30 then
1431 return new TKwfor.init_tk(location)
1432 end
1433 if accept_token == 31 then
1434 return new TKwin.init_tk(location)
1435 end
1436 if accept_token == 32 then
1437 return new TKwand.init_tk(location)
1438 end
1439 if accept_token == 33 then
1440 return new TKwor.init_tk(location)
1441 end
1442 if accept_token == 34 then
1443 return new TKwnot.init_tk(location)
1444 end
1445 if accept_token == 35 then
1446 return new TKwreturn.init_tk(location)
1447 end
1448 if accept_token == 36 then
1449 return new TKwcontinue.init_tk(location)
1450 end
1451 if accept_token == 37 then
1452 return new TKwbreak.init_tk(location)
1453 end
1454 if accept_token == 38 then
1455 return new TKwabort.init_tk(location)
1456 end
1457 if accept_token == 39 then
1458 return new TKwassert.init_tk(location)
1459 end
1460 if accept_token == 40 then
1461 return new TKwnew.init_tk(location)
1462 end
1463 if accept_token == 41 then
1464 return new TKwisa.init_tk(location)
1465 end
1466 if accept_token == 42 then
1467 return new TKwonce.init_tk(location)
1468 end
1469 if accept_token == 43 then
1470 return new TKwsuper.init_tk(location)
1471 end
1472 if accept_token == 44 then
1473 return new TKwself.init_tk(location)
1474 end
1475 if accept_token == 45 then
1476 return new TKwtrue.init_tk(location)
1477 end
1478 if accept_token == 46 then
1479 return new TKwfalse.init_tk(location)
1480 end
1481 if accept_token == 47 then
1482 return new TKwnull.init_tk(location)
1483 end
1484 if accept_token == 48 then
1485 return new TKwas.init_tk(location)
1486 end
1487 if accept_token == 49 then
1488 return new TKwnullable.init_tk(location)
1489 end
1490 if accept_token == 50 then
1491 return new TKwisset.init_tk(location)
1492 end
1493 if accept_token == 51 then
1494 return new TKwlabel.init_tk(location)
1495 end
1496 if accept_token == 52 then
1497 return new TOpar.init_tk(location)
1498 end
1499 if accept_token == 53 then
1500 return new TCpar.init_tk(location)
1501 end
1502 if accept_token == 54 then
1503 return new TObra.init_tk(location)
1504 end
1505 if accept_token == 55 then
1506 return new TCbra.init_tk(location)
1507 end
1508 if accept_token == 56 then
1509 return new TComma.init_tk(location)
1510 end
1511 if accept_token == 57 then
1512 return new TColumn.init_tk(location)
1513 end
1514 if accept_token == 58 then
1515 return new TQuad.init_tk(location)
1516 end
1517 if accept_token == 59 then
1518 return new TAssign.init_tk(location)
1519 end
1520 if accept_token == 60 then
1521 return new TPluseq.init_tk(location)
1522 end
1523 if accept_token == 61 then
1524 return new TMinuseq.init_tk(location)
1525 end
1526 if accept_token == 62 then
1527 return new TDotdotdot.init_tk(location)
1528 end
1529 if accept_token == 63 then
1530 return new TDotdot.init_tk(location)
1531 end
1532 if accept_token == 64 then
1533 return new TDot.init_tk(location)
1534 end
1535 if accept_token == 65 then
1536 return new TPlus.init_tk(location)
1537 end
1538 if accept_token == 66 then
1539 return new TMinus.init_tk(location)
1540 end
1541 if accept_token == 67 then
1542 return new TStar.init_tk(location)
1543 end
1544 if accept_token == 68 then
1545 return new TSlash.init_tk(location)
1546 end
1547 if accept_token == 69 then
1548 return new TPercent.init_tk(location)
1549 end
1550 if accept_token == 70 then
1551 return new TEq.init_tk(location)
1552 end
1553 if accept_token == 71 then
1554 return new TNe.init_tk(location)
1555 end
1556 if accept_token == 72 then
1557 return new TLt.init_tk(location)
1558 end
1559 if accept_token == 73 then
1560 return new TLe.init_tk(location)
1561 end
1562 if accept_token == 74 then
1563 return new TGt.init_tk(location)
1564 end
1565 if accept_token == 75 then
1566 return new TGe.init_tk(location)
1567 end
1568 if accept_token == 76 then
1569 return new TStarship.init_tk(location)
1570 end
1571 if accept_token == 77 then
1572 return new TBang.init_tk(location)
1573 end
1574 if accept_token == 78 then
1575 var token_text = text.substring(0, accept_length)
1576 return new TClassid.init_tk(token_text, location)
1577 end
1578 if accept_token == 79 then
1579 var token_text = text.substring(0, accept_length)
1580 return new TId.init_tk(token_text, location)
1581 end
1582 if accept_token == 80 then
1583 var token_text = text.substring(0, accept_length)
1584 return new TAttrid.init_tk(token_text, location)
1585 end
1586 if accept_token == 81 then
1587 var token_text = text.substring(0, accept_length)
1588 return new TNumber.init_tk(token_text, location)
1589 end
1590 if accept_token == 82 then
1591 var token_text = text.substring(0, accept_length)
1592 return new TFloat.init_tk(token_text, location)
1593 end
1594 if accept_token == 83 then
1595 var token_text = text.substring(0, accept_length)
1596 return new TChar.init_tk(token_text, location)
1597 end
1598 if accept_token == 84 then
1599 var token_text = text.substring(0, accept_length)
1600 return new TString.init_tk(token_text, location)
1601 end
1602 if accept_token == 85 then
1603 var token_text = text.substring(0, accept_length)
1604 return new TStartString.init_tk(token_text, location)
1605 end
1606 if accept_token == 86 then
1607 var token_text = text.substring(0, accept_length)
1608 return new TMidString.init_tk(token_text, location)
1609 end
1610 if accept_token == 87 then
1611 var token_text = text.substring(0, accept_length)
1612 return new TEndString.init_tk(token_text, location)
1613 end
1614 else
1615 var location = new Location(_filename, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1)
1616 if text.length > 0 then
1617 var token = new AError.init_error("Syntax error: unknown token {text}.", location)
1618 return token
1619 else
1620 var token = new EOF(location)
1621 return token
1622 end
1623 end
1624 end
1625 if false then break # FIXME remove once unreach loop exits are in c_src
1626 end
1627 return null # FIXME remove once unreach loop exits are in c_src
1628 end
1629
1630 # Read the next character.
1631 # The character is read from the stream of from the pushback buffer.
1632 private fun get_char: Int
1633 do
1634 if _eof then
1635 return -1
1636 end
1637
1638 var result: Int
1639
1640 var sp = _stream_pos
1641 if sp >= 0 then
1642 var res = _stream_buf[_stream_pos]
1643 _stream_pos = sp - 1
1644 result = res.ascii
1645 else
1646 result = _stream.read_char
1647 end
1648
1649 if result == -1 then
1650 _eof = true
1651 end
1652
1653 return result
1654 end
1655
1656 # Unread some characters.
1657 # Unread characters are stored in the pushback buffer.
1658 private fun push_back(accept_length: Int)
1659 do
1660 var length = _text.length
1661 var i = length - 1
1662 while i >= accept_length do
1663 _eof = false
1664 _stream_pos = _stream_pos + 1
1665 _stream_buf[_stream_pos] = _text[i]
1666 i = i - 1
1667 end
1668 end
1669 end
1670