ruby_parser 3.18.0 → 3.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ruby30_parser.y CHANGED
@@ -80,7 +80,7 @@ rule
80
80
  | klBEGIN
81
81
  {
82
82
  if (self.in_def || self.in_single > 0) then
83
- debug 11
83
+ debug 1
84
84
  yyerror "BEGIN in method"
85
85
  end
86
86
  self.env.extend
@@ -135,7 +135,7 @@ rule
135
135
  | error stmt
136
136
  {
137
137
  result = val[1]
138
- debug 12
138
+ debug 2
139
139
  }
140
140
 
141
141
  stmt_or_begin: stmt
@@ -207,7 +207,7 @@ rule
207
207
  (_, line), _, stmt, _ = val
208
208
 
209
209
  if (self.in_def || self.in_single > 0) then
210
- debug 13
210
+ debug 3
211
211
  yyerror "END in method; use at_exit"
212
212
  end
213
213
 
@@ -675,7 +675,7 @@ rule
675
675
  | primary_value tCOLON2 tCONSTANT
676
676
  {
677
677
  if (self.in_def || self.in_single > 0) then
678
- debug 14
678
+ debug 4
679
679
  yyerror "dynamic constant assignment"
680
680
  end
681
681
 
@@ -687,7 +687,7 @@ rule
687
687
  | tCOLON3 tCONSTANT
688
688
  {
689
689
  if (self.in_def || self.in_single > 0) then
690
- debug 15
690
+ debug 5
691
691
  yyerror "dynamic constant assignment"
692
692
  end
693
693
 
@@ -714,7 +714,7 @@ rule
714
714
 
715
715
  result = self.assignable var
716
716
 
717
- debug 16
717
+ debug 6
718
718
  }
719
719
  | primary_value tLBRACK2 opt_call_args rbracket
720
720
  {
@@ -745,7 +745,7 @@ rule
745
745
  expr, _, (id, _line) = val
746
746
 
747
747
  if (self.in_def || self.in_single > 0) then
748
- debug 17
748
+ debug 7
749
749
  yyerror "dynamic constant assignment"
750
750
  end
751
751
 
@@ -757,7 +757,7 @@ rule
757
757
  _, (id, l) = val
758
758
 
759
759
  if (self.in_def || self.in_single > 0) then
760
- debug 18
760
+ debug 8
761
761
  yyerror "dynamic constant assignment"
762
762
  end
763
763
 
@@ -776,8 +776,7 @@ rule
776
776
 
777
777
  cpath: tCOLON3 cname
778
778
  {
779
- _, (name, line) = val
780
- result = s(:colon3, name.to_sym).line line
779
+ result = wrap :colon3, val[1]
781
780
  }
782
781
  | cname
783
782
  {
@@ -802,9 +801,7 @@ rule
802
801
 
803
802
  fitem: fname
804
803
  {
805
- (id, line), = val
806
-
807
- result = s(:lit, id.to_sym).line line
804
+ result = wrap :lit, val[0]
808
805
  }
809
806
  | symbol
810
807
 
@@ -873,9 +870,9 @@ rule
873
870
  }
874
871
  | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
875
872
  {
876
- _, (lhs, line), op, rhs = val
873
+ _, lhs, op, rhs = val
877
874
 
878
- lhs = s(:colon3, lhs.to_sym).line line
875
+ lhs = wrap :colon3, lhs
879
876
  result = new_const_op_asgn [lhs, op, rhs]
880
877
  }
881
878
  | backref tOP_ASGN arg_rhs
@@ -958,8 +955,8 @@ rule
958
955
  }
959
956
  | tUMINUS_NUM simple_numeric tPOW arg
960
957
  {
961
- _, (num, line), _, arg = val
962
- lit = s(:lit, num).line line
958
+ _, num, _, arg = val
959
+ lit = wrap :lit, num
963
960
  result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
964
961
 
965
962
  }
@@ -1052,46 +1049,19 @@ rule
1052
1049
  }
1053
1050
  | defn_head f_opt_paren_args tEQL arg
1054
1051
  {
1055
- (name, line, in_def), args, _, body = val
1056
-
1057
- result = s(:defn, name, args, body).line line
1058
-
1059
- local_pop in_def
1060
- endless_method_name result
1052
+ result = new_endless_defn val
1061
1053
  }
1062
1054
  | defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
1063
1055
  {
1064
- (name, line, in_def), args, _, body, _, resbody = val
1065
-
1066
- result = s(:defn, name, args,
1067
- new_rescue(body,
1068
- new_resbody(s(:array).line(line),
1069
- resbody))).line line
1070
-
1071
- local_pop in_def
1072
- endless_method_name result
1056
+ result = new_endless_defn val
1073
1057
  }
1074
1058
  | defs_head f_opt_paren_args tEQL arg
1075
1059
  {
1076
- (recv, (name, line, in_def)), args, _, body = val
1077
-
1078
- result = s(:defs, recv, name, args, body).line(line)
1079
-
1080
- self.in_single -= 1
1081
- local_pop in_def
1082
- endless_method_name result
1060
+ result = new_endless_defs val
1083
1061
  }
1084
1062
  | defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
1085
1063
  {
1086
- (recv, (name, line, in_def)), args, _, body, _, resbody = val
1087
-
1088
- result = s(:defs, recv, name, args,
1089
- new_rescue(body,
1090
- new_resbody(s(:array).line(line),
1091
- resbody))).line line
1092
-
1093
- local_pop in_def
1094
- endless_method_name result
1064
+ result = new_endless_defs val
1095
1065
  }
1096
1066
  | primary
1097
1067
 
@@ -1366,9 +1336,7 @@ rule
1366
1336
  }
1367
1337
  | tCOLON3 tCONSTANT
1368
1338
  {
1369
- _, (id, line) = val
1370
-
1371
- result = s(:colon3, id.to_sym).line line
1339
+ result = wrap :colon3, val[1]
1372
1340
  }
1373
1341
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1374
1342
  {
@@ -1392,15 +1360,21 @@ rule
1392
1360
  }
1393
1361
  | kYIELD tLPAREN2 call_args rparen
1394
1362
  {
1395
- result = new_yield val[2]
1363
+ (_, line), _, args, _ = val
1364
+
1365
+ result = new_yield(args).line line
1396
1366
  }
1397
1367
  | kYIELD tLPAREN2 rparen
1398
1368
  {
1399
- result = new_yield
1369
+ (_, line), _, _ = val
1370
+
1371
+ result = new_yield.line line
1400
1372
  }
1401
1373
  | kYIELD
1402
1374
  {
1403
- result = new_yield
1375
+ (_, line), = val
1376
+
1377
+ result = new_yield.line line
1404
1378
  }
1405
1379
  | kDEFINED opt_nl tLPAREN2 expr rparen
1406
1380
  {
@@ -1415,7 +1389,7 @@ rule
1415
1389
  }
1416
1390
  | kNOT tLPAREN2 rparen
1417
1391
  {
1418
- debug 19
1392
+ debug 9
1419
1393
  }
1420
1394
  | fcall brace_block
1421
1395
  {
@@ -1725,6 +1699,7 @@ rule
1725
1699
  f_any_kwrest: f_kwrest
1726
1700
  | f_no_kwarg
1727
1701
 
1702
+
1728
1703
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1729
1704
  {
1730
1705
  result = call_args val
@@ -1855,8 +1830,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1855
1830
 
1856
1831
  bvar: tIDENTIFIER
1857
1832
  {
1858
- (id, line), = val
1859
- result = s(:shadow, id.to_sym).line line
1833
+ result = wrap :shadow, val[0]
1860
1834
  }
1861
1835
  | f_bad_arg
1862
1836
 
@@ -2470,7 +2444,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2470
2444
  assignable [lhs.value, lhs.line]
2471
2445
  else
2472
2446
  # TODO or done?
2473
- debug 666
2447
+ debug 10
2474
2448
  end
2475
2449
 
2476
2450
  # TODO PAIR -> LIST ?
@@ -2479,9 +2453,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2479
2453
 
2480
2454
  p_kw_label: tLABEL
2481
2455
  {
2482
- (id, line), = val
2483
-
2484
- result = s(:lit, id.to_sym).line line
2456
+ result = wrap :lit, val[0]
2485
2457
  }
2486
2458
 
2487
2459
  p_kwrest: kwrest_mark tIDENTIFIER
@@ -2576,26 +2548,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2576
2548
 
2577
2549
  p_variable: tIDENTIFIER
2578
2550
  {
2579
- (id, line), = val
2580
-
2581
2551
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2582
2552
  # TODO: assignable(p, $1, 0, &@$);
2583
- result = s(:lvar, id.to_sym).line line
2553
+ result = wrap :lvar, val[0]
2584
2554
  }
2585
2555
 
2586
2556
  p_var_ref: tCARET tIDENTIFIER
2587
2557
  {
2588
- _, (id, line) = val
2589
-
2590
2558
  # TODO: check id against env for lvar or dvar
2591
-
2592
- result = s(:lvar, id.to_sym).line line
2559
+ result = wrap :lvar, val[1]
2593
2560
  }
2594
2561
 
2562
+
2595
2563
  p_const: tCOLON3 cname
2596
2564
  {
2597
- _, (id, line) = val
2598
- result = s(:colon3, id.to_sym).line line
2565
+ result = wrap :colon3, val[1]
2599
2566
  }
2600
2567
  | p_const tCOLON2 cname
2601
2568
  {
@@ -2607,8 +2574,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2607
2574
  | tCONSTANT
2608
2575
  {
2609
2576
  # TODO $$ = gettable(p, $1, &@$);
2610
- (id, line), = val
2611
- result = s(:const, id.to_sym).line line
2577
+ result = wrap :const, val[0]
2612
2578
  }
2613
2579
  ######################################################################
2614
2580
 
@@ -2666,7 +2632,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2666
2632
 
2667
2633
  string: tCHAR
2668
2634
  {
2669
- debug 36
2635
+ debug 12
2670
2636
  }
2671
2637
  | string1
2672
2638
  | string string1
@@ -2887,25 +2853,22 @@ regexp_contents: none
2887
2853
  when nil then
2888
2854
  result = s(:evstr).line line
2889
2855
  else
2890
- debug 37
2856
+ debug 13
2891
2857
  raise "unknown string body: #{stmt.inspect}"
2892
2858
  end
2893
2859
  }
2894
2860
 
2895
2861
  string_dvar: tGVAR
2896
2862
  {
2897
- (id, line), = val
2898
- result = s(:gvar, id.to_sym).line line
2863
+ result = wrap :gvar, val[0]
2899
2864
  }
2900
2865
  | tIVAR
2901
2866
  {
2902
- (id, line), = val
2903
- result = s(:ivar, id.to_sym).line line
2867
+ result = wrap :ivar, val[0]
2904
2868
  }
2905
2869
  | tCVAR
2906
2870
  {
2907
- (id, line), = val
2908
- result = s(:cvar, id.to_sym).line line
2871
+ result = wrap :cvar, val[0]
2909
2872
  }
2910
2873
  | backref
2911
2874
 
@@ -2914,17 +2877,13 @@ regexp_contents: none
2914
2877
 
2915
2878
  ssym: tSYMBEG sym
2916
2879
  {
2917
- _, (id, line) = val
2918
-
2919
2880
  lexer.lex_state = EXPR_END
2920
- result = s(:lit, id.to_sym).line line
2881
+ result = wrap :lit, val[1]
2921
2882
  }
2922
2883
  | tSYMBOL
2923
2884
  {
2924
- (id, line), = val
2925
-
2926
2885
  lexer.lex_state = EXPR_END
2927
- result = s(:lit, id.to_sym).line line
2886
+ result = wrap :lit, val[0]
2928
2887
  }
2929
2888
 
2930
2889
  sym: fname | tIVAR | tGVAR | tCVAR
@@ -2945,7 +2904,7 @@ regexp_contents: none
2945
2904
  when :evstr then
2946
2905
  result = s(:dsym, "", result).line result.line
2947
2906
  else
2948
- debug 38
2907
+ debug 14
2949
2908
  end
2950
2909
  }
2951
2910
 
@@ -2961,6 +2920,7 @@ regexp_contents: none
2961
2920
  | tRATIONAL
2962
2921
  | tIMAGINARY
2963
2922
 
2923
+
2964
2924
  user_variable: tIDENTIFIER
2965
2925
  | tIVAR
2966
2926
  | tGVAR
@@ -3005,7 +2965,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3005
2965
  | keyword_variable
3006
2966
  {
3007
2967
  result = self.assignable val[0]
3008
- debug 39
2968
+ debug 15
3009
2969
  }
3010
2970
 
3011
2971
  backref: tNTH_REF
@@ -3035,6 +2995,9 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3035
2995
 
3036
2996
  f_opt_paren_args: f_paren_args
3037
2997
  | none
2998
+ {
2999
+ result = end_args val
3000
+ }
3038
3001
 
3039
3002
  f_paren_args: tLPAREN2 f_args rparen
3040
3003
  {
@@ -3283,17 +3246,25 @@ f_opt_paren_args: f_paren_args
3283
3246
  result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3284
3247
  }
3285
3248
 
3286
- f_opt: f_arg_asgn tEQL arg_value
3249
+ f_opt: f_arg_asgn
3250
+ tEQL
3251
+ arg_value
3287
3252
  {
3288
3253
  lhs, _, rhs = val
3289
3254
  result = self.assignable lhs, rhs
3290
3255
  # TODO: detect duplicate names
3256
+ # TODO? p->cur_arg = 0;
3257
+ # TODO? p->ctxt.in_argdef = 1;
3291
3258
  }
3292
3259
 
3293
- f_block_opt: f_arg_asgn tEQL primary_value
3260
+ f_block_opt: f_arg_asgn
3261
+ tEQL
3262
+ primary_value
3294
3263
  {
3295
3264
  lhs, _, rhs = val
3296
3265
  result = self.assignable lhs, rhs
3266
+ # TODO? p->cur_arg = 0;
3267
+ # TODO? p->ctxt.in_argdef = 1;
3297
3268
  }
3298
3269
 
3299
3270
  f_block_optarg: f_block_opt
@@ -3345,6 +3316,12 @@ f_opt_paren_args: f_paren_args
3345
3316
  self.env[identifier] = :lvar
3346
3317
  result = ["&#{identifier}".to_sym, line]
3347
3318
  }
3319
+ | blkarg_mark
3320
+ {
3321
+ (_, line), = val
3322
+
3323
+ result = [:&, line]
3324
+ }
3348
3325
 
3349
3326
  opt_f_block_arg: tCOMMA f_block_arg
3350
3327
  {
@@ -3391,10 +3368,17 @@ f_opt_paren_args: f_paren_args
3391
3368
  }
3392
3369
  | tLABEL arg_value
3393
3370
  {
3394
- (label, line), arg = val
3371
+ label, arg = val
3372
+
3373
+ lit = wrap :lit, label
3374
+ result = s(:array, lit, arg).line lit.line
3375
+ }
3376
+ | tLABEL
3377
+ {
3378
+ lit = wrap :lit, val[0]
3379
+ arg = nil
3395
3380
 
3396
- lit = s(:lit, label.to_sym).line line
3397
- result = s(:array, lit, arg).line line
3381
+ result = s(:array, lit, arg).line lit.line
3398
3382
  }
3399
3383
  | tSTRING_BEG string_contents tLABEL_END arg_value
3400
3384
  {