1 # Lexer and its tokens.
2 # This file was generated by SableCC (http://www.sablecc.org/).
5 intrude import parser_nodes
9 var _text
: nullable String
14 if res
!= null then return res
20 fun parser_index
: Int is abstract
24 redef fun parser_index
: Int
29 init init_tk
(loc
: Location)
36 redef fun parser_index
: Int
41 init init_tk
(loc
: Location)
48 redef fun parser_index
: Int
53 init init_tk
(loc
: Location)
60 redef fun parser_index
: Int
65 init init_tk
(loc
: Location)
72 redef fun parser_index
: Int
77 init init_tk
(loc
: Location)
83 redef class TKwabstract
84 redef fun parser_index
: Int
89 init init_tk
(loc
: Location)
95 redef class TKwinterface
96 redef fun parser_index
: Int
101 init init_tk
(loc
: Location)
108 redef fun parser_index
: Int
113 init init_tk
(loc
: Location)
120 redef fun parser_index
: Int
125 init init_tk
(loc
: Location)
132 redef fun parser_index
: Int
137 init init_tk
(loc
: Location)
144 redef fun parser_index
: Int
149 init init_tk
(loc
: Location)
156 redef fun parser_index
: Int
161 init init_tk
(loc
: Location)
168 redef fun parser_index
: Int
173 init init_tk
(loc
: Location)
180 redef fun parser_index
: Int
185 init init_tk
(loc
: Location)
192 redef fun parser_index
: Int
197 init init_tk
(loc
: Location)
203 redef class TKwreadable
204 redef fun parser_index
: Int
209 init init_tk
(loc
: Location)
215 redef class TKwwritable
216 redef fun parser_index
: Int
221 init init_tk
(loc
: Location)
228 redef fun parser_index
: Int
233 init init_tk
(loc
: Location)
239 redef class TKwintern
240 redef fun parser_index
: Int
245 init init_tk
(loc
: Location)
251 redef class TKwextern
252 redef fun parser_index
: Int
257 init init_tk
(loc
: Location)
263 redef class TKwprotected
264 redef fun parser_index
: Int
269 init init_tk
(loc
: Location)
275 redef class TKwprivate
276 redef fun parser_index
: Int
281 init init_tk
(loc
: Location)
287 redef class TKwintrude
288 redef fun parser_index
: Int
293 init init_tk
(loc
: Location)
300 redef fun parser_index
: Int
305 init init_tk
(loc
: Location)
312 redef fun parser_index
: Int
317 init init_tk
(loc
: Location)
324 redef fun parser_index
: Int
329 init init_tk
(loc
: Location)
336 redef fun parser_index
: Int
341 init init_tk
(loc
: Location)
348 redef fun parser_index
: Int
353 init init_tk
(loc
: Location)
360 redef fun parser_index
: Int
365 init init_tk
(loc
: Location)
372 redef fun parser_index
: Int
377 init init_tk
(loc
: Location)
384 redef fun parser_index
: Int
389 init init_tk
(loc
: Location)
396 redef fun parser_index
: Int
401 init init_tk
(loc
: Location)
408 redef fun parser_index
: Int
413 init init_tk
(loc
: Location)
419 redef class TKwreturn
420 redef fun parser_index
: Int
425 init init_tk
(loc
: Location)
431 redef class TKwcontinue
432 redef fun parser_index
: Int
437 init init_tk
(loc
: Location)
444 redef fun parser_index
: Int
449 init init_tk
(loc
: Location)
456 redef fun parser_index
: Int
461 init init_tk
(loc
: Location)
467 redef class TKwassert
468 redef fun parser_index
: Int
473 init init_tk
(loc
: Location)
480 redef fun parser_index
: Int
485 init init_tk
(loc
: Location)
492 redef fun parser_index
: Int
497 init init_tk
(loc
: Location)
504 redef fun parser_index
: Int
509 init init_tk
(loc
: Location)
516 redef fun parser_index
: Int
521 init init_tk
(loc
: Location)
528 redef fun parser_index
: Int
533 init init_tk
(loc
: Location)
540 redef fun parser_index
: Int
545 init init_tk
(loc
: Location)
552 redef fun parser_index
: Int
557 init init_tk
(loc
: Location)
564 redef fun parser_index
: Int
569 init init_tk
(loc
: Location)
576 redef fun parser_index
: Int
581 init init_tk
(loc
: Location)
587 redef class TKwnullable
588 redef fun parser_index
: Int
593 init init_tk
(loc
: Location)
600 redef fun parser_index
: Int
605 init init_tk
(loc
: Location)
612 redef fun parser_index
: Int
617 init init_tk
(loc
: Location)
624 redef fun parser_index
: Int
629 init init_tk
(loc
: Location)
636 redef fun parser_index
: Int
641 init init_tk
(loc
: Location)
648 redef fun parser_index
: Int
653 init init_tk
(loc
: Location)
660 redef fun parser_index
: Int
665 init init_tk
(loc
: Location)
672 redef fun parser_index
: Int
677 init init_tk
(loc
: Location)
684 redef fun parser_index
: Int
689 init init_tk
(loc
: Location)
696 redef fun parser_index
: Int
701 init init_tk
(loc
: Location)
708 redef fun parser_index
: Int
713 init init_tk
(loc
: Location)
720 redef fun parser_index
: Int
725 init init_tk
(loc
: Location)
732 redef fun parser_index
: Int
737 init init_tk
(loc
: Location)
744 redef fun parser_index
: Int
749 init init_tk
(loc
: Location)
755 redef class TDotdotdot
756 redef fun parser_index
: Int
761 init init_tk
(loc
: Location)
768 redef fun parser_index
: Int
773 init init_tk
(loc
: Location)
780 redef fun parser_index
: Int
785 init init_tk
(loc
: Location)
792 redef fun parser_index
: Int
797 init init_tk
(loc
: Location)
804 redef fun parser_index
: Int
809 init init_tk
(loc
: Location)
816 redef fun parser_index
: Int
821 init init_tk
(loc
: Location)
828 redef fun parser_index
: Int
833 init init_tk
(loc
: Location)
840 redef fun parser_index
: Int
845 init init_tk
(loc
: Location)
852 redef fun parser_index
: Int
857 init init_tk
(loc
: Location)
864 redef fun parser_index
: Int
869 init init_tk
(loc
: Location)
876 redef fun parser_index
: Int
881 init init_tk
(loc
: Location)
888 redef fun parser_index
: Int
893 init init_tk
(loc
: Location)
900 redef fun parser_index
: Int
905 init init_tk
(loc
: Location)
912 redef fun parser_index
: Int
917 init init_tk
(loc
: Location)
924 redef fun parser_index
: Int
929 init init_tk
(loc
: Location)
936 redef fun parser_index
: Int
941 init init_tk
(loc
: Location)
947 redef class TStarship
948 redef fun parser_index
: Int
953 init init_tk
(loc
: Location)
960 redef fun parser_index
: Int
965 init init_tk
(loc
: Location)
972 redef fun parser_index
: Int
977 init init_tk
(loc
: Location)
984 redef fun parser_index
: Int
989 init init_tk
(loc
: Location)
996 redef fun parser_index
: Int
1001 init init_tk
(loc
: Location)
1008 redef fun parser_index
: Int
1013 init init_tk
(loc
: Location)
1020 redef fun parser_index
: Int
1025 init init_tk
(loc
: Location)
1032 redef fun parser_index
: Int
1037 init init_tk
(loc
: Location)
1044 redef fun parser_index
: Int
1049 init init_tk
(loc
: Location)
1056 redef fun parser_index
: Int
1061 init init_tk
(loc
: Location)
1067 redef class TStartString
1068 redef fun parser_index
: Int
1073 init init_tk
(loc
: Location)
1079 redef class TMidString
1080 redef fun parser_index
: Int
1085 init init_tk
(loc
: Location)
1091 redef class TEndString
1092 redef fun parser_index
: Int
1097 init init_tk
(loc
: Location)
1103 redef class TBadChar
1104 redef fun parser_index
: Int
1109 init init_tk
(loc
: Location)
1115 redef class TBadString
1116 redef fun parser_index
: Int
1121 init init_tk
(loc
: Location)
1127 redef class TExternCodeSegment
1128 redef fun parser_index
: Int
1133 init init_tk
(loc
: Location)
1141 redef fun parser_index
: Int
1154 readable var _message
: String
1156 init init_error
(message
: String, loc
: Location)
1164 # The lexer extract NIT tokens from an input stream.
1165 # It is better user with the Parser
1169 var _token
: nullable Token
1171 # Lexer current state
1175 readable var _file
: SourceFile
1177 # Current character in the stream
1178 var _stream_pos
: Int = 0
1180 # Current line number in the input stream
1183 # Current column in the input stream
1186 # Was the last character a cariage-return?
1187 var _cr
: Bool = false
1189 # Constante state values
1190 private fun state_initial
: Int do return 0 end
1192 # Create a new lexer for a stream (and a name)
1193 init(file
: SourceFile)
1198 # Give the next token (but do not consume it)
1201 while _token
== null do
1204 return _token
.as(not null)
1207 # Give and consume the next token
1211 while result
== null do
1218 # Get a token, or null if it is discarded
1219 private fun get_token
: nullable Token
1223 var sp
= _stream_pos
1224 var start_stream_pos
= sp
1225 var start_pos
= _pos
1226 var start_line
= _line
1227 var string
= _file
.string
1228 var string_len
= string
.length
1230 var accept_state
= -1
1231 var accept_token
= -1
1232 var accept_length
= -1
1234 var accept_line
= -1
1237 if sp
>= string_len
then
1240 var c
= string
[sp
].ascii
1249 _file
.line_starts
[line
] = sp
1253 _file
.line_starts
[line
] = sp
1255 else if c
== 13 then
1259 _file
.line_starts
[line
] = sp
1266 var old_state
= dfa_state
1267 if dfa_state
< -1 then
1268 old_state
= -2 - dfa_state
1274 var high
= lexer_goto
(old_state
, 0) - 1
1277 while low
<= high
do
1278 var middle
= (low
+ high
) / 2
1279 var offset
= middle
* 3 + 1 # +1 because length is at 0
1281 if c
< lexer_goto
(old_state
, offset
) then
1283 else if c
> lexer_goto
(old_state
, offset
+1) then
1286 dfa_state
= lexer_goto
(old_state
, offset
+2)
1291 if dfa_state
> -2 then break
1299 if dfa_state
>= 0 then
1300 var tok
= lexer_accept
(dfa_state
)
1302 accept_state
= dfa_state
1304 accept_length
= sp
- start_stream_pos
1309 if accept_state
!= -1 then
1310 var location
= new Location(_file
, start_line
+ 1, accept_line
+ 1, start_pos
+ 1, accept_pos
)
1313 _stream_pos
= start_stream_pos
+ accept_length
1314 if accept_token
== 0 then
1317 if accept_token
== 1 then
1318 return new TEol.init_tk
(location
)
1320 if accept_token
== 2 then
1321 return new TComment.init_tk
(location
)
1323 if accept_token
== 3 then
1324 return new TKwmodule.init_tk
(location
)
1326 if accept_token
== 4 then
1327 return new TKwimport.init_tk
(location
)
1329 if accept_token
== 5 then
1330 return new TKwclass.init_tk
(location
)
1332 if accept_token
== 6 then
1333 return new TKwabstract.init_tk
(location
)
1335 if accept_token
== 7 then
1336 return new TKwinterface.init_tk
(location
)
1338 if accept_token
== 8 then
1339 return new TKwenum.init_tk
(location
)
1341 if accept_token
== 9 then
1342 return new TKwend.init_tk
(location
)
1344 if accept_token
== 10 then
1345 return new TKwmeth.init_tk
(location
)
1347 if accept_token
== 11 then
1348 return new TKwtype.init_tk
(location
)
1350 if accept_token
== 12 then
1351 return new TKwinit.init_tk
(location
)
1353 if accept_token
== 13 then
1354 return new TKwredef.init_tk
(location
)
1356 if accept_token
== 14 then
1357 return new TKwis.init_tk
(location
)
1359 if accept_token
== 15 then
1360 return new TKwdo.init_tk
(location
)
1362 if accept_token
== 16 then
1363 return new TKwreadable.init_tk
(location
)
1365 if accept_token
== 17 then
1366 return new TKwwritable.init_tk
(location
)
1368 if accept_token
== 18 then
1369 return new TKwvar.init_tk
(location
)
1371 if accept_token
== 19 then
1372 return new TKwintern.init_tk
(location
)
1374 if accept_token
== 20 then
1375 return new TKwextern.init_tk
(location
)
1377 if accept_token
== 21 then
1378 return new TKwprotected.init_tk
(location
)
1380 if accept_token
== 22 then
1381 return new TKwprivate.init_tk
(location
)
1383 if accept_token
== 23 then
1384 return new TKwintrude.init_tk
(location
)
1386 if accept_token
== 24 then
1387 return new TKwif.init_tk
(location
)
1389 if accept_token
== 25 then
1390 return new TKwthen.init_tk
(location
)
1392 if accept_token
== 26 then
1393 return new TKwelse.init_tk
(location
)
1395 if accept_token
== 27 then
1396 return new TKwwhile.init_tk
(location
)
1398 if accept_token
== 28 then
1399 return new TKwloop.init_tk
(location
)
1401 if accept_token
== 29 then
1402 return new TKwfor.init_tk
(location
)
1404 if accept_token
== 30 then
1405 return new TKwin.init_tk
(location
)
1407 if accept_token
== 31 then
1408 return new TKwand.init_tk
(location
)
1410 if accept_token
== 32 then
1411 return new TKwor.init_tk
(location
)
1413 if accept_token
== 33 then
1414 return new TKwnot.init_tk
(location
)
1416 if accept_token
== 34 then
1417 return new TKwreturn.init_tk
(location
)
1419 if accept_token
== 35 then
1420 return new TKwcontinue.init_tk
(location
)
1422 if accept_token
== 36 then
1423 return new TKwbreak.init_tk
(location
)
1425 if accept_token
== 37 then
1426 return new TKwabort.init_tk
(location
)
1428 if accept_token
== 38 then
1429 return new TKwassert.init_tk
(location
)
1431 if accept_token
== 39 then
1432 return new TKwnew.init_tk
(location
)
1434 if accept_token
== 40 then
1435 return new TKwisa.init_tk
(location
)
1437 if accept_token
== 41 then
1438 return new TKwonce.init_tk
(location
)
1440 if accept_token
== 42 then
1441 return new TKwsuper.init_tk
(location
)
1443 if accept_token
== 43 then
1444 return new TKwself.init_tk
(location
)
1446 if accept_token
== 44 then
1447 return new TKwtrue.init_tk
(location
)
1449 if accept_token
== 45 then
1450 return new TKwfalse.init_tk
(location
)
1452 if accept_token
== 46 then
1453 return new TKwnull.init_tk
(location
)
1455 if accept_token
== 47 then
1456 return new TKwas.init_tk
(location
)
1458 if accept_token
== 48 then
1459 return new TKwnullable.init_tk
(location
)
1461 if accept_token
== 49 then
1462 return new TKwisset.init_tk
(location
)
1464 if accept_token
== 50 then
1465 return new TKwlabel.init_tk
(location
)
1467 if accept_token
== 51 then
1468 return new TKwdebug.init_tk
(location
)
1470 if accept_token
== 52 then
1471 return new TOpar.init_tk
(location
)
1473 if accept_token
== 53 then
1474 return new TCpar.init_tk
(location
)
1476 if accept_token
== 54 then
1477 return new TObra.init_tk
(location
)
1479 if accept_token
== 55 then
1480 return new TCbra.init_tk
(location
)
1482 if accept_token
== 56 then
1483 return new TComma.init_tk
(location
)
1485 if accept_token
== 57 then
1486 return new TColumn.init_tk
(location
)
1488 if accept_token
== 58 then
1489 return new TQuad.init_tk
(location
)
1491 if accept_token
== 59 then
1492 return new TAssign.init_tk
(location
)
1494 if accept_token
== 60 then
1495 return new TPluseq.init_tk
(location
)
1497 if accept_token
== 61 then
1498 return new TMinuseq.init_tk
(location
)
1500 if accept_token
== 62 then
1501 return new TDotdotdot.init_tk
(location
)
1503 if accept_token
== 63 then
1504 return new TDotdot.init_tk
(location
)
1506 if accept_token
== 64 then
1507 return new TDot.init_tk
(location
)
1509 if accept_token
== 65 then
1510 return new TPlus.init_tk
(location
)
1512 if accept_token
== 66 then
1513 return new TMinus.init_tk
(location
)
1515 if accept_token
== 67 then
1516 return new TStar.init_tk
(location
)
1518 if accept_token
== 68 then
1519 return new TSlash.init_tk
(location
)
1521 if accept_token
== 69 then
1522 return new TPercent.init_tk
(location
)
1524 if accept_token
== 70 then
1525 return new TEq.init_tk
(location
)
1527 if accept_token
== 71 then
1528 return new TNe.init_tk
(location
)
1530 if accept_token
== 72 then
1531 return new TLt.init_tk
(location
)
1533 if accept_token
== 73 then
1534 return new TLe.init_tk
(location
)
1536 if accept_token
== 74 then
1537 return new TLl.init_tk
(location
)
1539 if accept_token
== 75 then
1540 return new TGt.init_tk
(location
)
1542 if accept_token
== 76 then
1543 return new TGe.init_tk
(location
)
1545 if accept_token
== 77 then
1546 return new TGg.init_tk
(location
)
1548 if accept_token
== 78 then
1549 return new TStarship.init_tk
(location
)
1551 if accept_token
== 79 then
1552 return new TBang.init_tk
(location
)
1554 if accept_token
== 80 then
1555 return new TAt.init_tk
(location
)
1557 if accept_token
== 81 then
1558 return new TClassid.init_tk
(location
)
1560 if accept_token
== 82 then
1561 return new TId.init_tk
(location
)
1563 if accept_token
== 83 then
1564 return new TAttrid.init_tk
(location
)
1566 if accept_token
== 84 then
1567 return new TNumber.init_tk
(location
)
1569 if accept_token
== 85 then
1570 return new TFloat.init_tk
(location
)
1572 if accept_token
== 86 then
1573 return new TChar.init_tk
(location
)
1575 if accept_token
== 87 then
1576 return new TString.init_tk
(location
)
1578 if accept_token
== 88 then
1579 return new TStartString.init_tk
(location
)
1581 if accept_token
== 89 then
1582 return new TMidString.init_tk
(location
)
1584 if accept_token
== 90 then
1585 return new TEndString.init_tk
(location
)
1587 if accept_token
== 91 then
1588 return new TBadChar.init_tk
(location
)
1590 if accept_token
== 92 then
1591 return new TBadString.init_tk
(location
)
1593 if accept_token
== 93 then
1594 return new TExternCodeSegment.init_tk
(location
)
1598 var location
= new Location(_file
, start_line
+ 1, start_line
+ 1, start_pos
+ 1, start_pos
+ 1)
1599 if sp
> start_stream_pos
then
1600 var text
= string
.substring
(start_stream_pos
, sp-start_stream_pos
)
1601 var token
= new AError.init_error
("Syntax error: unknown token {text}.", location
)
1604 var token
= new EOF(location
)