ruby_parser 3.17.0 → 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +76 -0
- data/Manifest.txt +3 -0
- data/README.rdoc +1 -0
- data/Rakefile +68 -18
- data/bin/ruby_parse_extract_error +1 -1
- data/compare/normalize.rb +6 -1
- data/gauntlet.md +106 -0
- data/lib/rp_extensions.rb +15 -36
- data/lib/rp_stringscanner.rb +20 -51
- data/lib/ruby20_parser.rb +3445 -3394
- data/lib/ruby20_parser.y +326 -248
- data/lib/ruby21_parser.rb +3543 -3511
- data/lib/ruby21_parser.y +321 -245
- data/lib/ruby22_parser.rb +3553 -3512
- data/lib/ruby22_parser.y +325 -247
- data/lib/ruby23_parser.rb +3566 -3530
- data/lib/ruby23_parser.y +325 -247
- data/lib/ruby24_parser.rb +3595 -3548
- data/lib/ruby24_parser.y +325 -247
- data/lib/ruby25_parser.rb +3595 -3547
- data/lib/ruby25_parser.y +325 -247
- data/lib/ruby26_parser.rb +3605 -3560
- data/lib/ruby26_parser.y +324 -246
- data/lib/ruby27_parser.rb +4657 -3539
- data/lib/ruby27_parser.y +878 -253
- data/lib/ruby30_parser.rb +5230 -3882
- data/lib/ruby30_parser.y +1069 -321
- data/lib/ruby3_parser.yy +3467 -0
- data/lib/ruby_lexer.rb +261 -609
- data/lib/ruby_lexer.rex +27 -20
- data/lib/ruby_lexer.rex.rb +59 -23
- data/lib/ruby_lexer_strings.rb +638 -0
- data/lib/ruby_parser.yy +910 -263
- data/lib/ruby_parser_extras.rb +289 -114
- data/test/test_ruby_lexer.rb +181 -129
- data/test/test_ruby_parser.rb +1213 -108
- data/tools/munge.rb +34 -6
- data/tools/ripper.rb +15 -10
- data.tar.gz.sig +0 -0
- metadata +11 -12
- metadata.gz.sig +0 -0
data/lib/ruby27_parser.y
CHANGED
@@ -18,7 +18,7 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
|
|
18
18
|
tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
|
19
19
|
tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END
|
20
20
|
tSTRING tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA
|
21
|
-
tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
|
21
|
+
tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
|
22
22
|
tRATIONAL tIMAGINARY
|
23
23
|
tLABEL_END
|
24
24
|
tLONELY
|
@@ -80,7 +80,7 @@ rule
|
|
80
80
|
| klBEGIN
|
81
81
|
{
|
82
82
|
if (self.in_def || self.in_single > 0) then
|
83
|
-
|
83
|
+
debug 11
|
84
84
|
yyerror "BEGIN in method"
|
85
85
|
end
|
86
86
|
self.env.extend
|
@@ -105,6 +105,8 @@ rule
|
|
105
105
|
bodystmt: compstmt opt_rescue k_else
|
106
106
|
{
|
107
107
|
res = _values[-2]
|
108
|
+
# TODO: move down to main match so I can just use val
|
109
|
+
|
108
110
|
yyerror "else without rescue is useless" unless res
|
109
111
|
}
|
110
112
|
compstmt
|
@@ -135,7 +137,7 @@ rule
|
|
135
137
|
| error stmt
|
136
138
|
{
|
137
139
|
result = val[1]
|
138
|
-
|
140
|
+
debug 12
|
139
141
|
}
|
140
142
|
|
141
143
|
stmt_or_begin: stmt
|
@@ -143,6 +145,10 @@ rule
|
|
143
145
|
{
|
144
146
|
yyerror "BEGIN is permitted only at toplevel"
|
145
147
|
}
|
148
|
+
begin_block
|
149
|
+
{
|
150
|
+
result = val[2] # wtf?
|
151
|
+
}
|
146
152
|
|
147
153
|
stmt: kALIAS fitem
|
148
154
|
{
|
@@ -155,12 +161,12 @@ rule
|
|
155
161
|
}
|
156
162
|
| kALIAS tGVAR tGVAR
|
157
163
|
{
|
158
|
-
(_, line), lhs, rhs = val
|
164
|
+
(_, line), (lhs, _), (rhs, _) = val
|
159
165
|
result = s(:valias, lhs.to_sym, rhs.to_sym).line line
|
160
166
|
}
|
161
167
|
| kALIAS tGVAR tBACK_REF
|
162
168
|
{
|
163
|
-
(_, line), lhs, rhs = val
|
169
|
+
(_, line), (lhs, _), (rhs, _) = val
|
164
170
|
result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
|
165
171
|
}
|
166
172
|
| kALIAS tGVAR tNTH_REF
|
@@ -203,7 +209,7 @@ rule
|
|
203
209
|
(_, line), _, stmt, _ = val
|
204
210
|
|
205
211
|
if (self.in_def || self.in_single > 0) then
|
206
|
-
|
212
|
+
debug 13
|
207
213
|
yyerror "END in method; use at_exit"
|
208
214
|
end
|
209
215
|
|
@@ -219,6 +225,15 @@ rule
|
|
219
225
|
lhs, _, rhs = val
|
220
226
|
result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
|
221
227
|
}
|
228
|
+
| mlhs tEQL mrhs_arg kRESCUE_MOD stmt
|
229
|
+
{
|
230
|
+
# unwraps s(:to_ary, rhs)
|
231
|
+
lhs, _, (_, rhs), _, resbody = val
|
232
|
+
|
233
|
+
resbody = new_resbody s(:array).line(resbody.line), resbody
|
234
|
+
|
235
|
+
result = new_masgn lhs, new_rescue(rhs, resbody), :wrap
|
236
|
+
}
|
222
237
|
| mlhs tEQL mrhs_arg
|
223
238
|
{
|
224
239
|
result = new_masgn val[0], val[2]
|
@@ -243,32 +258,31 @@ rule
|
|
243
258
|
}
|
244
259
|
| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
|
245
260
|
{
|
246
|
-
prim, _, id,
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
result.line = val[0].line
|
261
|
+
prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
|
262
|
+
|
263
|
+
result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
|
264
|
+
result.sexp_type = :safe_op_asgn if call_op == '&.'
|
265
|
+
result.line prim.line
|
252
266
|
}
|
253
267
|
| primary_value call_op tCONSTANT tOP_ASGN command_rhs
|
254
268
|
{
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
result.line
|
269
|
+
prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
|
270
|
+
|
271
|
+
result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
|
272
|
+
result.sexp_type = :safe_op_asgn if call_op == '&.'
|
273
|
+
result.line prim.line
|
260
274
|
}
|
261
275
|
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
|
262
276
|
{
|
263
|
-
lhs1, _, lhs2,
|
277
|
+
lhs1, _, (lhs2, line), (id, _), rhs = val
|
264
278
|
|
265
|
-
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym,
|
279
|
+
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
|
266
280
|
}
|
267
281
|
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
|
268
282
|
{
|
269
|
-
lhs1, _, lhs2,
|
283
|
+
lhs1, _, (lhs2, line), (id, _), rhs = val
|
270
284
|
|
271
|
-
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym,
|
285
|
+
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
|
272
286
|
}
|
273
287
|
| backref tOP_ASGN command_rhs
|
274
288
|
{
|
@@ -315,6 +329,28 @@ rule
|
|
315
329
|
# REFACTOR: call_uni_op -- see parse26.y
|
316
330
|
}
|
317
331
|
| arg
|
332
|
+
kIN
|
333
|
+
{
|
334
|
+
# TODO? value_expr($1);
|
335
|
+
self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
|
336
|
+
self.lexer.command_start = false
|
337
|
+
result = self.in_kwarg
|
338
|
+
self.in_kwarg = true
|
339
|
+
self.env.extend
|
340
|
+
}
|
341
|
+
p_expr
|
342
|
+
{
|
343
|
+
self.env.unextend
|
344
|
+
|
345
|
+
expr, _, old_kwarg, pat = val
|
346
|
+
|
347
|
+
expr = value_expr expr
|
348
|
+
|
349
|
+
self.in_kwarg = old_kwarg
|
350
|
+
pat_in = new_in pat, nil, nil, expr.line
|
351
|
+
result = new_case expr, pat_in, expr.line
|
352
|
+
}
|
353
|
+
| arg =tLBRACE_ARG
|
318
354
|
|
319
355
|
expr_value: expr
|
320
356
|
{
|
@@ -339,7 +375,7 @@ rule
|
|
339
375
|
block_command: block_call
|
340
376
|
| block_call call_op2 operation2 command_args
|
341
377
|
{
|
342
|
-
blk, _, msg, args = val
|
378
|
+
blk, _, (msg, _line), args = val
|
343
379
|
result = new_call(blk, msg.to_sym, args).line blk.line
|
344
380
|
}
|
345
381
|
|
@@ -353,15 +389,15 @@ rule
|
|
353
389
|
_, line, body, _ = val
|
354
390
|
|
355
391
|
result = body
|
356
|
-
result.line
|
392
|
+
result.line line
|
357
393
|
|
358
394
|
# self.env.unextend
|
359
395
|
}
|
360
396
|
|
361
397
|
fcall: operation
|
362
398
|
{
|
363
|
-
msg, = val
|
364
|
-
result = new_call(nil, msg.to_sym).line
|
399
|
+
(msg, line), = val
|
400
|
+
result = new_call(nil, msg.to_sym).line line
|
365
401
|
}
|
366
402
|
|
367
403
|
command: fcall command_args =tLOWEST
|
@@ -384,12 +420,14 @@ rule
|
|
384
420
|
}
|
385
421
|
| primary_value call_op operation2 command_args =tLOWEST
|
386
422
|
{
|
387
|
-
lhs, callop, op, args = val
|
423
|
+
lhs, callop, (op, _), args = val
|
424
|
+
|
388
425
|
result = new_call lhs, op.to_sym, args, callop
|
426
|
+
result.line lhs.line
|
389
427
|
}
|
390
428
|
| primary_value call_op operation2 command_args cmd_brace_block
|
391
429
|
{
|
392
|
-
recv, _, msg, args, block = val
|
430
|
+
recv, _, (msg, _line), args, block = val
|
393
431
|
call = new_call recv, msg.to_sym, args, val[1]
|
394
432
|
|
395
433
|
block_dup_check call, block
|
@@ -399,11 +437,14 @@ rule
|
|
399
437
|
}
|
400
438
|
| primary_value tCOLON2 operation2 command_args =tLOWEST
|
401
439
|
{
|
402
|
-
|
440
|
+
lhs, _, (id, line), args = val
|
441
|
+
|
442
|
+
result = new_call lhs, id.to_sym, args
|
443
|
+
result.line line
|
403
444
|
}
|
404
445
|
| primary_value tCOLON2 operation2 command_args cmd_brace_block
|
405
446
|
{
|
406
|
-
recv, _, msg, args, block = val
|
447
|
+
recv, _, (msg, _line), args, block = val
|
407
448
|
call = new_call recv, msg.to_sym, args
|
408
449
|
|
409
450
|
block_dup_check call, block
|
@@ -561,25 +602,29 @@ rule
|
|
561
602
|
}
|
562
603
|
| primary_value call_op tIDENTIFIER
|
563
604
|
{
|
564
|
-
|
605
|
+
lhs, call_op, (id, _line) = val
|
606
|
+
|
607
|
+
result = new_attrasgn lhs, id, call_op
|
565
608
|
}
|
566
609
|
| primary_value tCOLON2 tIDENTIFIER
|
567
610
|
{
|
568
|
-
recv, _, id = val
|
611
|
+
recv, _, (id, _line) = val
|
569
612
|
result = new_attrasgn recv, id
|
570
613
|
}
|
571
614
|
| primary_value call_op tCONSTANT
|
572
615
|
{
|
573
|
-
|
616
|
+
lhs, call_op, (id, _line) = val
|
617
|
+
|
618
|
+
result = new_attrasgn lhs, id, call_op
|
574
619
|
}
|
575
620
|
| primary_value tCOLON2 tCONSTANT
|
576
621
|
{
|
577
622
|
if (self.in_def || self.in_single > 0) then
|
578
|
-
|
623
|
+
debug 14
|
579
624
|
yyerror "dynamic constant assignment"
|
580
625
|
end
|
581
626
|
|
582
|
-
expr, _, id = val
|
627
|
+
expr, _, (id, _line) = val
|
583
628
|
l = expr.line
|
584
629
|
|
585
630
|
result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
|
@@ -587,58 +632,65 @@ rule
|
|
587
632
|
| tCOLON3 tCONSTANT
|
588
633
|
{
|
589
634
|
if (self.in_def || self.in_single > 0) then
|
590
|
-
|
635
|
+
debug 15
|
591
636
|
yyerror "dynamic constant assignment"
|
592
637
|
end
|
593
638
|
|
594
|
-
_, id = val
|
595
|
-
l = lexer.lineno
|
639
|
+
_, (id, l) = val
|
596
640
|
|
597
641
|
result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
|
598
642
|
}
|
599
643
|
| backref
|
600
644
|
{
|
601
|
-
|
645
|
+
ref, = val
|
646
|
+
|
647
|
+
self.backref_assign_error ref
|
602
648
|
}
|
603
649
|
|
604
650
|
lhs: user_variable
|
605
651
|
{
|
606
|
-
|
607
|
-
|
608
|
-
result
|
652
|
+
var, = val
|
653
|
+
|
654
|
+
result = self.assignable var
|
609
655
|
}
|
610
656
|
| keyword_variable
|
611
657
|
{
|
612
|
-
|
613
|
-
|
614
|
-
result
|
615
|
-
|
658
|
+
var, = val
|
659
|
+
|
660
|
+
result = self.assignable var
|
661
|
+
|
662
|
+
debug 16
|
616
663
|
}
|
617
664
|
| primary_value tLBRACK2 opt_call_args rbracket
|
618
665
|
{
|
619
666
|
lhs, _, args, _ = val
|
667
|
+
|
620
668
|
result = self.aryset lhs, args
|
621
669
|
}
|
622
670
|
| primary_value call_op tIDENTIFIER # REFACTOR
|
623
671
|
{
|
624
|
-
lhs, op, id = val
|
672
|
+
lhs, op, (id, _line) = val
|
673
|
+
|
625
674
|
result = new_attrasgn lhs, id, op
|
626
675
|
}
|
627
676
|
| primary_value tCOLON2 tIDENTIFIER
|
628
677
|
{
|
629
|
-
lhs, _, id = val
|
678
|
+
lhs, _, (id, _line) = val
|
679
|
+
|
630
680
|
result = new_attrasgn lhs, id
|
631
681
|
}
|
632
682
|
| primary_value call_op tCONSTANT # REFACTOR?
|
633
683
|
{
|
634
|
-
|
684
|
+
lhs, call_op, (id, _line) = val
|
685
|
+
|
686
|
+
result = new_attrasgn lhs, id, call_op
|
635
687
|
}
|
636
688
|
| primary_value tCOLON2 tCONSTANT
|
637
689
|
{
|
638
|
-
expr, _, id = val
|
690
|
+
expr, _, (id, _line) = val
|
639
691
|
|
640
692
|
if (self.in_def || self.in_single > 0) then
|
641
|
-
|
693
|
+
debug 17
|
642
694
|
yyerror "dynamic constant assignment"
|
643
695
|
end
|
644
696
|
|
@@ -647,14 +699,13 @@ rule
|
|
647
699
|
}
|
648
700
|
| tCOLON3 tCONSTANT
|
649
701
|
{
|
650
|
-
_, id = val
|
702
|
+
_, (id, l) = val
|
651
703
|
|
652
704
|
if (self.in_def || self.in_single > 0) then
|
653
|
-
|
705
|
+
debug 18
|
654
706
|
yyerror "dynamic constant assignment"
|
655
707
|
end
|
656
708
|
|
657
|
-
l = lexer.lineno
|
658
709
|
result = s(:const, s(:colon3, id.to_sym).line(l)).line l
|
659
710
|
}
|
660
711
|
| backref
|
@@ -670,16 +721,17 @@ rule
|
|
670
721
|
|
671
722
|
cpath: tCOLON3 cname
|
672
723
|
{
|
673
|
-
_, name = val
|
674
|
-
result = s(:colon3, name.to_sym).line
|
724
|
+
_, (name, line) = val
|
725
|
+
result = s(:colon3, name.to_sym).line line
|
675
726
|
}
|
676
727
|
| cname
|
677
728
|
{
|
678
|
-
|
729
|
+
(id, line), = val
|
730
|
+
result = [id.to_sym, line] # TODO: sexp?
|
679
731
|
}
|
680
732
|
| primary_value tCOLON2 cname
|
681
733
|
{
|
682
|
-
pval, _, name = val
|
734
|
+
pval, _, (name, _line) = val
|
683
735
|
|
684
736
|
result = s(:colon2, pval, name.to_sym)
|
685
737
|
result.line pval.line
|
@@ -689,24 +741,17 @@ rule
|
|
689
741
|
| op
|
690
742
|
{
|
691
743
|
lexer.lex_state = EXPR_END
|
692
|
-
result = val[0]
|
693
744
|
}
|
694
745
|
|
695
746
|
| reswords
|
696
|
-
{
|
697
|
-
(sym, _line), = val
|
698
|
-
lexer.lex_state = EXPR_END
|
699
|
-
result = sym
|
700
|
-
}
|
701
|
-
|
702
|
-
fsym: fname | symbol
|
703
747
|
|
704
|
-
fitem:
|
748
|
+
fitem: fname
|
705
749
|
{
|
706
|
-
id, = val
|
707
|
-
|
750
|
+
(id, line), = val
|
751
|
+
|
752
|
+
result = s(:lit, id.to_sym).line line
|
708
753
|
}
|
709
|
-
|
|
754
|
+
| symbol
|
710
755
|
|
711
756
|
undef_list: fitem
|
712
757
|
{
|
@@ -727,8 +772,6 @@ rule
|
|
727
772
|
| tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
|
728
773
|
| tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
|
729
774
|
| tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
|
730
|
-
# TODO: tUBANG dead?
|
731
|
-
| tUBANG
|
732
775
|
|
733
776
|
reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
|
734
777
|
| kALIAS | kAND | kBEGIN | kBREAK | kCASE
|
@@ -762,24 +805,20 @@ rule
|
|
762
805
|
}
|
763
806
|
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
|
764
807
|
{
|
765
|
-
lhs, _, id, op, rhs = val
|
808
|
+
lhs, _, (id, _line), (op, _), rhs = val
|
766
809
|
|
767
810
|
result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
|
768
811
|
}
|
769
812
|
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
|
770
813
|
{
|
771
|
-
lhs1, _, lhs2, op, rhs = val
|
814
|
+
lhs1, _, (lhs2, _line), op, rhs = val
|
772
815
|
|
773
816
|
lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
|
774
817
|
result = new_const_op_asgn [lhs, op, rhs]
|
775
818
|
}
|
776
|
-
| tCOLON3 tCONSTANT
|
819
|
+
| tCOLON3 tCONSTANT tOP_ASGN arg_rhs
|
777
820
|
{
|
778
|
-
|
779
|
-
}
|
780
|
-
tOP_ASGN arg_rhs
|
781
|
-
{
|
782
|
-
_, lhs, line, op, rhs = val
|
821
|
+
_, (lhs, line), op, rhs = val
|
783
822
|
|
784
823
|
lhs = s(:colon3, lhs.to_sym).line line
|
785
824
|
result = new_const_op_asgn [lhs, op, rhs]
|
@@ -793,7 +832,7 @@ rule
|
|
793
832
|
| arg tDOT2 arg
|
794
833
|
{
|
795
834
|
v1, v2 = val[0], val[2]
|
796
|
-
if v1.
|
835
|
+
if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
|
797
836
|
result = s(:lit, (v1.last)..(v2.last)).line v1.line
|
798
837
|
else
|
799
838
|
result = s(:dot2, v1, v2).line v1.line
|
@@ -802,7 +841,7 @@ rule
|
|
802
841
|
| arg tDOT3 arg
|
803
842
|
{
|
804
843
|
v1, v2 = val[0], val[2]
|
805
|
-
if v1.
|
844
|
+
if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
|
806
845
|
result = s(:lit, (v1.last)...(v2.last)).line v1.line
|
807
846
|
else
|
808
847
|
result = s(:dot3, v1, v2).line v1.line
|
@@ -864,8 +903,9 @@ rule
|
|
864
903
|
}
|
865
904
|
| tUMINUS_NUM simple_numeric tPOW arg
|
866
905
|
{
|
867
|
-
|
868
|
-
|
906
|
+
_, (num, line), _, arg = val
|
907
|
+
lit = s(:lit, num).line line
|
908
|
+
result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
|
869
909
|
|
870
910
|
}
|
871
911
|
| tUPLUS arg
|
@@ -964,12 +1004,12 @@ rule
|
|
964
1004
|
|
965
1005
|
rel_expr: arg relop arg =tGT
|
966
1006
|
{
|
967
|
-
lhs, op, rhs = val
|
1007
|
+
lhs, (op, _), rhs = val
|
968
1008
|
result = new_call lhs, op.to_sym, argl(rhs)
|
969
1009
|
}
|
970
1010
|
| rel_expr relop arg =tGT
|
971
1011
|
{
|
972
|
-
lhs, op, rhs = val
|
1012
|
+
lhs, (op, _), rhs = val
|
973
1013
|
warn "comparison '%s' after comparison", op
|
974
1014
|
result = new_call lhs, op.to_sym, argl(rhs)
|
975
1015
|
}
|
@@ -1178,8 +1218,9 @@ rule
|
|
1178
1218
|
| backref
|
1179
1219
|
| tFID
|
1180
1220
|
{
|
1181
|
-
msg, = val
|
1221
|
+
(msg, line), = val
|
1182
1222
|
result = new_call nil, msg.to_sym
|
1223
|
+
result.line line
|
1183
1224
|
}
|
1184
1225
|
| k_begin
|
1185
1226
|
{
|
@@ -1221,15 +1262,15 @@ rule
|
|
1221
1262
|
}
|
1222
1263
|
| primary_value tCOLON2 tCONSTANT
|
1223
1264
|
{
|
1224
|
-
expr, _, id = val
|
1265
|
+
expr, _, (id, _line) = val
|
1225
1266
|
|
1226
1267
|
result = s(:colon2, expr, id.to_sym).line expr.line
|
1227
1268
|
}
|
1228
1269
|
| tCOLON3 tCONSTANT
|
1229
1270
|
{
|
1230
|
-
_, id = val
|
1271
|
+
_, (id, line) = val
|
1231
1272
|
|
1232
|
-
result = s(:colon3, id.to_sym).line
|
1273
|
+
result = s(:colon3, id.to_sym).line line
|
1233
1274
|
}
|
1234
1275
|
| tLBRACK { result = lexer.lineno } aref_args tRBRACK
|
1235
1276
|
{
|
@@ -1276,7 +1317,7 @@ rule
|
|
1276
1317
|
}
|
1277
1318
|
| kNOT tLPAREN2 rparen
|
1278
1319
|
{
|
1279
|
-
|
1320
|
+
debug 20
|
1280
1321
|
}
|
1281
1322
|
| fcall brace_block
|
1282
1323
|
{
|
@@ -1294,9 +1335,10 @@ rule
|
|
1294
1335
|
iter.insert 1, call # FIX
|
1295
1336
|
result = iter
|
1296
1337
|
}
|
1297
|
-
|
|
1338
|
+
| lambda
|
1298
1339
|
{
|
1299
|
-
|
1340
|
+
expr, = val
|
1341
|
+
result = expr
|
1300
1342
|
}
|
1301
1343
|
| k_if expr_value then compstmt if_tail k_end
|
1302
1344
|
{
|
@@ -1328,6 +1370,12 @@ rule
|
|
1328
1370
|
(_, line), _, body, _ = val
|
1329
1371
|
result = new_case nil, body, line
|
1330
1372
|
}
|
1373
|
+
| k_case expr_value opt_terms p_case_body k_end
|
1374
|
+
{
|
1375
|
+
(_, line), expr, _, body, _ = val
|
1376
|
+
|
1377
|
+
result = new_case expr, body, line
|
1378
|
+
}
|
1331
1379
|
| k_for for_var kIN expr_value_do compstmt k_end
|
1332
1380
|
{
|
1333
1381
|
_, var, _, iter, body, _ = val
|
@@ -1339,7 +1387,6 @@ rule
|
|
1339
1387
|
}
|
1340
1388
|
cpath superclass
|
1341
1389
|
{
|
1342
|
-
self.comments.push self.lexer.comments
|
1343
1390
|
if (self.in_def || self.in_single > 0) then
|
1344
1391
|
yyerror "class definition in method body"
|
1345
1392
|
end
|
@@ -1349,7 +1396,7 @@ rule
|
|
1349
1396
|
{
|
1350
1397
|
result = new_class val
|
1351
1398
|
self.env.unextend
|
1352
|
-
self.lexer.
|
1399
|
+
self.lexer.ignore_body_comments
|
1353
1400
|
}
|
1354
1401
|
| k_class tLSHFT
|
1355
1402
|
{
|
@@ -1370,7 +1417,7 @@ rule
|
|
1370
1417
|
{
|
1371
1418
|
result = new_sclass val
|
1372
1419
|
self.env.unextend
|
1373
|
-
self.lexer.
|
1420
|
+
self.lexer.ignore_body_comments
|
1374
1421
|
}
|
1375
1422
|
| k_module
|
1376
1423
|
{
|
@@ -1378,7 +1425,6 @@ rule
|
|
1378
1425
|
}
|
1379
1426
|
cpath
|
1380
1427
|
{
|
1381
|
-
self.comments.push self.lexer.comments
|
1382
1428
|
yyerror "module definition in method body" if
|
1383
1429
|
self.in_def or self.in_single > 0
|
1384
1430
|
|
@@ -1388,7 +1434,7 @@ rule
|
|
1388
1434
|
{
|
1389
1435
|
result = new_module val
|
1390
1436
|
self.env.unextend
|
1391
|
-
self.lexer.
|
1437
|
+
self.lexer.ignore_body_comments
|
1392
1438
|
}
|
1393
1439
|
| k_def fname
|
1394
1440
|
{
|
@@ -1398,21 +1444,17 @@ rule
|
|
1398
1444
|
self.env.extend
|
1399
1445
|
lexer.cmdarg.push false
|
1400
1446
|
lexer.cond.push false
|
1401
|
-
|
1402
|
-
self.comments.push self.lexer.comments
|
1403
1447
|
}
|
1404
|
-
f_arglist bodystmt
|
1448
|
+
f_arglist bodystmt k_end
|
1405
1449
|
{
|
1406
|
-
in_def = val
|
1407
|
-
|
1408
|
-
result = new_defn val
|
1450
|
+
result, in_def = new_defn val
|
1409
1451
|
|
1410
1452
|
lexer.cond.pop # group = local_pop
|
1411
1453
|
lexer.cmdarg.pop
|
1412
1454
|
self.env.unextend
|
1413
1455
|
self.in_def = in_def
|
1414
1456
|
|
1415
|
-
self.lexer.
|
1457
|
+
self.lexer.ignore_body_comments
|
1416
1458
|
}
|
1417
1459
|
| k_def singleton dot_or_colon
|
1418
1460
|
{
|
@@ -1420,7 +1462,7 @@ rule
|
|
1420
1462
|
}
|
1421
1463
|
fname
|
1422
1464
|
{
|
1423
|
-
result =
|
1465
|
+
result = self.in_def
|
1424
1466
|
|
1425
1467
|
self.in_single += 1 # TODO: remove?
|
1426
1468
|
|
@@ -1430,13 +1472,18 @@ rule
|
|
1430
1472
|
lexer.cond.push false
|
1431
1473
|
|
1432
1474
|
lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
|
1433
|
-
self.comments.push self.lexer.comments
|
1434
1475
|
}
|
1435
1476
|
f_arglist bodystmt k_end
|
1436
1477
|
{
|
1437
|
-
_, _recv, _, _, _name, (in_def, _lineno), _args, _body, _ = val
|
1438
1478
|
|
1439
|
-
|
1479
|
+
# [kdef, recv, _, _, (name, line), in_def, args, body, kend]
|
1480
|
+
# =>
|
1481
|
+
# [kdef, recv, (name, line), in_def, args, body, kend]
|
1482
|
+
|
1483
|
+
val.delete_at 3
|
1484
|
+
val.delete_at 2
|
1485
|
+
|
1486
|
+
result, in_def = new_defs val
|
1440
1487
|
|
1441
1488
|
lexer.cond.pop # group = local_pop
|
1442
1489
|
lexer.cmdarg.pop
|
@@ -1447,7 +1494,7 @@ rule
|
|
1447
1494
|
|
1448
1495
|
# TODO: restore cur_arg ? what's cur_arg?
|
1449
1496
|
|
1450
|
-
self.lexer.
|
1497
|
+
self.lexer.ignore_body_comments
|
1451
1498
|
}
|
1452
1499
|
| kBREAK
|
1453
1500
|
{
|
@@ -1484,8 +1531,17 @@ rule
|
|
1484
1531
|
k_case: kCASE
|
1485
1532
|
k_for: kFOR
|
1486
1533
|
k_class: kCLASS
|
1534
|
+
{
|
1535
|
+
self.comments.push self.lexer.comments
|
1536
|
+
}
|
1487
1537
|
k_module: kMODULE
|
1538
|
+
{
|
1539
|
+
self.comments.push self.lexer.comments
|
1540
|
+
}
|
1488
1541
|
k_def: kDEF
|
1542
|
+
{
|
1543
|
+
self.comments.push self.lexer.comments
|
1544
|
+
}
|
1489
1545
|
k_do: kDO
|
1490
1546
|
k_do_block: kDO_BLOCK
|
1491
1547
|
k_rescue: kRESCUE
|
@@ -1546,51 +1602,42 @@ rule
|
|
1546
1602
|
|
1547
1603
|
result = block_var args
|
1548
1604
|
}
|
1549
|
-
| f_marg_list tCOMMA
|
1605
|
+
| f_marg_list tCOMMA f_rest_marg
|
1550
1606
|
{
|
1551
|
-
args, _,
|
1607
|
+
args, _, rest = val
|
1552
1608
|
|
1553
|
-
result = block_var args,
|
1609
|
+
result = block_var args, rest
|
1554
1610
|
}
|
1555
|
-
| f_marg_list tCOMMA
|
1611
|
+
| f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
|
1556
1612
|
{
|
1557
|
-
|
1613
|
+
lhs, _, splat, _, rhs = val
|
1558
1614
|
|
1559
|
-
result = block_var
|
1615
|
+
result = block_var lhs, splat, rhs
|
1560
1616
|
}
|
1561
|
-
|
|
1617
|
+
| f_rest_marg
|
1562
1618
|
{
|
1563
|
-
|
1619
|
+
rest, = val
|
1564
1620
|
|
1565
|
-
result = block_var
|
1621
|
+
result = block_var rest
|
1566
1622
|
}
|
1567
|
-
|
|
1623
|
+
| f_rest_marg tCOMMA f_marg_list
|
1568
1624
|
{
|
1569
|
-
|
1625
|
+
splat, _, rest = val
|
1570
1626
|
|
1571
|
-
result = block_var
|
1627
|
+
result = block_var splat, rest
|
1572
1628
|
}
|
1573
|
-
| tSTAR f_norm_arg
|
1574
|
-
{
|
1575
|
-
_, splat = val
|
1576
1629
|
|
1577
|
-
|
1578
|
-
}
|
1579
|
-
| tSTAR f_norm_arg tCOMMA f_marg_list
|
1630
|
+
f_rest_marg: tSTAR f_norm_arg
|
1580
1631
|
{
|
1581
|
-
_,
|
1632
|
+
_, (id, line) = val
|
1582
1633
|
|
1583
|
-
result =
|
1634
|
+
result = args ["*#{id}".to_sym]
|
1635
|
+
result.line line
|
1584
1636
|
}
|
1585
1637
|
| tSTAR
|
1586
1638
|
{
|
1587
|
-
result =
|
1588
|
-
|
1589
|
-
| tSTAR tCOMMA f_marg_list
|
1590
|
-
{
|
1591
|
-
_, _, args = val
|
1592
|
-
|
1593
|
-
result = block_var :*, args
|
1639
|
+
result = args [:*]
|
1640
|
+
result.line lexer.lineno # FIX: tSTAR -> line
|
1594
1641
|
}
|
1595
1642
|
|
1596
1643
|
block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
|
@@ -1605,10 +1652,14 @@ rule
|
|
1605
1652
|
{
|
1606
1653
|
result = call_args val
|
1607
1654
|
}
|
1655
|
+
| f_no_kwarg opt_f_block_arg
|
1656
|
+
{
|
1657
|
+
result = args val
|
1658
|
+
}
|
1608
1659
|
| f_block_arg
|
1609
1660
|
{
|
1610
|
-
line =
|
1611
|
-
result = call_args
|
1661
|
+
(id, line), = val
|
1662
|
+
result = call_args [id]
|
1612
1663
|
result.line line
|
1613
1664
|
}
|
1614
1665
|
|
@@ -1717,13 +1768,13 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1717
1768
|
|
1718
1769
|
bvar: tIDENTIFIER
|
1719
1770
|
{
|
1720
|
-
id, = val
|
1721
|
-
line = lexer.lineno
|
1771
|
+
(id, line), = val
|
1722
1772
|
result = s(:shadow, id.to_sym).line line
|
1723
1773
|
}
|
1724
1774
|
| f_bad_arg
|
1725
1775
|
|
1726
|
-
lambda:
|
1776
|
+
lambda: tLAMBDA
|
1777
|
+
{
|
1727
1778
|
self.env.extend :dynamic
|
1728
1779
|
result = [lexer.lineno, lexer.lpar_beg]
|
1729
1780
|
lexer.paren_nest += 1
|
@@ -1735,14 +1786,14 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1735
1786
|
}
|
1736
1787
|
lambda_body
|
1737
1788
|
{
|
1738
|
-
(line, lpar), args, _cmdarg, body = val
|
1789
|
+
_, (line, lpar), args, _cmdarg, body = val
|
1739
1790
|
lexer.lpar_beg = lpar
|
1740
1791
|
|
1741
1792
|
lexer.cmdarg.pop
|
1742
1793
|
|
1743
1794
|
call = s(:lambda).line line
|
1744
1795
|
result = new_iter call, args, body
|
1745
|
-
result.line
|
1796
|
+
result.line line
|
1746
1797
|
self.env.unextend # TODO: dynapush & dynapop
|
1747
1798
|
}
|
1748
1799
|
|
@@ -1777,23 +1828,28 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1777
1828
|
## if (nd_type($1) == NODE_YIELD) {
|
1778
1829
|
## compile_error(PARSER_ARG "block given to yield");
|
1779
1830
|
|
1780
|
-
|
1781
|
-
val[0].block_pass?
|
1831
|
+
cmd, blk = val
|
1782
1832
|
|
1783
|
-
|
1833
|
+
syntax_error "Both block arg and actual block given." if
|
1834
|
+
cmd.block_pass?
|
1784
1835
|
|
1785
|
-
|
1836
|
+
if inverted? val then
|
1837
|
+
val = invert_block_call val
|
1838
|
+
cmd, blk = val
|
1839
|
+
end
|
1786
1840
|
|
1787
1841
|
result = blk
|
1788
1842
|
result.insert 1, cmd
|
1789
1843
|
}
|
1790
1844
|
| block_call call_op2 operation2 opt_paren_args
|
1791
1845
|
{
|
1792
|
-
|
1846
|
+
lhs, _, (id, _line), args = val
|
1847
|
+
|
1848
|
+
result = new_call lhs, id.to_sym, args
|
1793
1849
|
}
|
1794
1850
|
| block_call call_op2 operation2 opt_paren_args brace_block
|
1795
1851
|
{
|
1796
|
-
iter1, _, name, args, iter2 = val
|
1852
|
+
iter1, _, (name, _line), args, iter2 = val
|
1797
1853
|
|
1798
1854
|
call = new_call iter1, name.to_sym, args
|
1799
1855
|
iter2.insert 1, call
|
@@ -1802,7 +1858,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1802
1858
|
}
|
1803
1859
|
| block_call call_op2 operation2 command_args do_block
|
1804
1860
|
{
|
1805
|
-
iter1, _, name, args, iter2 = val
|
1861
|
+
iter1, _, (name, _line), args, iter2 = val
|
1806
1862
|
|
1807
1863
|
call = new_call iter1, name.to_sym, args
|
1808
1864
|
iter2.insert 1, call
|
@@ -1810,28 +1866,29 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1810
1866
|
result = iter2
|
1811
1867
|
}
|
1812
1868
|
|
1813
|
-
method_call: fcall
|
1869
|
+
method_call: fcall paren_args
|
1814
1870
|
{
|
1815
|
-
|
1816
|
-
}
|
1817
|
-
paren_args
|
1818
|
-
{
|
1819
|
-
call, lineno, args = val
|
1871
|
+
call, args = val
|
1820
1872
|
|
1821
1873
|
result = call.concat args.sexp_body if args
|
1822
|
-
result.line lineno
|
1823
1874
|
}
|
1824
1875
|
| primary_value call_op operation2 opt_paren_args
|
1825
1876
|
{
|
1826
|
-
|
1877
|
+
recv, call_op, (op, _line), args = val
|
1878
|
+
|
1879
|
+
result = new_call recv, op.to_sym, args, call_op
|
1827
1880
|
}
|
1828
1881
|
| primary_value tCOLON2 operation2 paren_args
|
1829
1882
|
{
|
1830
|
-
|
1883
|
+
recv, _, (op, _line), args = val
|
1884
|
+
|
1885
|
+
result = new_call recv, op.to_sym, args
|
1831
1886
|
}
|
1832
1887
|
| primary_value tCOLON2 operation3
|
1833
1888
|
{
|
1834
|
-
|
1889
|
+
lhs, _, (id, _line) = val
|
1890
|
+
|
1891
|
+
result = new_call lhs, id.to_sym
|
1835
1892
|
}
|
1836
1893
|
| primary_value call_op paren_args
|
1837
1894
|
{
|
@@ -1864,7 +1921,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1864
1921
|
_, line, body, _ = val
|
1865
1922
|
|
1866
1923
|
result = body
|
1867
|
-
result.line
|
1924
|
+
result.line line
|
1868
1925
|
|
1869
1926
|
self.env.unextend
|
1870
1927
|
}
|
@@ -1878,7 +1935,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1878
1935
|
_, line, body, _ = val
|
1879
1936
|
|
1880
1937
|
result = body
|
1881
|
-
result.line
|
1938
|
+
result.line line
|
1882
1939
|
|
1883
1940
|
self.env.unextend
|
1884
1941
|
}
|
@@ -1907,18 +1964,546 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1907
1964
|
self.env.unextend
|
1908
1965
|
}
|
1909
1966
|
|
1967
|
+
case_args: arg_value
|
1968
|
+
{
|
1969
|
+
arg, = val
|
1970
|
+
|
1971
|
+
result = s(:array, arg).line arg.line
|
1972
|
+
}
|
1973
|
+
| tSTAR arg_value
|
1974
|
+
{
|
1975
|
+
_, arg = val
|
1976
|
+
|
1977
|
+
result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
|
1978
|
+
}
|
1979
|
+
| case_args tCOMMA arg_value
|
1980
|
+
{
|
1981
|
+
args, _, id = val
|
1982
|
+
|
1983
|
+
result = self.list_append args, id
|
1984
|
+
}
|
1985
|
+
| case_args tCOMMA tSTAR arg_value
|
1986
|
+
{
|
1987
|
+
args, _, _, id = val
|
1988
|
+
|
1989
|
+
result = self.list_append args, s(:splat, id).line(id.line)
|
1990
|
+
}
|
1991
|
+
|
1910
1992
|
case_body: k_when
|
1911
1993
|
{
|
1912
1994
|
result = self.lexer.lineno
|
1913
1995
|
}
|
1914
|
-
|
1996
|
+
case_args then compstmt cases
|
1915
1997
|
{
|
1916
1998
|
result = new_when(val[2], val[4])
|
1917
|
-
result.line
|
1999
|
+
result.line val[1]
|
1918
2000
|
result << val[5] if val[5]
|
1919
2001
|
}
|
1920
2002
|
|
1921
2003
|
cases: opt_else | case_body
|
2004
|
+
######################################################################
|
2005
|
+
|
2006
|
+
p_case_body: kIN
|
2007
|
+
{
|
2008
|
+
self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
|
2009
|
+
self.lexer.command_start = false
|
2010
|
+
result = self.in_kwarg
|
2011
|
+
self.in_kwarg = true
|
2012
|
+
push_pvtbl
|
2013
|
+
push_pktbl
|
2014
|
+
}
|
2015
|
+
p_top_expr then
|
2016
|
+
{
|
2017
|
+
pop_pktbl
|
2018
|
+
pop_pvtbl
|
2019
|
+
old_kwargs = _values[-3]
|
2020
|
+
self.in_kwarg = old_kwargs
|
2021
|
+
}
|
2022
|
+
compstmt
|
2023
|
+
p_cases
|
2024
|
+
{
|
2025
|
+
(_, line), _, pat, _, _, body, cases = val
|
2026
|
+
|
2027
|
+
result = new_in pat, body, cases, line
|
2028
|
+
}
|
2029
|
+
|
2030
|
+
p_cases: opt_else
|
2031
|
+
| p_case_body
|
2032
|
+
|
2033
|
+
p_top_expr: p_top_expr_body
|
2034
|
+
| p_top_expr_body kIF_MOD expr_value
|
2035
|
+
{
|
2036
|
+
body, _, cond = val
|
2037
|
+
body = remove_begin body
|
2038
|
+
|
2039
|
+
result = s(:if, cond, body, nil).line body.line
|
2040
|
+
}
|
2041
|
+
| p_top_expr_body kUNLESS_MOD expr_value
|
2042
|
+
{
|
2043
|
+
body, _, cond = val
|
2044
|
+
body = remove_begin body
|
2045
|
+
|
2046
|
+
result = s(:if, cond, nil, body).line body.line
|
2047
|
+
}
|
2048
|
+
|
2049
|
+
p_top_expr_body: p_expr
|
2050
|
+
| p_expr tCOMMA
|
2051
|
+
{
|
2052
|
+
expr, _ = val
|
2053
|
+
|
2054
|
+
tail = new_array_pattern_tail nil, true, nil, nil
|
2055
|
+
result = new_array_pattern nil, expr, tail, expr.line
|
2056
|
+
}
|
2057
|
+
| p_expr tCOMMA p_args
|
2058
|
+
{
|
2059
|
+
expr, _, args = val
|
2060
|
+
|
2061
|
+
result = new_array_pattern nil, expr, args, expr.line
|
2062
|
+
}
|
2063
|
+
| p_args_tail
|
2064
|
+
{
|
2065
|
+
args, = val
|
2066
|
+
result = new_array_pattern nil, nil, args, args.line
|
2067
|
+
}
|
2068
|
+
| p_kwargs
|
2069
|
+
{
|
2070
|
+
kwargs, = val
|
2071
|
+
result = new_hash_pattern nil, kwargs, kwargs.line
|
2072
|
+
}
|
2073
|
+
|
2074
|
+
p_expr: p_as
|
2075
|
+
|
2076
|
+
p_as: p_expr tASSOC p_variable
|
2077
|
+
{
|
2078
|
+
# NODE *n = NEW_LIST($1, &@$);
|
2079
|
+
# n = list_append(p, n, $3);
|
2080
|
+
# $$ = new_hash(p, n, &@$);
|
2081
|
+
|
2082
|
+
expr, _, var = val
|
2083
|
+
|
2084
|
+
id = var.last
|
2085
|
+
|
2086
|
+
self.env[id] = :lvar # HACK: need to extend env
|
2087
|
+
lhs = s(:lasgn, id).line var.line
|
2088
|
+
|
2089
|
+
result = new_assign lhs, expr
|
2090
|
+
}
|
2091
|
+
| p_alt
|
2092
|
+
|
2093
|
+
p_alt: p_alt tPIPE p_expr_basic
|
2094
|
+
{
|
2095
|
+
lhs, _, rhs = val
|
2096
|
+
|
2097
|
+
result = s(:or, lhs, rhs).line lhs.line
|
2098
|
+
}
|
2099
|
+
| p_expr_basic
|
2100
|
+
|
2101
|
+
p_lparen: tLPAREN2 { push_pktbl }
|
2102
|
+
p_lbracket: tLBRACK2 { push_pktbl }
|
2103
|
+
|
2104
|
+
p_expr_basic: p_value
|
2105
|
+
| p_const p_lparen p_args tRPAREN
|
2106
|
+
{
|
2107
|
+
lhs, _, args, _ = val
|
2108
|
+
|
2109
|
+
pop_pktbl
|
2110
|
+
result = new_array_pattern(lhs, nil, args, lhs.line)
|
2111
|
+
}
|
2112
|
+
| p_const p_lparen p_kwargs tRPAREN
|
2113
|
+
{
|
2114
|
+
lhs, _, kwargs, _ = val
|
2115
|
+
|
2116
|
+
pop_pktbl
|
2117
|
+
result = new_hash_pattern(lhs, kwargs, lhs.line)
|
2118
|
+
}
|
2119
|
+
| p_const tLPAREN2 tRPAREN
|
2120
|
+
{
|
2121
|
+
const, _, _ = val
|
2122
|
+
|
2123
|
+
tail = new_array_pattern_tail nil, nil, nil, nil
|
2124
|
+
result = new_array_pattern const, nil, tail, const.line
|
2125
|
+
}
|
2126
|
+
| p_const p_lbracket p_args rbracket
|
2127
|
+
{
|
2128
|
+
const, _, pre_arg, _ = val
|
2129
|
+
|
2130
|
+
pop_pktbl
|
2131
|
+
result = new_array_pattern const, nil, pre_arg, const.line
|
2132
|
+
}
|
2133
|
+
| p_const p_lbracket p_kwargs rbracket
|
2134
|
+
{
|
2135
|
+
const, _, kwargs, _ = val
|
2136
|
+
|
2137
|
+
result = new_hash_pattern const, kwargs, const.line
|
2138
|
+
}
|
2139
|
+
| p_const tLBRACK2 rbracket
|
2140
|
+
{
|
2141
|
+
const, _, _ = val
|
2142
|
+
|
2143
|
+
tail = new_array_pattern_tail nil, nil, nil, nil
|
2144
|
+
result = new_array_pattern const, nil, tail, const.line
|
2145
|
+
}
|
2146
|
+
| tLBRACK { push_pktbl } p_args rbracket
|
2147
|
+
{
|
2148
|
+
_, _, pat, _ = val
|
2149
|
+
|
2150
|
+
pop_pktbl
|
2151
|
+
result = new_array_pattern nil, nil, pat, pat.line
|
2152
|
+
}
|
2153
|
+
| tLBRACK rbracket
|
2154
|
+
{
|
2155
|
+
(_, line), _ = val
|
2156
|
+
|
2157
|
+
result = s(:array_pat).line line
|
2158
|
+
}
|
2159
|
+
| tLBRACE
|
2160
|
+
{
|
2161
|
+
push_pktbl
|
2162
|
+
result = self.in_kwarg
|
2163
|
+
self.in_kwarg = false
|
2164
|
+
}
|
2165
|
+
p_kwargs rbrace
|
2166
|
+
{
|
2167
|
+
_, in_kwarg, kwargs, _ = val
|
2168
|
+
|
2169
|
+
pop_pktbl
|
2170
|
+
self.in_kwarg = in_kwarg
|
2171
|
+
|
2172
|
+
result = new_hash_pattern(nil, kwargs, kwargs.line)
|
2173
|
+
}
|
2174
|
+
| tLBRACE rbrace
|
2175
|
+
{
|
2176
|
+
(_, line), _ = val
|
2177
|
+
|
2178
|
+
tail = new_hash_pattern_tail nil, nil, line
|
2179
|
+
result = new_hash_pattern nil, tail, line
|
2180
|
+
}
|
2181
|
+
| tLPAREN { push_pktbl } p_expr tRPAREN
|
2182
|
+
{
|
2183
|
+
_, _, expr, _ = val
|
2184
|
+
|
2185
|
+
pop_pktbl
|
2186
|
+
result = expr
|
2187
|
+
}
|
2188
|
+
|
2189
|
+
p_args: p_expr
|
2190
|
+
{
|
2191
|
+
expr, = val
|
2192
|
+
|
2193
|
+
ary = s(:array_TAIL, expr).line expr.line
|
2194
|
+
result = new_array_pattern_tail(ary, nil, nil, nil).line expr.line
|
2195
|
+
}
|
2196
|
+
| p_args_head
|
2197
|
+
{
|
2198
|
+
head, = val
|
2199
|
+
|
2200
|
+
result = new_array_pattern_tail head, true, nil, nil
|
2201
|
+
}
|
2202
|
+
| p_args_head p_arg
|
2203
|
+
{
|
2204
|
+
head, tail = val
|
2205
|
+
|
2206
|
+
both = array_pat_concat head, tail
|
2207
|
+
|
2208
|
+
result = new_array_pattern_tail both, nil, nil, nil
|
2209
|
+
result.line head.line
|
2210
|
+
}
|
2211
|
+
| p_args_head tSTAR tIDENTIFIER
|
2212
|
+
{
|
2213
|
+
head, _, (id, _line) = val
|
2214
|
+
|
2215
|
+
result = new_array_pattern_tail head, true, id.to_sym, nil
|
2216
|
+
result.line head.line
|
2217
|
+
}
|
2218
|
+
| p_args_head tSTAR tIDENTIFIER tCOMMA p_args_post
|
2219
|
+
{
|
2220
|
+
head, _, (id, _line), _, post = val
|
2221
|
+
|
2222
|
+
result = new_array_pattern_tail head, true, id.to_sym, post
|
2223
|
+
result.line head.line
|
2224
|
+
}
|
2225
|
+
| p_args_head tSTAR
|
2226
|
+
{
|
2227
|
+
expr, _ = val
|
2228
|
+
|
2229
|
+
result = new_array_pattern_tail(expr, true, nil, nil).line expr.line
|
2230
|
+
}
|
2231
|
+
| p_args_head tSTAR tCOMMA p_args_post
|
2232
|
+
{
|
2233
|
+
head, _, _, post = val
|
2234
|
+
|
2235
|
+
result = new_array_pattern_tail(head, true, nil, post).line head.line
|
2236
|
+
}
|
2237
|
+
| p_args_tail
|
2238
|
+
|
2239
|
+
p_args_head: p_arg tCOMMA
|
2240
|
+
{
|
2241
|
+
arg, _ = val
|
2242
|
+
result = arg
|
2243
|
+
}
|
2244
|
+
| p_args_head p_arg tCOMMA
|
2245
|
+
{
|
2246
|
+
head, tail, _ = val
|
2247
|
+
|
2248
|
+
result = s(:PATTERN, *head.sexp_body, *tail.sexp_body)
|
2249
|
+
result.line head.line
|
2250
|
+
}
|
2251
|
+
|
2252
|
+
p_args_tail: tSTAR tIDENTIFIER
|
2253
|
+
{
|
2254
|
+
_, (id, line) = val
|
2255
|
+
|
2256
|
+
result = new_array_pattern_tail nil, true, id.to_sym, nil
|
2257
|
+
result.line line
|
2258
|
+
}
|
2259
|
+
| tSTAR tIDENTIFIER tCOMMA p_args_post
|
2260
|
+
{
|
2261
|
+
_, (id, line), _, rhs = val
|
2262
|
+
|
2263
|
+
result = new_array_pattern_tail nil, true, id.to_sym, rhs
|
2264
|
+
result.line line
|
2265
|
+
}
|
2266
|
+
| tSTAR
|
2267
|
+
{
|
2268
|
+
(_, line), = val
|
2269
|
+
|
2270
|
+
result = new_array_pattern_tail nil, true, nil, nil
|
2271
|
+
result.line line
|
2272
|
+
}
|
2273
|
+
| tSTAR tCOMMA p_args_post
|
2274
|
+
{
|
2275
|
+
(_, line), _, args = val
|
2276
|
+
|
2277
|
+
result = new_array_pattern_tail nil, true, nil, args
|
2278
|
+
result.line line
|
2279
|
+
}
|
2280
|
+
|
2281
|
+
p_args_post: p_arg
|
2282
|
+
| p_args_post tCOMMA p_arg
|
2283
|
+
{
|
2284
|
+
lhs, _, rhs = val
|
2285
|
+
|
2286
|
+
result = array_pat_concat lhs, rhs
|
2287
|
+
}
|
2288
|
+
|
2289
|
+
p_arg: p_expr
|
2290
|
+
{
|
2291
|
+
expr, = val
|
2292
|
+
expr = s(:array_TAIL, expr).line expr.line unless
|
2293
|
+
expr.sexp_type == :array_TAIL
|
2294
|
+
result = expr
|
2295
|
+
}
|
2296
|
+
|
2297
|
+
p_kwargs: p_kwarg tCOMMA p_kwrest
|
2298
|
+
{
|
2299
|
+
kw_arg, _, rest = val
|
2300
|
+
# TODO? new_unique_key_hash(p, $1, &@$)
|
2301
|
+
result = new_hash_pattern_tail kw_arg, rest, kw_arg.line
|
2302
|
+
}
|
2303
|
+
| p_kwarg
|
2304
|
+
{
|
2305
|
+
kwarg, = val
|
2306
|
+
# TODO? new_unique_key_hash(p, $1, &@$)
|
2307
|
+
result = new_hash_pattern_tail kwarg, nil, kwarg.line
|
2308
|
+
}
|
2309
|
+
| p_kwarg tCOMMA
|
2310
|
+
{
|
2311
|
+
kwarg, _ = val
|
2312
|
+
# TODO? new_unique_key_hash(p, $1, &@$)
|
2313
|
+
result = new_hash_pattern_tail kwarg, nil, kwarg.line
|
2314
|
+
}
|
2315
|
+
| p_kwrest
|
2316
|
+
{
|
2317
|
+
rest, = val
|
2318
|
+
|
2319
|
+
result = new_hash_pattern_tail nil, rest, rest.line
|
2320
|
+
}
|
2321
|
+
| p_kwarg tCOMMA p_kwnorest
|
2322
|
+
{
|
2323
|
+
kwarg, _, norest = val
|
2324
|
+
|
2325
|
+
# TODO? new_unique_key_hash(p, $1, &@$)
|
2326
|
+
result = new_hash_pattern_tail kwarg, norest, kwarg.line
|
2327
|
+
}
|
2328
|
+
| p_kwnorest
|
2329
|
+
{
|
2330
|
+
norest, = val
|
2331
|
+
|
2332
|
+
result = new_hash_pattern_tail nil, norest, norest.line
|
2333
|
+
}
|
2334
|
+
|
2335
|
+
p_kwarg: p_kw # TODO? rb_ary_new_from_args(1, $1)
|
2336
|
+
| p_kwarg tCOMMA p_kw
|
2337
|
+
{
|
2338
|
+
kwarg, _, kw = val
|
2339
|
+
kwarg.concat kw.sexp_body
|
2340
|
+
result = kwarg
|
2341
|
+
}
|
2342
|
+
|
2343
|
+
p_kw: p_kw_label p_expr
|
2344
|
+
{
|
2345
|
+
# TODO: error_duplicate_pattern_key(p, get_id($1), &@1);
|
2346
|
+
lhs, rhs = val
|
2347
|
+
|
2348
|
+
result = s(:PAIR, lhs, rhs).line lhs.line
|
2349
|
+
}
|
2350
|
+
| p_kw_label
|
2351
|
+
{
|
2352
|
+
lhs, = val
|
2353
|
+
|
2354
|
+
# TODO: error_duplicate_pattern_variable(p, get_id($1), &@1);
|
2355
|
+
|
2356
|
+
# TODO: if ($1 && !is_local_id(get_id($1))) {
|
2357
|
+
# yyerror1(&@1, "key must be valid as local variables");
|
2358
|
+
# }
|
2359
|
+
|
2360
|
+
# $$ = list_append(p, NEW_LIST(NEW_LIT(ID2SYM($1), &@$), &@$),
|
2361
|
+
# assignable(p, $1, 0, &@$));
|
2362
|
+
|
2363
|
+
|
2364
|
+
case lhs.sexp_type
|
2365
|
+
when :lit then
|
2366
|
+
assignable [lhs.value, lhs.line]
|
2367
|
+
else
|
2368
|
+
# TODO or done?
|
2369
|
+
debug 666
|
2370
|
+
end
|
2371
|
+
|
2372
|
+
# TODO PAIR -> LIST ?
|
2373
|
+
result = s(:PAIR, lhs, nil).line lhs.line
|
2374
|
+
}
|
2375
|
+
|
2376
|
+
p_kw_label: tLABEL
|
2377
|
+
{
|
2378
|
+
(id, line), = val
|
2379
|
+
|
2380
|
+
result = s(:lit, id.to_sym).line line
|
2381
|
+
}
|
2382
|
+
|
2383
|
+
p_kwrest: kwrest_mark tIDENTIFIER
|
2384
|
+
{
|
2385
|
+
_, (id, line) = val
|
2386
|
+
|
2387
|
+
name = id.to_sym
|
2388
|
+
self.assignable [name, line]
|
2389
|
+
result = s(:kwrest, :"**#{name}").line line
|
2390
|
+
}
|
2391
|
+
| kwrest_mark
|
2392
|
+
{
|
2393
|
+
(_, line), = val
|
2394
|
+
|
2395
|
+
result = s(:kwrest, :"**").line line
|
2396
|
+
}
|
2397
|
+
|
2398
|
+
p_kwnorest: kwrest_mark kNIL
|
2399
|
+
{
|
2400
|
+
(_, line), _ = val
|
2401
|
+
|
2402
|
+
# TODO: or s(:norest)? s(:**nil)?
|
2403
|
+
result = s(:kwrest, :"**nil").line line
|
2404
|
+
}
|
2405
|
+
|
2406
|
+
p_value: p_primitive
|
2407
|
+
| p_primitive tDOT2 p_primitive
|
2408
|
+
{
|
2409
|
+
lhs, _, rhs = val
|
2410
|
+
|
2411
|
+
lhs = value_expr lhs
|
2412
|
+
rhs = value_expr rhs
|
2413
|
+
|
2414
|
+
result = s(:dot2, lhs, rhs).line lhs.line
|
2415
|
+
}
|
2416
|
+
| p_primitive tDOT3 p_primitive
|
2417
|
+
{
|
2418
|
+
lhs, _, rhs = val
|
2419
|
+
|
2420
|
+
lhs = value_expr lhs
|
2421
|
+
rhs = value_expr rhs
|
2422
|
+
|
2423
|
+
result = s(:dot3, lhs, rhs).line lhs.line
|
2424
|
+
}
|
2425
|
+
| p_primitive tDOT2
|
2426
|
+
{
|
2427
|
+
v1, _ = val
|
2428
|
+
|
2429
|
+
result = s(:dot2, v1, nil).line v1.line
|
2430
|
+
}
|
2431
|
+
| p_primitive tDOT3
|
2432
|
+
{
|
2433
|
+
v1, _ = val
|
2434
|
+
|
2435
|
+
result = s(:dot3, v1, nil).line v1.line
|
2436
|
+
}
|
2437
|
+
| p_variable
|
2438
|
+
| p_var_ref
|
2439
|
+
| p_const
|
2440
|
+
| tBDOT2 p_primitive
|
2441
|
+
{
|
2442
|
+
_, v1 = val
|
2443
|
+
|
2444
|
+
result = s(:dot2, nil, v1).line v1.line
|
2445
|
+
}
|
2446
|
+
| tBDOT3 p_primitive
|
2447
|
+
{
|
2448
|
+
_, v1 = val
|
2449
|
+
|
2450
|
+
result = s(:dot3, nil, v1).line v1.line
|
2451
|
+
}
|
2452
|
+
|
2453
|
+
p_primitive: literal
|
2454
|
+
| strings
|
2455
|
+
| xstring
|
2456
|
+
| regexp
|
2457
|
+
| words
|
2458
|
+
| qwords
|
2459
|
+
| symbols
|
2460
|
+
| qsymbols
|
2461
|
+
| keyword_variable
|
2462
|
+
{
|
2463
|
+
# TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
|
2464
|
+
var, = val
|
2465
|
+
|
2466
|
+
result = var
|
2467
|
+
}
|
2468
|
+
| lambda
|
2469
|
+
|
2470
|
+
p_variable: tIDENTIFIER
|
2471
|
+
{
|
2472
|
+
(id, line), = val
|
2473
|
+
|
2474
|
+
# TODO: error_duplicate_pattern_variable(p, $1, &@1);
|
2475
|
+
# TODO: assignable(p, $1, 0, &@$);
|
2476
|
+
result = s(:lvar, id.to_sym).line line
|
2477
|
+
}
|
2478
|
+
|
2479
|
+
p_var_ref: tCARET tIDENTIFIER
|
2480
|
+
{
|
2481
|
+
_, (id, line) = val
|
2482
|
+
|
2483
|
+
# TODO: check id against env for lvar or dvar
|
2484
|
+
|
2485
|
+
result = s(:lvar, id.to_sym).line line
|
2486
|
+
}
|
2487
|
+
|
2488
|
+
p_const: tCOLON3 cname
|
2489
|
+
{
|
2490
|
+
_, (id, line) = val
|
2491
|
+
result = s(:colon3, id.to_sym).line line
|
2492
|
+
}
|
2493
|
+
| p_const tCOLON2 cname
|
2494
|
+
{
|
2495
|
+
lhs, _, (id, _line) = val
|
2496
|
+
|
2497
|
+
l = lhs.line
|
2498
|
+
result = s(:const, s(:colon2, lhs, id.to_sym).line(l)).line l
|
2499
|
+
}
|
2500
|
+
| tCONSTANT
|
2501
|
+
{
|
2502
|
+
# TODO $$ = gettable(p, $1, &@$);
|
2503
|
+
(id, line), = val
|
2504
|
+
result = s(:const, id.to_sym).line line
|
2505
|
+
}
|
2506
|
+
######################################################################
|
1922
2507
|
|
1923
2508
|
opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
|
1924
2509
|
{
|
@@ -1960,17 +2545,10 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1960
2545
|
|
1961
2546
|
literal: numeric
|
1962
2547
|
{
|
1963
|
-
line =
|
1964
|
-
result = s(:lit,
|
1965
|
-
result.line = line
|
2548
|
+
(lit, line), = val
|
2549
|
+
result = s(:lit, lit).line line
|
1966
2550
|
}
|
1967
2551
|
| symbol
|
1968
|
-
{
|
1969
|
-
line = lexer.lineno
|
1970
|
-
result = s(:lit, val[0])
|
1971
|
-
result.line = line
|
1972
|
-
}
|
1973
|
-
| dsym
|
1974
2552
|
|
1975
2553
|
strings: string
|
1976
2554
|
{
|
@@ -1981,7 +2559,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1981
2559
|
|
1982
2560
|
string: tCHAR
|
1983
2561
|
{
|
1984
|
-
|
2562
|
+
debug 37
|
1985
2563
|
}
|
1986
2564
|
| string1
|
1987
2565
|
| string string1
|
@@ -1991,11 +2569,11 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1991
2569
|
|
1992
2570
|
string1: tSTRING_BEG string_contents tSTRING_END
|
1993
2571
|
{
|
1994
|
-
_, str, (_, func) = val
|
2572
|
+
(_, line), str, (_, func) = val
|
1995
2573
|
|
1996
|
-
str = dedent str if func =~ RubyLexer::
|
2574
|
+
str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
|
1997
2575
|
|
1998
|
-
result = str
|
2576
|
+
result = str.line line
|
1999
2577
|
}
|
2000
2578
|
| tSTRING
|
2001
2579
|
{
|
@@ -2015,11 +2593,15 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2015
2593
|
|
2016
2594
|
words: tWORDS_BEG tSPACE tSTRING_END
|
2017
2595
|
{
|
2018
|
-
|
2596
|
+
(_, line), _, _ = val
|
2597
|
+
|
2598
|
+
result = s(:array).line line
|
2019
2599
|
}
|
2020
2600
|
| tWORDS_BEG word_list tSTRING_END
|
2021
2601
|
{
|
2022
|
-
|
2602
|
+
(_, line), list, _ = val
|
2603
|
+
|
2604
|
+
result = list.line line
|
2023
2605
|
}
|
2024
2606
|
|
2025
2607
|
word_list: none
|
@@ -2039,18 +2621,20 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2039
2621
|
|
2040
2622
|
symbols: tSYMBOLS_BEG tSPACE tSTRING_END
|
2041
2623
|
{
|
2042
|
-
|
2624
|
+
(_, line), _, _ = val
|
2625
|
+
|
2626
|
+
result = s(:array).line line
|
2043
2627
|
}
|
2044
|
-
| tSYMBOLS_BEG
|
2628
|
+
| tSYMBOLS_BEG symbol_list tSTRING_END
|
2045
2629
|
{
|
2046
|
-
_, line, list, _, = val
|
2047
|
-
list.line
|
2630
|
+
(_, line), list, _, = val
|
2631
|
+
list.line line
|
2048
2632
|
result = list
|
2049
2633
|
}
|
2050
2634
|
|
2051
2635
|
symbol_list: none
|
2052
2636
|
{
|
2053
|
-
result = new_symbol_list
|
2637
|
+
result = new_symbol_list
|
2054
2638
|
}
|
2055
2639
|
| symbol_list word tSPACE
|
2056
2640
|
{
|
@@ -2060,20 +2644,28 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2060
2644
|
|
2061
2645
|
qwords: tQWORDS_BEG tSPACE tSTRING_END
|
2062
2646
|
{
|
2063
|
-
|
2647
|
+
(_, line), _, _ = val
|
2648
|
+
|
2649
|
+
result = s(:array).line line
|
2064
2650
|
}
|
2065
2651
|
| tQWORDS_BEG qword_list tSTRING_END
|
2066
2652
|
{
|
2067
|
-
|
2653
|
+
(_, line), list, _ = val
|
2654
|
+
|
2655
|
+
result = list.line line
|
2068
2656
|
}
|
2069
2657
|
|
2070
2658
|
qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
|
2071
2659
|
{
|
2072
|
-
|
2660
|
+
(_, line), _, _ = val
|
2661
|
+
|
2662
|
+
result = s(:array).line line
|
2073
2663
|
}
|
2074
2664
|
| tQSYMBOLS_BEG qsym_list tSTRING_END
|
2075
2665
|
{
|
2076
|
-
|
2666
|
+
(_, line), list, _ = val
|
2667
|
+
|
2668
|
+
result = list.line line
|
2077
2669
|
}
|
2078
2670
|
|
2079
2671
|
qword_list: none
|
@@ -2096,7 +2688,8 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2096
2688
|
|
2097
2689
|
string_contents: none
|
2098
2690
|
{
|
2099
|
-
|
2691
|
+
line = prev_value_to_lineno _values.last
|
2692
|
+
result = s(:str, +"").line line
|
2100
2693
|
}
|
2101
2694
|
| string_contents string_content
|
2102
2695
|
{
|
@@ -2171,8 +2764,8 @@ regexp_contents: none
|
|
2171
2764
|
lexer.brace_nest = brace_nest
|
2172
2765
|
lexer.string_nest = string_nest
|
2173
2766
|
|
2174
|
-
lexer.cmdarg.pop
|
2175
2767
|
lexer.cond.pop
|
2768
|
+
lexer.cmdarg.pop
|
2176
2769
|
|
2177
2770
|
lexer.lex_state = oldlex_state
|
2178
2771
|
|
@@ -2187,29 +2780,49 @@ regexp_contents: none
|
|
2187
2780
|
when nil then
|
2188
2781
|
result = s(:evstr).line line
|
2189
2782
|
else
|
2190
|
-
|
2783
|
+
debug 38
|
2191
2784
|
raise "unknown string body: #{stmt.inspect}"
|
2192
2785
|
end
|
2193
2786
|
}
|
2194
2787
|
|
2195
|
-
string_dvar: tGVAR
|
2196
|
-
|
2197
|
-
|
2788
|
+
string_dvar: tGVAR
|
2789
|
+
{
|
2790
|
+
(id, line), = val
|
2791
|
+
result = s(:gvar, id.to_sym).line line
|
2792
|
+
}
|
2793
|
+
| tIVAR
|
2794
|
+
{
|
2795
|
+
(id, line), = val
|
2796
|
+
result = s(:ivar, id.to_sym).line line
|
2797
|
+
}
|
2798
|
+
| tCVAR
|
2799
|
+
{
|
2800
|
+
(id, line), = val
|
2801
|
+
result = s(:cvar, id.to_sym).line line
|
2802
|
+
}
|
2198
2803
|
| backref
|
2199
2804
|
|
2200
|
-
symbol:
|
2805
|
+
symbol: ssym
|
2806
|
+
| dsym
|
2807
|
+
|
2808
|
+
ssym: tSYMBEG sym
|
2201
2809
|
{
|
2810
|
+
_, (id, line) = val
|
2811
|
+
|
2202
2812
|
lexer.lex_state = EXPR_END
|
2203
|
-
result =
|
2813
|
+
result = s(:lit, id.to_sym).line line
|
2204
2814
|
}
|
2205
2815
|
| tSYMBOL
|
2206
2816
|
{
|
2207
|
-
|
2817
|
+
(id, line), = val
|
2818
|
+
|
2819
|
+
lexer.lex_state = EXPR_END
|
2820
|
+
result = s(:lit, id.to_sym).line line
|
2208
2821
|
}
|
2209
2822
|
|
2210
2823
|
sym: fname | tIVAR | tGVAR | tCVAR
|
2211
2824
|
|
2212
|
-
dsym: tSYMBEG
|
2825
|
+
dsym: tSYMBEG string_contents tSTRING_END
|
2213
2826
|
{
|
2214
2827
|
_, result, _ = val
|
2215
2828
|
|
@@ -2225,14 +2838,15 @@ regexp_contents: none
|
|
2225
2838
|
when :evstr then
|
2226
2839
|
result = s(:dsym, "", result).line result.line
|
2227
2840
|
else
|
2228
|
-
|
2841
|
+
debug 39
|
2229
2842
|
end
|
2230
2843
|
}
|
2231
2844
|
|
2232
2845
|
numeric: simple_numeric
|
2233
|
-
| tUMINUS_NUM simple_numeric
|
2846
|
+
| tUMINUS_NUM simple_numeric =tLOWEST
|
2234
2847
|
{
|
2235
|
-
|
2848
|
+
_, (num, line) = val
|
2849
|
+
result = [-num, line]
|
2236
2850
|
}
|
2237
2851
|
|
2238
2852
|
simple_numeric: tINTEGER
|
@@ -2265,8 +2879,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2265
2879
|
|
2266
2880
|
var_ref: user_variable
|
2267
2881
|
{
|
2268
|
-
|
2882
|
+
raise "NO: #{val.inspect}" if Sexp === val.first
|
2883
|
+
(var, line), = val
|
2269
2884
|
result = Sexp === var ? var : self.gettable(var)
|
2885
|
+
result.line line
|
2270
2886
|
}
|
2271
2887
|
| keyword_variable
|
2272
2888
|
{
|
@@ -2281,11 +2897,19 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2281
2897
|
| keyword_variable
|
2282
2898
|
{
|
2283
2899
|
result = self.assignable val[0]
|
2284
|
-
|
2900
|
+
debug 40
|
2285
2901
|
}
|
2286
2902
|
|
2287
|
-
backref: tNTH_REF
|
2288
|
-
|
2903
|
+
backref: tNTH_REF
|
2904
|
+
{
|
2905
|
+
(ref, line), = val
|
2906
|
+
result = s(:nth_ref, ref).line line
|
2907
|
+
}
|
2908
|
+
| tBACK_REF
|
2909
|
+
{
|
2910
|
+
(ref, line), = val
|
2911
|
+
result = s(:back_ref, ref).line line
|
2912
|
+
}
|
2289
2913
|
|
2290
2914
|
superclass: tLT
|
2291
2915
|
{
|
@@ -2303,23 +2927,15 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2303
2927
|
|
2304
2928
|
f_arglist: tLPAREN2 f_args rparen
|
2305
2929
|
{
|
2306
|
-
result = val
|
2307
|
-
self.lexer.lex_state = EXPR_BEG
|
2308
|
-
self.lexer.command_start = true
|
2930
|
+
result = end_args val
|
2309
2931
|
}
|
2310
2932
|
| tLPAREN2 f_arg tCOMMA args_forward rparen
|
2311
2933
|
{
|
2312
|
-
result =
|
2313
|
-
|
2314
|
-
self.lexer.lex_state = EXPR_BEG
|
2315
|
-
self.lexer.command_start = true
|
2934
|
+
result = end_args val
|
2316
2935
|
}
|
2317
2936
|
| tLPAREN2 args_forward rparen
|
2318
2937
|
{
|
2319
|
-
result =
|
2320
|
-
|
2321
|
-
self.lexer.lex_state = EXPR_BEG
|
2322
|
-
self.lexer.command_start = true
|
2938
|
+
result = end_args val
|
2323
2939
|
}
|
2324
2940
|
| {
|
2325
2941
|
result = self.in_kwarg
|
@@ -2328,12 +2944,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2328
2944
|
}
|
2329
2945
|
f_args term
|
2330
2946
|
{
|
2331
|
-
|
2332
|
-
|
2333
|
-
self.in_kwarg = kwarg
|
2334
|
-
result = args
|
2335
|
-
lexer.lex_state = EXPR_BEG
|
2336
|
-
lexer.command_start = true
|
2947
|
+
result = end_args val
|
2337
2948
|
}
|
2338
2949
|
|
2339
2950
|
args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
|
@@ -2348,6 +2959,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2348
2959
|
{
|
2349
2960
|
result = args val
|
2350
2961
|
}
|
2962
|
+
| f_no_kwarg opt_f_block_arg
|
2963
|
+
{
|
2964
|
+
result = args val
|
2965
|
+
}
|
2351
2966
|
| f_block_arg
|
2352
2967
|
|
2353
2968
|
opt_args_tail: tCOMMA args_tail
|
@@ -2418,6 +3033,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2418
3033
|
|
|
2419
3034
|
{
|
2420
3035
|
result = args val
|
3036
|
+
# result.line lexer.lineno
|
2421
3037
|
}
|
2422
3038
|
|
2423
3039
|
args_forward: tBDOT3
|
@@ -2445,10 +3061,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2445
3061
|
f_norm_arg: f_bad_arg
|
2446
3062
|
| tIDENTIFIER
|
2447
3063
|
{
|
2448
|
-
|
3064
|
+
(id, line), = val
|
3065
|
+
identifier = id.to_sym
|
2449
3066
|
self.env[identifier] = :lvar
|
2450
3067
|
|
2451
|
-
result = identifier
|
3068
|
+
result = [identifier, line]
|
2452
3069
|
}
|
2453
3070
|
|
2454
3071
|
f_arg_asgn: f_norm_arg
|
@@ -2456,22 +3073,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2456
3073
|
f_arg_item: f_arg_asgn
|
2457
3074
|
| tLPAREN f_margs rparen
|
2458
3075
|
{
|
2459
|
-
|
3076
|
+
_, margs, _ = val
|
3077
|
+
|
3078
|
+
result = margs
|
2460
3079
|
}
|
2461
3080
|
|
2462
3081
|
f_arg: f_arg_item
|
2463
3082
|
{
|
2464
|
-
|
2465
|
-
|
2466
|
-
case arg
|
2467
|
-
when Symbol then
|
2468
|
-
result = s(:args, arg).line lexer.lineno
|
2469
|
-
when Sexp then
|
2470
|
-
result = arg
|
2471
|
-
else
|
2472
|
-
debug20 32
|
2473
|
-
raise "Unknown f_arg type: #{val.inspect}"
|
2474
|
-
end
|
3083
|
+
result = new_arg val
|
2475
3084
|
}
|
2476
3085
|
| f_arg tCOMMA f_arg_item
|
2477
3086
|
{
|
@@ -2483,7 +3092,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2483
3092
|
result = s(:args, list).line list.line
|
2484
3093
|
end
|
2485
3094
|
|
2486
|
-
result << item
|
3095
|
+
result << (Sexp === item ? item : item.first)
|
2487
3096
|
}
|
2488
3097
|
|
2489
3098
|
f_label: tLABEL
|
@@ -2544,27 +3153,37 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2544
3153
|
kwrest_mark: tPOW
|
2545
3154
|
| tDSTAR
|
2546
3155
|
|
3156
|
+
f_no_kwarg: kwrest_mark kNIL
|
3157
|
+
{
|
3158
|
+
result = :"**nil"
|
3159
|
+
}
|
3160
|
+
|
2547
3161
|
f_kwrest: kwrest_mark tIDENTIFIER
|
2548
3162
|
{
|
2549
|
-
|
2550
|
-
|
2551
|
-
|
3163
|
+
_, (id, line) = val
|
3164
|
+
|
3165
|
+
name = id.to_sym
|
3166
|
+
self.assignable [name, line]
|
3167
|
+
result = [:"**#{name}", line]
|
2552
3168
|
}
|
2553
3169
|
| kwrest_mark
|
2554
3170
|
{
|
2555
|
-
|
2556
|
-
self.env[
|
3171
|
+
id = :"**"
|
3172
|
+
self.env[id] = :lvar # TODO: needed?!?
|
3173
|
+
result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
|
2557
3174
|
}
|
2558
3175
|
|
2559
3176
|
f_opt: f_arg_asgn tEQL arg_value
|
2560
3177
|
{
|
2561
|
-
|
3178
|
+
lhs, _, rhs = val
|
3179
|
+
result = self.assignable lhs, rhs
|
2562
3180
|
# TODO: detect duplicate names
|
2563
3181
|
}
|
2564
3182
|
|
2565
3183
|
f_block_opt: f_arg_asgn tEQL primary_value
|
2566
3184
|
{
|
2567
|
-
|
3185
|
+
lhs, _, rhs = val
|
3186
|
+
result = self.assignable lhs, rhs
|
2568
3187
|
}
|
2569
3188
|
|
2570
3189
|
f_block_optarg: f_block_opt
|
@@ -2594,30 +3213,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2594
3213
|
f_rest_arg: restarg_mark tIDENTIFIER
|
2595
3214
|
{
|
2596
3215
|
# TODO: differs from parse.y - needs tests
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
3216
|
+
_, (id, line) = val
|
3217
|
+
name = id.to_sym
|
3218
|
+
self.assignable [name, line]
|
3219
|
+
result = [:"*#{name}", line]
|
2600
3220
|
}
|
2601
3221
|
| restarg_mark
|
2602
3222
|
{
|
2603
3223
|
name = :"*"
|
2604
3224
|
self.env[name] = :lvar
|
2605
|
-
result = name
|
3225
|
+
result = [name, lexer.lineno] # FIX: tSTAR to include lineno
|
2606
3226
|
}
|
2607
3227
|
|
2608
3228
|
blkarg_mark: tAMPER2 | tAMPER
|
2609
3229
|
|
2610
3230
|
f_block_arg: blkarg_mark tIDENTIFIER
|
2611
3231
|
{
|
2612
|
-
|
3232
|
+
_, (id, line) = val
|
3233
|
+
identifier = id.to_sym
|
2613
3234
|
|
2614
3235
|
self.env[identifier] = :lvar
|
2615
|
-
result = "&#{identifier}".to_sym
|
3236
|
+
result = ["&#{identifier}".to_sym, line]
|
2616
3237
|
}
|
2617
3238
|
|
2618
3239
|
opt_f_block_arg: tCOMMA f_block_arg
|
2619
3240
|
{
|
2620
|
-
|
3241
|
+
_, arg = val
|
3242
|
+
result = arg
|
2621
3243
|
}
|
2622
3244
|
|
|
2623
3245
|
{
|
@@ -2666,9 +3288,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2666
3288
|
}
|
2667
3289
|
| tSTRING_BEG string_contents tLABEL_END arg_value
|
2668
3290
|
{
|
2669
|
-
_, sym, _, value = val
|
3291
|
+
(_, line), sym, _, value = val
|
3292
|
+
|
2670
3293
|
sym.sexp_type = :dsym
|
2671
|
-
|
3294
|
+
|
3295
|
+
result = s(:array, sym, value).line line
|
2672
3296
|
}
|
2673
3297
|
| tDSTAR arg_value
|
2674
3298
|
{
|
@@ -2691,6 +3315,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
2691
3315
|
opt_nl: | tNL
|
2692
3316
|
rparen: opt_nl tRPAREN
|
2693
3317
|
rbracket: opt_nl tRBRACK
|
3318
|
+
rbrace: opt_nl tRCURLY
|
2694
3319
|
trailer: | tNL | tCOMMA
|
2695
3320
|
|
2696
3321
|
term: tSEMI { yyerrok }
|