@@ -8,6 +8,8 @@ class Lexer
8
8
9
9
attr_accessor :lex_state , :strterm , :scanner
10
10
11
+ attr_accessor :yylval
12
+
11
13
def initialize ( source , file )
12
14
@lex_state = :expr_beg
13
15
@cond = 0
@@ -81,6 +83,14 @@ def set_arg_state
81
83
end
82
84
83
85
def scan ( regexp )
86
+ if result = @scanner . scan ( regexp )
87
+ @yylval += @scanner . matched
88
+ end
89
+
90
+ result
91
+ end
92
+
93
+ def skip_scan ( regexp )
84
94
@scanner . scan regexp
85
95
end
86
96
@@ -97,9 +107,11 @@ def matched
97
107
end
98
108
99
109
def next_token
100
- old = self . yylex
101
- loc = [ @line , @column ]
102
- [ old [ 0 ] , [ old [ 1 ] , loc ] ]
110
+ token = self . yylex
111
+ value = self . yylval
112
+ location = [ @line , @column ]
113
+
114
+ [ token , [ value , location ] ]
103
115
end
104
116
105
117
def strterm_expand? ( strterm )
@@ -122,15 +134,20 @@ def process_numeric
122
134
scanner = @scanner
123
135
124
136
if scan ( /0b?(0|1|_)+/ )
125
- return [ :tINTEGER , scanner . matched . to_i ( 2 ) ]
137
+ self . yylval = scanner . matched . to_i ( 2 )
138
+ return :tINTEGER
126
139
elsif scan ( /0o?([0-7]|_)+/ )
127
- return [ :tINTEGER , scanner . matched . to_i ( 8 ) ]
140
+ self . yylval = scanner . matched . to_i ( 8 )
141
+ return :tINTEGER
128
142
elsif scan ( /[\d _]+\. [\d _]+\b |[\d _]+(\. [\d _]+)?[eE][-+]?[\d _]+\b / )
129
- return [ :tFLOAT , scanner . matched . gsub ( /_/ , '' ) . to_f ]
143
+ self . yylval = scanner . matched . gsub ( /_/ , '' ) . to_f
144
+ return :tFLOAT
130
145
elsif scan ( /[\d _]+\b / )
131
- return [ :tINTEGER , scanner . matched . gsub ( /_/ , '' ) . to_i ]
146
+ self . yylval = scanner . matched . gsub ( /_/ , '' ) . to_i
147
+ return :tINTEGER
132
148
elsif scan ( /0(x|X)(\d |[a-f]|[A-F]|_)+/ )
133
- return [ :tINTEGER , scanner . matched . to_i ( 16 ) ]
149
+ self . yylval = scanner . matched . to_i ( 16 )
150
+ return :tINTEGER
134
151
else
135
152
raise "Lexing error on numeric type: `#{ scanner . peek 5 } `"
136
153
end
@@ -163,7 +180,7 @@ def next_string_token
163
180
end
164
181
165
182
@lex_state = :expr_end
166
- return :tSTRING_END , scanner . matched
183
+ return :tSTRING_END
167
184
end
168
185
end
169
186
@@ -173,7 +190,8 @@ def next_string_token
173
190
if words && !str_parse [ :done_last_space ] #&& space
174
191
str_parse [ :done_last_space ] = true
175
192
pushback ( 1 )
176
- return :tSPACE , ' '
193
+ self . yylval = ' '
194
+ return :tSPACE
177
195
end
178
196
self . strterm = nil
179
197
@@ -182,10 +200,10 @@ def next_string_token
182
200
@lex_state = :expr_end
183
201
184
202
if str_parse [ :type ] == :regexp
185
- result = scan ( /\w +/ )
186
- return :tREGEXP_END , result
203
+ self . yylval = scan ( /\w +/ )
204
+ return :tREGEXP_END
187
205
end
188
- return :tSTRING_END , scanner . matched
206
+ return :tSTRING_END
189
207
else
190
208
str_buffer << scanner . matched
191
209
str_parse [ :nesting ] -= 1
@@ -194,16 +212,16 @@ def next_string_token
194
212
195
213
elsif [ '"' , "'" ] . include? str_parse [ :beg ]
196
214
@lex_state = :expr_end
197
- return :tSTRING_END , scanner . matched
215
+ return :tSTRING_END
198
216
199
217
elsif str_parse [ :beg ] == '`'
200
218
@lex_state = :expr_end
201
- return :tSTRING_END , scanner . matched
219
+ return :tSTRING_END
202
220
203
221
elsif str_parse [ :beg ] == '/' || str_parse [ :type ] == :regexp
204
- result = scan ( /\w +/ )
205
222
@lex_state = :expr_end
206
- return :tREGEXP_END , result
223
+ self . yylval = scan ( /\w +/ )
224
+ return :tREGEXP_END
207
225
208
226
else
209
227
if str_parse [ :scanner ]
@@ -212,27 +230,30 @@ def next_string_token
212
230
end
213
231
214
232
@lex_state = :expr_end
215
- return :tSTRING_END , scanner . matched
233
+ return :tSTRING_END
216
234
end
217
235
end
218
236
219
- return :tSPACE , ' ' if space
237
+ if space
238
+ self . yylval = ' '
239
+ return :tSPACE
240
+ end
220
241
221
242
if str_parse [ :balance ] and scan Regexp . new ( Regexp . escape ( str_parse [ :beg ] ) )
222
243
str_buffer << scanner . matched
223
244
str_parse [ :nesting ] += 1
224
245
elsif check ( /#[@$]/ )
225
246
scan ( /#/ )
226
247
if expand
227
- return :tSTRING_DVAR , scanner . matched
248
+ return :tSTRING_DVAR
228
249
else
229
250
str_buffer << scanner . matched
230
251
end
231
252
232
253
elsif scan ( /#\{ / )
233
254
if expand
234
255
# we are into ruby code, so stop parsing content (for now)
235
- return :tSTRING_DBEG , scanner . matched
256
+ return :tSTRING_DBEG
236
257
else
237
258
str_buffer << scanner . matched
238
259
end
@@ -250,7 +271,9 @@ def next_string_token
250
271
251
272
complete_str = str_buffer . join ''
252
273
@line += complete_str . count ( "\n " )
253
- return :tSTRING_CONTENT , complete_str
274
+
275
+ self . yylval = complete_str
276
+ return :tSTRING_CONTENT
254
277
end
255
278
256
279
def add_heredoc_content ( str_buffer , str_parse )
@@ -402,7 +425,8 @@ def heredoc_identifier
402
425
end_of_line = @scanner . scan ( /.*\n / )
403
426
self . strterm [ :scanner ] = StringScanner . new ( end_of_line ) if end_of_line != "\n "
404
427
405
- return :tSTRING_BEG , heredoc
428
+ self . yylval = heredoc
429
+ return :tSTRING_BEG
406
430
end
407
431
end
408
432
@@ -412,17 +436,18 @@ def process_identifier(matched, cmd_start)
412
436
413
437
if scanner . peek ( 2 ) != '::' && scan ( /:/ )
414
438
@lex_state = :expr_beg
415
- return :tLABEL , "#{ matched } "
439
+ self . yylval = matched
440
+ return :tLABEL
416
441
end
417
442
418
443
if matched == 'defined?'
419
444
if after_operator?
420
445
@lex_state = :expr_end
421
- return :tIDENTIFIER , matched
446
+ return :tIDENTIFIER
422
447
end
423
448
424
449
@lex_state = :expr_arg
425
- return :kDEFINED , 'defined?'
450
+ return :kDEFINED
426
451
end
427
452
428
453
if matched . end_with? '?' , '!'
@@ -446,7 +471,8 @@ def process_identifier(matched, cmd_start)
446
471
@lex_state = kw . state
447
472
448
473
if old_state == :expr_fname
449
- return [ kw . id [ 0 ] , kw . name ]
474
+ self . yylval = kw . name
475
+ return kw . id [ 0 ]
450
476
end
451
477
452
478
if @lex_state == :expr_beg
@@ -456,34 +482,36 @@ def process_identifier(matched, cmd_start)
456
482
if matched == "do"
457
483
if after_operator?
458
484
@lex_state = :expr_end
459
- return :tIDENTIFIER , matched
485
+ return :tIDENTIFIER
460
486
end
461
487
462
488
if @start_of_lambda
463
489
@start_of_lambda = false
464
490
@lex_state = :expr_beg
465
- return [ :kDO_LAMBDA , scanner . matched ]
491
+ return :kDO_LAMBDA
466
492
elsif cond?
467
493
@lex_state = :expr_beg
468
- return :kDO_COND , matched
494
+ return :kDO_COND
469
495
elsif cmdarg? && @lex_state != :expr_cmdarg
470
496
@lex_state = :expr_beg
471
- return :kDO_BLOCK , matched
497
+ return :kDO_BLOCK
472
498
elsif @lex_state == :expr_endarg
473
- return :kDO_BLOCK , matched
499
+ return :kDO_BLOCK
474
500
else
475
501
@lex_state = :expr_beg
476
- return :kDO , matched
502
+ return :kDO
477
503
end
478
504
else
479
505
if old_state == :expr_beg or old_state == :expr_value
480
- return [ kw . id [ 0 ] , matched ]
506
+ self . yylval = matched
507
+ return kw . id [ 0 ]
481
508
else
482
509
if kw . id [ 0 ] != kw . id [ 1 ]
483
510
@lex_state = :expr_beg
484
511
end
485
512
486
- return [ kw . id [ 1 ] , matched ]
513
+ self . yylval = matched
514
+ return kw . id [ 1 ]
487
515
end
488
516
end
489
517
end
@@ -494,10 +522,11 @@ def process_identifier(matched, cmd_start)
494
522
@lex_state = :expr_end
495
523
end
496
524
497
- return [ matched =~ /^[A-Z]/ ? :tCONSTANT : :tIDENTIFIER , matched ]
525
+ return matched =~ /^[A-Z]/ ? :tCONSTANT : :tIDENTIFIER
498
526
end
499
527
500
528
def yylex
529
+ @yylval = ''
501
530
@space_seen = false
502
531
cmd_start = false
503
532
c = ''
@@ -507,20 +536,20 @@ def yylex
507
536
end
508
537
509
538
while true
510
- if scan ( /\ |\t |\r / )
539
+ if skip_scan ( /\ |\t |\r / )
511
540
@space_seen = true
512
541
next
513
542
514
- elsif scan ( /(\n |#)/ )
543
+ elsif skip_scan ( /(\n |#)/ )
515
544
c = scanner . matched
516
- if c == '#' then scan ( /(.*)/ ) else @line += 1 ; end
545
+ if c == '#' then skip_scan ( /(.*)/ ) else @line += 1 ; end
517
546
518
- scan ( /(\n +)/ )
547
+ skip_scan ( /(\n +)/ )
519
548
@line += scanner . matched . length if scanner . matched
520
549
521
550
next if [ :expr_beg , :expr_dot ] . include? @lex_state
522
551
523
- if scan ( /([\ \t \r \f \v ]*)\. / )
552
+ if skip_scan ( /([\ \t \r \f \v ]*)\. / )
524
553
@space_seen = true unless scanner [ 1 ] . empty?
525
554
scanner . pos = scanner . pos - 1
526
555
@@ -529,37 +558,40 @@ def yylex
529
558
530
559
cmd_start = true
531
560
@lex_state = :expr_beg
532
- return :tNL , '\\n'
561
+ self . yylval = '\\n'
562
+ return :tNL
533
563
534
564
elsif scan ( /\; / )
535
565
@lex_state = :expr_beg
536
- return :tSEMI , ';'
566
+ return :tSEMI
537
567
538
568
elsif check ( /\* / )
539
569
if scan ( /\* \* \= / )
540
570
@lex_state = :expr_beg
541
- return :tOP_ASGN , '**'
571
+ self . yylval = '**'
572
+ return :tOP_ASGN
542
573
elsif scan ( /\* \* / )
543
574
self . set_arg_state
544
- return :tPOW , '**'
575
+ return :tPOW
545
576
elsif scan ( /\* \= / )
546
577
@lex_state = :expr_beg
547
- return :tOP_ASGN , '*'
578
+ self . yylval = '*'
579
+ return :tOP_ASGN
548
580
else
549
- result = scan ( /\* / )
581
+ scan ( /\* / )
550
582
551
583
if after_operator?
552
584
@lex_state = :expr_arg
553
- return :tSTAR2 , result
585
+ return :tSTAR2
554
586
elsif @space_seen && check ( /\S / )
555
587
@lex_state = :expr_beg
556
- return :tSTAR , result
588
+ return :tSTAR
557
589
elsif [ :expr_beg , :expr_mid ] . include? @lex_state
558
590
@lex_state = :expr_beg
559
- return :tSTAR , result
591
+ return :tSTAR
560
592
else
561
593
@lex_state = :expr_beg
562
- return :tSTAR2 , result
594
+ return :tSTAR2
563
595
end
564
596
end
565
597
@@ -575,13 +607,13 @@ def yylex
575
607
end
576
608
577
609
if c == '='
578
- return :tNEQ , '!='
610
+ return :tNEQ
579
611
elsif c == '~'
580
- return :tNMATCH , '!~'
612
+ return :tNMATCH
581
613
end
582
614
583
- scanner . pos = scanner . pos - 1
584
- return :tBANG , '!'
615
+ pushback ( 1 )
616
+ return :tBANG
585
617
586
618
elsif scan ( /\= / )
587
619
if @lex_state == :expr_beg and !@space_seen
@@ -613,45 +645,47 @@ def yylex
613
645
614
646
if scan ( /\= / )
615
647
if scan ( /\= / )
616
- return :tEQQ , '==='
648
+ return :tEQQ
617
649
end
618
650
619
- return :tEQ , '=='
651
+ return :tEQ
620
652
end
621
653
622
654
if scan ( /\~ / )
623
- return :tMATCH , '=~'
655
+ return :tMATCH
624
656
elsif scan ( /\> / )
625
- return :tASSOC , '=>'
657
+ return :tASSOC
626
658
end
627
659
628
- return :tEQL , '='
660
+ return :tEQL
629
661
630
662
elsif scan ( /\" / )
631
663
self . strterm = new_strterm ( :dquote , '"' , '"' )
632
- return :tSTRING_BEG , scanner . matched
664
+ return :tSTRING_BEG
633
665
634
666
elsif scan ( /\' / )
635
667
self . strterm = new_strterm ( :squote , "'" , "'" )
636
- return :tSTRING_BEG , scanner . matched
668
+ return :tSTRING_BEG
637
669
638
670
elsif scan ( /\` / )
639
671
self . strterm = new_strterm ( :xquote , '`' , '`' )
640
- return :tXSTRING_BEG , scanner . matched
672
+ return :tXSTRING_BEG
641
673
642
674
elsif scan ( /\& / )
643
675
if scan ( /\& / )
644
676
@lex_state = :expr_beg
645
677
646
678
if scan ( /\= / )
647
- return :tOP_ASGN , '&&'
679
+ self . yylval = '&&'
680
+ return :tOP_ASGN
648
681
end
649
682
650
- return :tANDOP , '&&'
683
+ return :tANDOP
651
684
652
685
elsif scan ( /\= / )
653
686
@lex_state = :expr_beg
654
- return :tOP_ASGN , '&'
687
+ self . yylval = '&'
688
+ return :tOP_ASGN
655
689
end
656
690
657
691
if spcarg?
@@ -665,23 +699,25 @@ def yylex
665
699
end
666
700
667
701
self . set_arg_state
668
- return result , '&'
702
+ return result
669
703
670
704
elsif scan ( /\| / )
671
705
if scan ( /\| / )
672
706
@lex_state = :expr_beg
673
707
if scan ( /\= / )
674
- return :tOP_ASGN , '||'
708
+ self . yylval = '||'
709
+ return :tOP_ASGN
675
710
end
676
711
677
- return :tOROP , '||'
712
+ return :tOROP
678
713
679
714
elsif scan ( /\= / )
680
- return :tOP_ASGN , '|'
715
+ self . yylval = '|'
716
+ return :tOP_ASGN
681
717
end
682
718
683
719
self . set_arg_state
684
- return :tPIPE , '|'
720
+ return :tPIPE
685
721
686
722
elsif scan ( /\% [QqWwixr]/ )
687
723
str_type = scanner . matched [ 1 , 1 ]
@@ -697,62 +733,64 @@ def yylex
697
733
case str_type
698
734
when 'Q'
699
735
self . strterm = new_strterm2 ( :dquote , paren , term )
700
- return :tSTRING_BEG , scanner . matched
736
+ return :tSTRING_BEG
701
737
when 'q'
702
738
self . strterm = new_strterm2 ( :squote , paren , term )
703
- return :tSTRING_BEG , scanner . matched
739
+ return :tSTRING_BEG
704
740
when 'W'
705
741
self . strterm = new_strterm ( :dword , 'W' , term )
706
- scan ( /\s */ )
707
- return :tWORDS_BEG , scanner . matched
742
+ skip_scan ( /\s */ )
743
+ return :tWORDS_BEG
708
744
when 'w' , 'i'
709
745
self . strterm = new_strterm ( :sword , 'w' , term )
710
- scan ( /\s */ )
711
- return :tAWORDS_BEG , scanner . matched
746
+ skip_scan ( /\s */ )
747
+ return :tAWORDS_BEG
712
748
when 'x'
713
749
self . strterm = new_strterm2 ( :xquote , paren , term )
714
- return :tXSTRING_BEG , scanner . matched
750
+ return :tXSTRING_BEG
715
751
when 'r'
716
752
self . strterm = new_strterm2 ( :regexp , paren , term )
717
- return :tREGEXP_BEG , scanner . matched
753
+ return :tREGEXP_BEG
718
754
end
719
755
720
756
elsif scan ( /\/ / )
721
757
if beg?
722
758
self . strterm = new_strterm ( :regexp , '/' , '/' )
723
- return :tREGEXP_BEG , scanner . matched
759
+ return :tREGEXP_BEG
724
760
elsif scan ( /\= / )
725
761
@lex_state = :expr_beg
726
- return :tOP_ASGN , '/'
762
+ self . yylval = '/'
763
+ return :tOP_ASGN
727
764
elsif after_operator?
728
765
@lex_state = :expr_arg
729
766
elsif arg?
730
767
if !check ( /\s / ) && @space_seen
731
768
self . strterm = new_strterm ( :regexp , '/' , '/' )
732
- return :tREGEXP_BEG , scanner . matched
769
+ return :tREGEXP_BEG
733
770
end
734
771
else
735
772
@lex_state = :expr_beg
736
773
end
737
774
738
- return :tDIVIDE , '/'
775
+ return :tDIVIDE
739
776
740
777
elsif scan ( /\% / )
741
778
if scan ( /\= / )
742
779
@lex_state = :expr_beg
743
- return :tOP_ASGN , '%'
780
+ self . yylval = '%'
781
+ return :tOP_ASGN
744
782
elsif check ( /[^\s ]/ )
745
783
if @lex_state == :expr_beg or ( @lex_state == :expr_arg && @space_seen )
746
784
start_word = scan ( /./ )
747
785
end_word = { '(' => ')' , '[' => ']' , '{' => '}' } [ start_word ] || start_word
748
786
self . strterm = new_strterm2 ( :dquote , start_word , end_word )
749
- return :tSTRING_BEG , scanner . matched
787
+ return :tSTRING_BEG
750
788
end
751
789
end
752
790
753
791
self . set_arg_state
754
792
755
- return :tPERCENT , '%'
793
+ return :tPERCENT
756
794
757
795
elsif scan ( /\\ / )
758
796
if scan ( /\r ?\n / )
@@ -776,84 +814,84 @@ def yylex
776
814
cond_push 0
777
815
cmdarg_push 0
778
816
779
- return result , scanner . matched
817
+ return result
780
818
781
819
elsif scan ( /\) / )
782
820
cond_lexpop
783
821
cmdarg_lexpop
784
822
@lex_state = :expr_end
785
- return :tRPAREN , scanner . matched
823
+ return :tRPAREN
786
824
787
825
elsif scan ( /\[ / )
788
826
result = scanner . matched
789
827
790
828
if after_operator?
791
829
@lex_state = :expr_arg
792
830
if scan ( /\] =/ )
793
- return :tASET , '[]='
831
+ return :tASET
794
832
elsif scan ( /\] / )
795
- return :tAREF , '[]'
833
+ return :tAREF
796
834
else
797
835
raise "Unexpected '[' token"
798
836
end
799
837
elsif beg? || @space_seen
800
838
@lex_state = :expr_beg
801
839
cond_push 0
802
840
cmdarg_push 0
803
- return :tLBRACK , scanner . matched
841
+ return :tLBRACK
804
842
else
805
843
@lex_state = :expr_beg
806
844
cond_push 0
807
845
cmdarg_push 0
808
- return :tLBRACK2 , scanner . matched
846
+ return :tLBRACK2
809
847
end
810
848
811
849
elsif scan ( /\] / )
812
850
cond_lexpop
813
851
cmdarg_lexpop
814
852
@lex_state = :expr_end
815
- return :tRBRACK , scanner . matched
853
+ return :tRBRACK
816
854
817
855
elsif scan ( /\} / )
818
856
cond_lexpop
819
857
cmdarg_lexpop
820
858
@lex_state = :expr_end
821
859
822
- return :tRCURLY , scanner . matched
860
+ return :tRCURLY
823
861
824
862
elsif scan ( /\. \. \. / )
825
863
@lex_state = :expr_beg
826
- return :tDOT3 , scanner . matched
864
+ return :tDOT3
827
865
828
866
elsif scan ( /\. \. / )
829
867
@lex_state = :expr_beg
830
- return :tDOT2 , scanner . matched
868
+ return :tDOT2
831
869
832
870
elsif scan ( /\. / )
833
871
@lex_state = :expr_dot unless @lex_state == :expr_fname
834
- return :tDOT , scanner . matched
872
+ return :tDOT
835
873
836
874
elsif scan ( /\: \: / )
837
875
if beg?
838
876
@lex_state = :expr_beg
839
- return :tCOLON3 , scanner . matched
877
+ return :tCOLON3
840
878
elsif spcarg?
841
879
@lex_state = :expr_beg
842
- return :tCOLON3 , scanner . matched
880
+ return :tCOLON3
843
881
end
844
882
845
883
@lex_state = :expr_dot
846
- return :tCOLON2 , scanner . matched
884
+ return :tCOLON2
847
885
848
886
elsif scan ( /\: / )
849
887
if end? || check ( /\s / )
850
888
unless check ( /\w / )
851
889
@lex_state = :expr_beg
852
- return :tCOLON , ':'
890
+ return :tCOLON
853
891
end
854
892
855
893
@lex_state = :expr_fname
856
- return :tSYMBEG , ':'
894
+ return :tSYMBEG
857
895
end
858
896
859
897
if scan ( /\' / )
@@ -863,33 +901,37 @@ def yylex
863
901
end
864
902
865
903
@lex_state = :expr_fname
866
- return :tSYMBEG , ':'
904
+ return :tSYMBEG
867
905
868
906
elsif scan ( /\^ \= / )
869
907
@lex_state = :expr_beg
870
- return :tOP_ASGN , '^'
908
+ self . yylval = '^'
909
+ return :tOP_ASGN
910
+
871
911
elsif scan ( /\^ / )
872
912
self . set_arg_state
873
- return :tCARET , scanner . matched
913
+ return :tCARET
874
914
875
915
elsif check ( /\< / )
876
916
if scan ( /\< \< \= / )
877
917
@lex_state = :expr_beg
878
- return :tOP_ASGN , '<<'
918
+ self . yylval = '<<'
919
+ return :tOP_ASGN
920
+
879
921
elsif scan ( /\< \< / )
880
922
if after_operator?
881
923
@lex_state = :expr_arg
882
- return :tLSHFT , '<<'
924
+ return :tLSHFT
883
925
elsif !after_operator? && !end? && ( !arg? || @space_seen )
884
926
if token = heredoc_identifier
885
927
return token
886
928
end
887
929
888
930
@lex_state = :expr_beg
889
- return :tLSHFT , '<<'
931
+ return :tLSHFT
890
932
end
891
933
@lex_state = :expr_beg
892
- return :tLSHFT , '<<'
934
+ return :tLSHFT
893
935
elsif scan ( /\< \= \> / )
894
936
if after_operator?
895
937
@lex_state = :expr_arg
@@ -901,37 +943,39 @@ def yylex
901
943
@lex_state = :expr_beg
902
944
end
903
945
904
- return :tCMP , '<=>'
946
+ return :tCMP
905
947
elsif scan ( /\< \= / )
906
948
self . set_arg_state
907
- return :tLEQ , '<='
949
+ return :tLEQ
908
950
909
951
elsif scan ( /\< / )
910
952
self . set_arg_state
911
- return :tLT , '<'
953
+ return :tLT
912
954
end
913
955
914
956
elsif check ( /\> / )
915
957
if scan ( /\> \> \= / )
916
- return :tOP_ASGN , '>>'
958
+ self . yylval = '>>'
959
+ return :tOP_ASGN
960
+
917
961
elsif scan ( /\> \> / )
918
962
self . set_arg_state
919
- return :tRSHFT , '>>'
963
+ return :tRSHFT
920
964
921
965
elsif scan ( /\> \= / )
922
966
self . set_arg_state
923
- return :tGEQ , scanner . matched
967
+ return :tGEQ
924
968
925
969
elsif scan ( /\> / )
926
970
self . set_arg_state
927
- return :tGT , '>'
971
+ return :tGT
928
972
end
929
973
930
974
elsif scan ( /->/ )
931
975
# FIXME: # should be :expr_arg, but '(' breaks it...
932
976
@lex_state = :expr_end
933
977
@start_of_lambda = true
934
- return [ :tLAMBDA , scanner . matched ]
978
+ return :tLAMBDA
935
979
936
980
elsif scan ( /[+-]/ )
937
981
matched = scanner . matched
@@ -943,84 +987,95 @@ def yylex
943
987
944
988
if beg?
945
989
@lex_state = :expr_mid
946
- return [ utype , matched ]
990
+ self . yylval = matched
991
+ return utype
947
992
elsif after_operator?
948
993
@lex_state = :expr_arg
949
- return [ :tIDENTIFIER , matched + '@' ] if scan ( /@/ )
950
- return [ sign , matched ]
994
+ if scan ( /@/ )
995
+ self . yylval = matched + '@'
996
+ return :tIDENTIFIER
997
+ end
998
+
999
+ self . yylval = matched
1000
+ return sign
951
1001
end
952
1002
953
1003
if scan ( /\= / )
954
1004
@lex_state = :expr_beg
955
- return [ :tOP_ASGN , matched ]
1005
+ self . yylval = matched
1006
+ return :tOP_ASGN
956
1007
end
957
1008
958
1009
if spcarg?
959
1010
@lex_state = :expr_mid
960
- return [ utype , matched ]
1011
+ self . yylval = matched
1012
+ return utype
961
1013
end
962
1014
963
1015
@lex_state = :expr_beg
964
- return [ sign , matched ]
1016
+ self . yylval = matched
1017
+ return sign
965
1018
966
1019
elsif scan ( /\? / )
967
1020
if end?
968
1021
@lex_state = :expr_beg
969
- return :tEH , scanner . matched
1022
+ return :tEH
970
1023
end
971
1024
972
1025
unless check ( /\ |\t |\r |\s / )
973
1026
@lex_state = :expr_end
974
- return :tSTRING , scan ( /./ )
1027
+ self . yylval = scan ( /./ )
1028
+ return :tSTRING
975
1029
end
976
1030
977
1031
@lex_state = :expr_beg
978
- return :tEH , scanner . matched
1032
+ return :tEH
979
1033
980
1034
elsif scan ( /\~ / )
981
1035
self . set_arg_state
982
- return :tTILDE , '~'
1036
+ return :tTILDE
983
1037
984
1038
elsif check ( /\$ / )
985
1039
if scan ( /\$ ([1-9]\d *)/ )
986
1040
@lex_state = :expr_end
987
- return :tNTH_REF , scanner . matched . sub ( '$' , '' )
1041
+ self . yylval = scanner . matched . sub ( '$' , '' )
1042
+ return :tNTH_REF
988
1043
989
1044
elsif scan ( /(\$ _)(\w +)/ )
990
1045
@lex_state = :expr_end
991
- return :tGVAR , scanner . matched
1046
+ return :tGVAR
992
1047
993
1048
elsif scan ( /\$ [\+ \' \` \& !@\" ~*$?\/ \\ :;=.,<>_]/ )
994
1049
@lex_state = :expr_end
995
- return :tGVAR , scanner . matched
1050
+ return :tGVAR
996
1051
elsif scan ( /\$ \w +/ )
997
1052
@lex_state = :expr_end
998
- return :tGVAR , scanner . matched
1053
+ return :tGVAR
999
1054
else
1000
1055
raise "Bad gvar name: #{ scanner . peek ( 5 ) . inspect } "
1001
1056
end
1002
1057
1003
1058
elsif scan ( /\$ \w +/ )
1004
1059
@lex_state = :expr_end
1005
- return :tGVAR , scanner . matched
1060
+ return :tGVAR
1006
1061
1007
1062
elsif scan ( /\@ \@ \w */ )
1008
1063
@lex_state = :expr_end
1009
- return :tCVAR , scanner . matched
1064
+ return :tCVAR
1010
1065
1011
1066
elsif scan ( /\@ \w */ )
1012
1067
@lex_state = :expr_end
1013
- return :tIVAR , scanner . matched
1068
+ return :tIVAR
1014
1069
1015
1070
elsif scan ( /\, / )
1016
1071
@lex_state = :expr_beg
1017
- return :tCOMMA , scanner . matched
1072
+ return :tCOMMA
1018
1073
1019
1074
elsif scan ( /\{ / )
1020
1075
if @start_of_lambda
1021
1076
@start_of_lambda = false
1022
1077
@lex_state = :expr_beg
1023
- return [ :tLAMBEG , scanner . matched ]
1078
+ return :tLAMBEG
1024
1079
1025
1080
elsif arg? or @lex_state == :expr_end
1026
1081
result = :tLCURLY
@@ -1033,7 +1088,7 @@ def yylex
1033
1088
@lex_state = :expr_beg
1034
1089
cond_push 0
1035
1090
cmdarg_push 0
1036
- return result , scanner . matched
1091
+ return result
1037
1092
1038
1093
elsif check ( /[0-9]/ )
1039
1094
return process_numeric
@@ -1044,7 +1099,8 @@ def yylex
1044
1099
1045
1100
if scanner . eos?
1046
1101
if @scanner_stack . size == 1 # our main scanner, we cant pop this
1047
- return [ false , false ]
1102
+ self . yylval = false
1103
+ return false
1048
1104
else # we were probably parsing a heredoc, so pop that parser and continue
1049
1105
@scanner_stack . pop
1050
1106
@scanner = @scanner_stack . last
0 commit comments