forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexer.cr
2923 lines (2703 loc) · 84.9 KB
/
lexer.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require "./token"
require "../exception"
require "string_pool"
require "../warnings"
module Crystal
class Lexer
property? doc_enabled : Bool
property? comments_enabled : Bool
property? count_whitespace : Bool
property? wants_raw : Bool
property? slash_is_regex : Bool
property? wants_def_or_macro_name : Bool
getter reader : Char::Reader
getter token : Token
property line_number : Int32
property column_number : Int32
property wants_symbol : Bool
@filename : String | VirtualFile | Nil
@stacked_filename : String | VirtualFile | Nil
@token_end_location : Location?
@string_pool : StringPool
# This is an interface for storing data associated to a heredoc
module HeredocItem
end
# Heredocs pushed when found. Should be processed when encountering a newline
getter heredocs = [] of {Token::DelimiterState, HeredocItem}
property macro_expansion_pragmas : Hash(Int32, Array(LocPragma))? = nil
alias LocPragma = LocSetPragma | LocPushPragma | LocPopPragma
record LocSetPragma,
filename : String,
line_number : Int32,
column_number : Int32 do
def run_pragma(lexer)
lexer.set_location filename, line_number, column_number
end
end
record LocPushPragma do
def run_pragma(lexer)
lexer.push_location
end
end
record LocPopPragma do
def run_pragma(lexer)
lexer.pop_location
end
end
# Warning settings and all detected warnings.
property warnings : WarningCollection
def initialize(string, string_pool : StringPool? = nil, warnings : WarningCollection? = nil)
@warnings = warnings || WarningCollection.new
@reader = Char::Reader.new(string)
@token = Token.new
@temp_token = Token.new
@line_number = 1
@column_number = 1
@filename = ""
@wants_regex = true
@doc_enabled = false
@comment_is_doc = true
@comments_enabled = false
@count_whitespace = false
@slash_is_regex = true
@wants_raw = false
@wants_def_or_macro_name = false
@wants_symbol = true
@string_pool = string_pool || StringPool.new
# When lexing macro tokens, when we encounter `#{` inside
# a string we push the current delimiter here and reset
# the current one to nil. The reason is, inside strings
# we don't want to consider %foo a macro variable, but
# we do want to do this inside interpolations.
# We then count curly braces, with @macro_curly_count,
# until we find the last `}` and then we pop from the stack
# and get the original delimiter.
@delimiter_state_stack = [] of Token::DelimiterState
@macro_curly_count = 0
@stacked = false
@stacked_filename = ""
@stacked_line_number = 1
@stacked_column_number = 1
end
def filename=(filename)
@filename = filename
end
def next_token
# Check previous token:
if @token.type.newline? || @token.type.eof?
# 1) After a newline or at the start of the stream (:EOF), a following comment can be a doc comment
@comment_is_doc = true
elsif !@token.type.space?
# 2) Any non-space token prevents a following comment from being a doc
# comment.
@comment_is_doc = false
end
reset_token
# Skip comments
while current_char == '#'
start = current_pos
# Check #<loc:...> pragma comment
if char_sequence?('<', 'l', 'o', 'c', ':', column_increment: false)
next_char_no_column_increment
consume_loc_pragma
else
if @doc_enabled && @comment_is_doc
consume_doc
elsif @comments_enabled
return consume_comment(start)
else
skip_comment
end
end
end
start = current_pos
# Fix location by `macro_expansion_pragmas`.
if me_pragmas = macro_expansion_pragmas
# It might happen that the current "start" already passed some
# location pragmas, so we must consume all of those. For example
# if one does `@{{...}}` inside a macro, "start" will be one less
# number than the pragma, and after consuming "@..." if we don't
# consume the pragmas generated by `{{...}}` we'll be in an
# incorrect location.
while me_pragmas.first_key?.try &.<=(start)
_, pragmas = me_pragmas.shift
pragmas.each &.run_pragma self
end
end
reset_regex_flags = true
case current_char
when '\0'
@token.type = :EOF
when ' ', '\t'
consume_whitespace
reset_regex_flags = false
when '\\'
case next_char
when '\r', '\n'
handle_slash_r_slash_n_or_slash_n
incr_line_number
@token.passed_backslash_newline = true
consume_whitespace
reset_regex_flags = false
else
unknown_token
end
when '\n'
next_char :NEWLINE
incr_line_number
reset_regex_flags = false
consume_newlines
when '\r'
if next_char == '\n'
next_char :NEWLINE
incr_line_number
reset_regex_flags = false
consume_newlines
else
raise "expected '\\n' after '\\r'"
end
when '='
case next_char
when '='
case next_char
when '='
next_char :OP_EQ_EQ_EQ
else
@token.type = :OP_EQ_EQ
end
when '>'
next_char :OP_EQ_GT
when '~'
next_char :OP_EQ_TILDE
else
@token.type = :OP_EQ
end
when '!'
case next_char
when '='
next_char :OP_BANG_EQ
when '~'
next_char :OP_BANG_TILDE
else
@token.type = :OP_BANG
end
when '<'
case next_char
when '='
case next_char
when '>'
next_char :OP_LT_EQ_GT
else
@token.type = :OP_LT_EQ
end
when '<'
case next_char
when '='
next_char :OP_LT_LT_EQ
when '-'
consume_heredoc_start(start)
else
@token.type = :OP_LT_LT
end
else
@token.type = :OP_LT
end
when '>'
case next_char
when '='
next_char :OP_GT_EQ
when '>'
case next_char
when '='
next_char :OP_GT_GT_EQ
else
@token.type = :OP_GT_GT
end
else
@token.type = :OP_GT
end
when '+'
@token.start = start
case next_char
when '='
next_char :OP_PLUS_EQ
when '0'..'9'
scan_number start
when '+'
raise "postfix increment is not supported, use `exp += 1`"
else
@token.type = :OP_PLUS
end
when '-'
@token.start = start
case next_char
when '='
next_char :OP_MINUS_EQ
when '>'
next_char :OP_MINUS_GT
when '0'..'9'
scan_number start, negative: true
when '-'
raise "postfix decrement is not supported, use `exp -= 1`"
else
@token.type = :OP_MINUS
end
when '*'
case next_char
when '='
next_char :OP_STAR_EQ
when '*'
case next_char
when '='
next_char :OP_STAR_STAR_EQ
else
@token.type = :OP_STAR_STAR
end
else
@token.type = :OP_STAR
end
when '/'
char = next_char
if (@wants_def_or_macro_name || !@slash_is_regex) && char == '/'
case next_char
when '='
next_char :OP_SLASH_SLASH_EQ
else
@token.type = :OP_SLASH_SLASH
end
elsif !@slash_is_regex && char == '='
next_char :OP_SLASH_EQ
elsif @wants_def_or_macro_name
@token.type = :OP_SLASH
elsif @slash_is_regex
delimited_pair :regex, '/', '/', start, advance: false
elsif char.ascii_whitespace? || char == '\0'
@token.type = :OP_SLASH
elsif @wants_regex
delimited_pair :regex, '/', '/', start, advance: false
else
@token.type = :OP_SLASH
end
when '%'
if @wants_def_or_macro_name
next_char :OP_PERCENT
else
case next_char
when '='
next_char :OP_PERCENT_EQ
when '(', '[', '{', '<', '|'
delimited_pair :string, current_char, closing_char, start
when 'i'
case peek_next_char
when '(', '{', '[', '<', '|'
start_char = next_char
next_char :SYMBOL_ARRAY_START
@token.raw = "%i#{start_char}" if @wants_raw
@token.delimiter_state = Token::DelimiterState.new(:symbol_array, start_char, closing_char(start_char))
else
@token.type = :OP_PERCENT
end
when 'q'
case peek_next_char
when '(', '{', '[', '<', '|'
next_char
delimited_pair :string, current_char, closing_char, start, allow_escapes: false
else
@token.type = :OP_PERCENT
end
when 'Q'
case peek_next_char
when '(', '{', '[', '<', '|'
next_char
delimited_pair :string, current_char, closing_char, start
else
@token.type = :OP_PERCENT
end
when 'r'
case next_char
when '(', '[', '{', '<', '|'
delimited_pair :regex, current_char, closing_char, start
else
raise "unknown %r char"
end
when 'x'
case next_char
when '(', '[', '{', '<', '|'
delimited_pair :command, current_char, closing_char, start
else
raise "unknown %x char"
end
when 'w'
case peek_next_char
when '(', '{', '[', '<', '|'
start_char = next_char
next_char :STRING_ARRAY_START
@token.raw = "%w#{start_char}" if @wants_raw
@token.delimiter_state = Token::DelimiterState.new(:string_array, start_char, closing_char(start_char))
else
@token.type = :OP_PERCENT
end
when '}'
next_char :OP_PERCENT_RCURLY
else
@token.type = :OP_PERCENT
end
end
when '(' then next_char :OP_LPAREN
when ')' then next_char :OP_RPAREN
when '{'
case next_char
when '%'
next_char :OP_LCURLY_PERCENT
when '{'
next_char :OP_LCURLY_LCURLY
else
@token.type = :OP_LCURLY
end
when '}' then next_char :OP_RCURLY
when '['
case next_char
when ']'
case next_char
when '='
next_char :OP_LSQUARE_RSQUARE_EQ
when '?'
next_char :OP_LSQUARE_RSQUARE_QUESTION
else
@token.type = :OP_LSQUARE_RSQUARE
end
else
@token.type = :OP_LSQUARE
end
when ']' then next_char :OP_RSQUARE
when ',' then next_char :OP_COMMA
when '?' then next_char :OP_QUESTION
when ';'
reset_regex_flags = false
next_char :OP_SEMICOLON
when ':'
if next_char == ':'
next_char :OP_COLON_COLON
elsif @wants_symbol
consume_symbol
else
@token.type = :OP_COLON
end
when '~'
next_char :OP_TILDE
when '.'
line = @line_number
column = @column_number
case next_char
when '.'
case next_char
when '.'
next_char :OP_PERIOD_PERIOD_PERIOD
else
@token.type = :OP_PERIOD_PERIOD
end
when .ascii_number?
raise ".1 style number literal is not supported, put 0 before dot", line, column
else
@token.type = :OP_PERIOD
end
when '&'
case next_char
when '&'
case next_char
when '='
next_char :OP_AMP_AMP_EQ
else
@token.type = :OP_AMP_AMP
end
when '='
next_char :OP_AMP_EQ
when '+'
case next_char
when '='
next_char :OP_AMP_PLUS_EQ
else
@token.type = :OP_AMP_PLUS
end
when '-'
# Check if '>' comes after '&-', making it '&->'.
# We want to parse that like '&(->...)',
# so we only return '&' for now.
if peek_next_char == '>'
@token.type = :OP_AMP
else
case next_char
when '='
next_char :OP_AMP_MINUS_EQ
else
@token.type = :OP_AMP_MINUS
end
end
when '*'
case next_char
when '*'
next_char :OP_AMP_STAR_STAR
when '='
next_char :OP_AMP_STAR_EQ
else
@token.type = :OP_AMP_STAR
end
else
@token.type = :OP_AMP
end
when '|'
case next_char
when '|'
case next_char
when '='
next_char :OP_BAR_BAR_EQ
else
@token.type = :OP_BAR_BAR
end
when '='
next_char :OP_BAR_EQ
else
@token.type = :OP_BAR
end
when '^'
case next_char
when '='
next_char :OP_CARET_EQ
else
@token.type = :OP_CARET
end
when '\''
line = @line_number
column = @column_number
@token.type = :CHAR
case char1 = next_char
when '\\'
case char2 = next_char
when '\\'
@token.value = '\\'
when '\''
@token.value = '\''
when 'a'
@token.value = '\a'
when 'b'
@token.value = '\b'
when 'e'
@token.value = '\e'
when 'f'
@token.value = '\f'
when 'n'
@token.value = '\n'
when 'r'
@token.value = '\r'
when 't'
@token.value = '\t'
when 'v'
@token.value = '\v'
when 'u'
value = consume_char_unicode_escape
@token.value = value.chr
when '0'
@token.value = '\0'
when '\0'
raise "unterminated char literal", line, column
else
raise "invalid char escape sequence '\\#{char2}'", line, column
end
when '\''
raise "invalid empty char literal (did you mean '\\''?)", line, column
when '\0'
raise "unterminated char literal", line, column
else
@token.value = char1
end
if next_char != '\''
raise "unterminated char literal, use double quotes for strings", line, column
end
next_char
set_token_raw_from_start(start)
when '`'
if @wants_def_or_macro_name
next_char :OP_GRAVE
else
delimited_pair :command, '`', '`', start
end
when '"'
delimited_pair :string, '"', '"', start
when '0'..'9'
scan_number start
when '@'
case next_char
when '['
next_char :OP_AT_LSQUARE
when '@'
next_char
consume_variable :CLASS_VAR, start
else
consume_variable :INSTANCE_VAR, start
end
when '$'
case next_char
when '~'
next_char :OP_DOLLAR_TILDE
when '?'
next_char :OP_DOLLAR_QUESTION
when .ascii_number?
start = current_pos
if current_char == '0'
next_char
else
while next_char.ascii_number?
# Nothing to do
end
next_char if current_char == '?'
end
@token.type = :GLOBAL_MATCH_DATA_INDEX
@token.value = string_range_from_pool(start)
else
consume_variable :GLOBAL, start
end
when 'a'
case next_char
when 'b'
if char_sequence?('s', 't', 'r', 'a', 'c', 't')
return check_ident_or_keyword(:abstract, start)
end
when 'l'
if char_sequence?('i', 'a', 's')
return check_ident_or_keyword(:alias, start)
end
when 's'
case peek_next_char
when 'm'
next_char
return check_ident_or_keyword(:asm, start)
when '?'
next_char
next_char :IDENT
@token.value = :as_question
return @token
else
return check_ident_or_keyword(:as, start)
end
when 'n'
if char_sequence?('n', 'o', 't', 'a', 't', 'i', 'o', 'n')
return check_ident_or_keyword(:annotation, start)
end
else
# scan_ident
end
scan_ident(start)
when 'b'
case next_char
when 'e'
if char_sequence?('g', 'i', 'n')
return check_ident_or_keyword(:begin, start)
end
when 'r'
if char_sequence?('e', 'a', 'k')
return check_ident_or_keyword(:break, start)
end
else
# scan_ident
end
scan_ident(start)
when 'c'
case next_char
when 'a'
if char_sequence?('s', 'e')
return check_ident_or_keyword(:case, start)
end
when 'l'
if char_sequence?('a', 's', 's')
return check_ident_or_keyword(:class, start)
end
else
# scan_ident
end
scan_ident(start)
when 'd'
case next_char
when 'e'
if next_char == 'f'
return check_ident_or_keyword(:def, start)
end
when 'o' then return check_ident_or_keyword(:do, start)
else
# scan_ident
end
scan_ident(start)
when 'e'
case next_char
when 'l'
case next_char
when 's'
case next_char
when 'e' then return check_ident_or_keyword(:else, start)
when 'i'
if next_char == 'f'
return check_ident_or_keyword(:elsif, start)
end
else
# scan_ident
end
else
# scan_ident
end
when 'n'
case next_char
when 'd'
return check_ident_or_keyword(:end, start)
when 's'
if char_sequence?('u', 'r', 'e')
return check_ident_or_keyword(:ensure, start)
end
when 'u'
if next_char == 'm'
return check_ident_or_keyword(:enum, start)
end
else
# scan_ident
end
when 'x'
if char_sequence?('t', 'e', 'n', 'd')
return check_ident_or_keyword(:extend, start)
end
else
# scan_ident
end
scan_ident(start)
when 'f'
case next_char
when 'a'
if char_sequence?('l', 's', 'e')
return check_ident_or_keyword(:false, start)
end
when 'o'
if next_char == 'r'
return check_ident_or_keyword(:for, start)
end
when 'u'
if next_char == 'n'
return check_ident_or_keyword(:fun, start)
end
else
# scan_ident
end
scan_ident(start)
when 'i'
case next_char
when 'f'
return check_ident_or_keyword(:if, start)
when 'n'
if ident_part_or_end?(peek_next_char)
case next_char
when 'c'
if char_sequence?('l', 'u', 'd', 'e')
return check_ident_or_keyword(:include, start)
end
when 's'
if char_sequence?('t', 'a', 'n', 'c', 'e', '_', 's', 'i', 'z', 'e', 'o', 'f')
return check_ident_or_keyword(:instance_sizeof, start)
end
else
# scan_ident
end
else
next_char :IDENT
@token.value = :in
return @token
end
when 's'
if char_sequence?('_', 'a', '?')
return check_ident_or_keyword(:is_a_question, start)
end
else
# scan_ident
end
scan_ident(start)
when 'l'
case next_char
when 'i'
if next_char == 'b'
return check_ident_or_keyword(:lib, start)
end
else
# scan_ident
end
scan_ident(start)
when 'm'
case next_char
when 'a'
if char_sequence?('c', 'r', 'o')
return check_ident_or_keyword(:macro, start)
end
when 'o'
case next_char
when 'd'
if char_sequence?('u', 'l', 'e')
return check_ident_or_keyword(:module, start)
end
else
# scan_ident
end
else
# scan_ident
end
scan_ident(start)
when 'n'
case next_char
when 'e'
if char_sequence?('x', 't')
return check_ident_or_keyword(:next, start)
end
when 'i'
case next_char
when 'l'
if peek_next_char == '?'
next_char
return check_ident_or_keyword(:nil_question, start)
else
return check_ident_or_keyword(:nil, start)
end
else
# scan_ident
end
else
# scan_ident
end
scan_ident(start)
when 'o'
case next_char
when 'f'
if peek_next_char == 'f'
next_char
if char_sequence?('s', 'e', 't', 'o', 'f')
return check_ident_or_keyword(:offsetof, start)
end
else
return check_ident_or_keyword(:of, start)
end
when 'u'
if next_char == 't'
return check_ident_or_keyword(:out, start)
end
else
# scan_ident
end
scan_ident(start)
when 'p'
case next_char
when 'o'
if char_sequence?('i', 'n', 't', 'e', 'r', 'o', 'f')
return check_ident_or_keyword(:pointerof, start)
end
when 'r'
case next_char
when 'i'
if char_sequence?('v', 'a', 't', 'e')
return check_ident_or_keyword(:private, start)
end
when 'o'
if char_sequence?('t', 'e', 'c', 't', 'e', 'd')
return check_ident_or_keyword(:protected, start)
end
else
# scan_ident
end
else
# scan_ident
end
scan_ident(start)
when 'r'
case next_char
when 'e'
case next_char
when 's'
case next_char
when 'c'
if char_sequence?('u', 'e')
return check_ident_or_keyword(:rescue, start)
end
when 'p'
if char_sequence?('o', 'n', 'd', 's', '_', 't', 'o', '?')
return check_ident_or_keyword(:responds_to_question, start)
end
else
# scan_ident
end
when 't'
if char_sequence?('u', 'r', 'n')
return check_ident_or_keyword(:return, start)
end
when 'q'
if char_sequence?('u', 'i', 'r', 'e')
return check_ident_or_keyword(:require, start)
end
else
# scan_ident
end
else
# scan_ident
end
scan_ident(start)
when 's'
case next_char
when 'e'
if next_char == 'l'
case next_char
when 'e'
if char_sequence?('c', 't')
return check_ident_or_keyword(:select, start)
end
when 'f'
return check_ident_or_keyword(:self, start)
else
# scan_ident
end
end
when 'i'
if char_sequence?('z', 'e', 'o', 'f')
return check_ident_or_keyword(:sizeof, start)
end
when 't'
if char_sequence?('r', 'u', 'c', 't')
return check_ident_or_keyword(:struct, start)
end
when 'u'
if char_sequence?('p', 'e', 'r')
return check_ident_or_keyword(:super, start)
end
else
# scan_ident
end
scan_ident(start)
when 't'
case next_char
when 'h'
if char_sequence?('e', 'n')
return check_ident_or_keyword(:then, start)
end
when 'r'
if char_sequence?('u', 'e')
return check_ident_or_keyword(:true, start)
end
when 'y'
if char_sequence?('p', 'e')
if peek_next_char == 'o'
next_char
if next_char == 'f'
return check_ident_or_keyword(:typeof, start)
end
else
return check_ident_or_keyword(:type, start)
end
end
else
# scan_ident
end
scan_ident(start)
when 'u'
if next_char == 'n'
case next_char
when 'i'
case next_char
when 'o'
if next_char == 'n'
return check_ident_or_keyword(:union, start)
end
when 'n'
if char_sequence?('i', 't', 'i', 'a', 'l', 'i', 'z', 'e', 'd')
return check_ident_or_keyword(:uninitialized, start)
end
else
# scan_ident
end
when 'l'
if char_sequence?('e', 's', 's')
return check_ident_or_keyword(:unless, start)
end
when 't'
if char_sequence?('i', 'l')
return check_ident_or_keyword(:until, start)
end
else
# scan_ident
end
end
scan_ident(start)
when 'v'
if char_sequence?('e', 'r', 'b', 'a', 't', 'i', 'm')
return check_ident_or_keyword(:verbatim, start)
end
scan_ident(start)
when 'w'
case next_char
when 'h'
case next_char
when 'e'
if next_char == 'n'
return check_ident_or_keyword(:when, start)
end
when 'i'
if char_sequence?('l', 'e')
return check_ident_or_keyword(:while, start)
end
else
# scan_ident
end
when 'i'
if char_sequence?('t', 'h')
return check_ident_or_keyword(:with, start)
end
else
# scan_ident
end
scan_ident(start)
when 'y'
if char_sequence?('i', 'e', 'l', 'd')
return check_ident_or_keyword(:yield, start)
end
scan_ident(start)
when '_'
case next_char
when '_'
case next_char
when 'D'
if char_sequence?('I', 'R', '_', '_')
unless ident_part_or_end?(peek_next_char)
next_char :MAGIC_DIR
return @token
end
end
when 'E'
if char_sequence?('N', 'D', '_', 'L', 'I', 'N', 'E', '_', '_')
unless ident_part_or_end?(peek_next_char)
next_char :MAGIC_END_LINE
return @token
end
end
when 'F'