ruby_parser 3.18.0 → 3.19.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby3_parser.yy CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  #if V == 30
4
4
  class Ruby30Parser
5
+ #elif V == 31
6
+ class Ruby31Parser
5
7
  #else
6
8
  fail "version not specified or supported on code generation"
7
9
  #endif
@@ -84,7 +86,7 @@ rule
84
86
  | klBEGIN
85
87
  {
86
88
  if (self.in_def || self.in_single > 0) then
87
- debug 11
89
+ debug 1
88
90
  yyerror "BEGIN in method"
89
91
  end
90
92
  self.env.extend
@@ -139,7 +141,7 @@ rule
139
141
  | error stmt
140
142
  {
141
143
  result = val[1]
142
- debug 12
144
+ debug 2
143
145
  }
144
146
 
145
147
  stmt_or_begin: stmt
@@ -211,7 +213,7 @@ rule
211
213
  (_, line), _, stmt, _ = val
212
214
 
213
215
  if (self.in_def || self.in_single > 0) then
214
- debug 13
216
+ debug 3
215
217
  yyerror "END in method; use at_exit"
216
218
  end
217
219
 
@@ -286,6 +288,24 @@ rule
286
288
 
287
289
  result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
288
290
  }
291
+ #if V > 30
292
+ | defn_head f_opt_paren_args tEQL command
293
+ {
294
+ result = new_endless_defn val
295
+ }
296
+ | defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
297
+ {
298
+ result = new_endless_defn val
299
+ }
300
+ | defs_head f_opt_paren_args tEQL command
301
+ {
302
+ result = new_endless_defs val
303
+ }
304
+ | defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
305
+ {
306
+ result = new_endless_defs val
307
+ }
308
+ #endif
289
309
  | backref tOP_ASGN command_rhs
290
310
  {
291
311
  self.backref_assign_error val[0]
@@ -339,7 +359,11 @@ rule
339
359
  self.in_kwarg = true
340
360
  self.env.extend
341
361
  }
362
+ #if V == 30
342
363
  p_expr
364
+ #else
365
+ p_top_expr_body
366
+ #endif
343
367
  {
344
368
  lhs, _, in_kwarg, rhs = val
345
369
 
@@ -359,7 +383,11 @@ rule
359
383
  self.in_kwarg = true
360
384
  self.env.extend
361
385
  }
386
+ #if V == 30
362
387
  p_expr
388
+ #else
389
+ p_top_expr_body
390
+ #endif
363
391
  {
364
392
  self.env.unextend
365
393
 
@@ -679,7 +707,7 @@ rule
679
707
  | primary_value tCOLON2 tCONSTANT
680
708
  {
681
709
  if (self.in_def || self.in_single > 0) then
682
- debug 14
710
+ debug 4
683
711
  yyerror "dynamic constant assignment"
684
712
  end
685
713
 
@@ -691,7 +719,7 @@ rule
691
719
  | tCOLON3 tCONSTANT
692
720
  {
693
721
  if (self.in_def || self.in_single > 0) then
694
- debug 15
722
+ debug 5
695
723
  yyerror "dynamic constant assignment"
696
724
  end
697
725
 
@@ -718,7 +746,7 @@ rule
718
746
 
719
747
  result = self.assignable var
720
748
 
721
- debug 16
749
+ debug 6
722
750
  }
723
751
  | primary_value tLBRACK2 opt_call_args rbracket
724
752
  {
@@ -749,7 +777,7 @@ rule
749
777
  expr, _, (id, _line) = val
750
778
 
751
779
  if (self.in_def || self.in_single > 0) then
752
- debug 17
780
+ debug 7
753
781
  yyerror "dynamic constant assignment"
754
782
  end
755
783
 
@@ -761,7 +789,7 @@ rule
761
789
  _, (id, l) = val
762
790
 
763
791
  if (self.in_def || self.in_single > 0) then
764
- debug 18
792
+ debug 8
765
793
  yyerror "dynamic constant assignment"
766
794
  end
767
795
 
@@ -780,8 +808,7 @@ rule
780
808
 
781
809
  cpath: tCOLON3 cname
782
810
  {
783
- _, (name, line) = val
784
- result = s(:colon3, name.to_sym).line line
811
+ result = wrap :colon3, val[1]
785
812
  }
786
813
  | cname
787
814
  {
@@ -806,9 +833,7 @@ rule
806
833
 
807
834
  fitem: fname
808
835
  {
809
- (id, line), = val
810
-
811
- result = s(:lit, id.to_sym).line line
836
+ result = wrap :lit, val[0]
812
837
  }
813
838
  | symbol
814
839
 
@@ -877,9 +902,9 @@ rule
877
902
  }
878
903
  | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
879
904
  {
880
- _, (lhs, line), op, rhs = val
905
+ _, lhs, op, rhs = val
881
906
 
882
- lhs = s(:colon3, lhs.to_sym).line line
907
+ lhs = wrap :colon3, lhs
883
908
  result = new_const_op_asgn [lhs, op, rhs]
884
909
  }
885
910
  | backref tOP_ASGN arg_rhs
@@ -962,8 +987,8 @@ rule
962
987
  }
963
988
  | tUMINUS_NUM simple_numeric tPOW arg
964
989
  {
965
- _, (num, line), _, arg = val
966
- lit = s(:lit, num).line line
990
+ _, num, _, arg = val
991
+ lit = wrap :lit, num
967
992
  result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
968
993
 
969
994
  }
@@ -1056,46 +1081,19 @@ rule
1056
1081
  }
1057
1082
  | defn_head f_opt_paren_args tEQL arg
1058
1083
  {
1059
- (name, line, in_def), args, _, body = val
1060
-
1061
- result = s(:defn, name, args, body).line line
1062
-
1063
- local_pop in_def
1064
- endless_method_name result
1084
+ result = new_endless_defn val
1065
1085
  }
1066
1086
  | defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
1067
1087
  {
1068
- (name, line, in_def), args, _, body, _, resbody = val
1069
-
1070
- result = s(:defn, name, args,
1071
- new_rescue(body,
1072
- new_resbody(s(:array).line(line),
1073
- resbody))).line line
1074
-
1075
- local_pop in_def
1076
- endless_method_name result
1088
+ result = new_endless_defn val
1077
1089
  }
1078
1090
  | defs_head f_opt_paren_args tEQL arg
1079
1091
  {
1080
- (recv, (name, line, in_def)), args, _, body = val
1081
-
1082
- result = s(:defs, recv, name, args, body).line(line)
1083
-
1084
- self.in_single -= 1
1085
- local_pop in_def
1086
- endless_method_name result
1092
+ result = new_endless_defs val
1087
1093
  }
1088
1094
  | defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
1089
1095
  {
1090
- (recv, (name, line, in_def)), args, _, body, _, resbody = val
1091
-
1092
- result = s(:defs, recv, name, args,
1093
- new_rescue(body,
1094
- new_resbody(s(:array).line(line),
1095
- resbody))).line line
1096
-
1097
- local_pop in_def
1098
- endless_method_name result
1096
+ result = new_endless_defs val
1099
1097
  }
1100
1098
  | primary
1101
1099
 
@@ -1251,6 +1249,13 @@ rule
1251
1249
  _, arg = val
1252
1250
  result = s(:block_pass, arg).line arg.line
1253
1251
  }
1252
+ #if V > 30
1253
+ | tAMPER
1254
+ {
1255
+ (_, line), = val
1256
+ result = s(:block_pass).line line
1257
+ }
1258
+ #endif
1254
1259
 
1255
1260
  opt_block_arg: tCOMMA block_arg
1256
1261
  {
@@ -1370,9 +1375,7 @@ rule
1370
1375
  }
1371
1376
  | tCOLON3 tCONSTANT
1372
1377
  {
1373
- _, (id, line) = val
1374
-
1375
- result = s(:colon3, id.to_sym).line line
1378
+ result = wrap :colon3, val[1]
1376
1379
  }
1377
1380
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1378
1381
  {
@@ -1396,15 +1399,21 @@ rule
1396
1399
  }
1397
1400
  | kYIELD tLPAREN2 call_args rparen
1398
1401
  {
1399
- result = new_yield val[2]
1402
+ (_, line), _, args, _ = val
1403
+
1404
+ result = new_yield(args).line line
1400
1405
  }
1401
1406
  | kYIELD tLPAREN2 rparen
1402
1407
  {
1403
- result = new_yield
1408
+ (_, line), _, _ = val
1409
+
1410
+ result = new_yield.line line
1404
1411
  }
1405
1412
  | kYIELD
1406
1413
  {
1407
- result = new_yield
1414
+ (_, line), = val
1415
+
1416
+ result = new_yield.line line
1408
1417
  }
1409
1418
  | kDEFINED opt_nl tLPAREN2 expr rparen
1410
1419
  {
@@ -1419,7 +1428,7 @@ rule
1419
1428
  }
1420
1429
  | kNOT tLPAREN2 rparen
1421
1430
  {
1422
- debug 19
1431
+ debug 9
1423
1432
  }
1424
1433
  | fcall brace_block
1425
1434
  {
@@ -1729,6 +1738,10 @@ rule
1729
1738
  f_any_kwrest: f_kwrest
1730
1739
  | f_no_kwarg
1731
1740
 
1741
+ #if V > 30
1742
+ f_eq: tEQL # TODO: self.in_argdef = false
1743
+ #endif
1744
+
1732
1745
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1733
1746
  {
1734
1747
  result = call_args val
@@ -1859,8 +1872,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1859
1872
 
1860
1873
  bvar: tIDENTIFIER
1861
1874
  {
1862
- (id, line), = val
1863
- result = s(:shadow, id.to_sym).line line
1875
+ result = wrap :shadow, val[0]
1864
1876
  }
1865
1877
  | f_bad_arg
1866
1878
 
@@ -2199,6 +2211,9 @@ opt_block_args_tail: tCOMMA block_args_tail
2199
2211
  p_lbracket: tLBRACK2 { push_pktbl }
2200
2212
 
2201
2213
  p_expr_basic: p_value
2214
+ #if V > 30
2215
+ | p_variable
2216
+ #endif
2202
2217
  | p_const p_lparen p_args tRPAREN
2203
2218
  {
2204
2219
  lhs, _, args, _ = val
@@ -2474,7 +2489,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2474
2489
  assignable [lhs.value, lhs.line]
2475
2490
  else
2476
2491
  # TODO or done?
2477
- debug 666
2492
+ debug 10
2478
2493
  end
2479
2494
 
2480
2495
  # TODO PAIR -> LIST ?
@@ -2483,10 +2498,15 @@ opt_block_args_tail: tCOMMA block_args_tail
2483
2498
 
2484
2499
  p_kw_label: tLABEL
2485
2500
  {
2486
- (id, line), = val
2487
-
2488
- result = s(:lit, id.to_sym).line line
2501
+ result = wrap :lit, val[0]
2502
+ }
2503
+ #if V > 30
2504
+ | tSTRING_BEG string_contents tLABEL_END
2505
+ {
2506
+ # you can't actually get here the way I lex labels
2507
+ debug 11
2489
2508
  }
2509
+ #endif
2490
2510
 
2491
2511
  p_kwrest: kwrest_mark tIDENTIFIER
2492
2512
  {
@@ -2545,8 +2565,13 @@ opt_block_args_tail: tCOMMA block_args_tail
2545
2565
 
2546
2566
  result = s(:dot3, v1, nil).line v1.line
2547
2567
  }
2568
+ #if V == 30
2548
2569
  | p_variable
2570
+ #endif
2549
2571
  | p_var_ref
2572
+ #if V > 30
2573
+ | p_expr_ref
2574
+ #endif
2550
2575
  | p_const
2551
2576
  | tBDOT2 p_primitive
2552
2577
  {
@@ -2580,26 +2605,35 @@ opt_block_args_tail: tCOMMA block_args_tail
2580
2605
 
2581
2606
  p_variable: tIDENTIFIER
2582
2607
  {
2583
- (id, line), = val
2584
-
2585
2608
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2586
2609
  # TODO: assignable(p, $1, 0, &@$);
2587
- result = s(:lvar, id.to_sym).line line
2610
+ result = wrap :lvar, val[0]
2588
2611
  }
2589
2612
 
2590
2613
  p_var_ref: tCARET tIDENTIFIER
2591
2614
  {
2592
- _, (id, line) = val
2593
-
2594
2615
  # TODO: check id against env for lvar or dvar
2616
+ result = wrap :lvar, val[1]
2617
+ }
2618
+ #if V > 30
2619
+ | tCARET nonlocal_var
2620
+ {
2621
+ _, var = val
2622
+ result = var
2623
+ }
2624
+ #endif
2595
2625
 
2596
- result = s(:lvar, id.to_sym).line line
2626
+ #if V > 30
2627
+ p_expr_ref: tCARET tLPAREN expr_value rparen
2628
+ {
2629
+ _, _, expr, _ = val
2630
+ result = expr # TODO? s(:begin, expr).line expr.line
2597
2631
  }
2632
+ #endif
2598
2633
 
2599
2634
  p_const: tCOLON3 cname
2600
2635
  {
2601
- _, (id, line) = val
2602
- result = s(:colon3, id.to_sym).line line
2636
+ result = wrap :colon3, val[1]
2603
2637
  }
2604
2638
  | p_const tCOLON2 cname
2605
2639
  {
@@ -2611,8 +2645,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2611
2645
  | tCONSTANT
2612
2646
  {
2613
2647
  # TODO $$ = gettable(p, $1, &@$);
2614
- (id, line), = val
2615
- result = s(:const, id.to_sym).line line
2648
+ result = wrap :const, val[0]
2616
2649
  }
2617
2650
  ######################################################################
2618
2651
 
@@ -2670,7 +2703,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2670
2703
 
2671
2704
  string: tCHAR
2672
2705
  {
2673
- debug 36
2706
+ debug 12
2674
2707
  }
2675
2708
  | string1
2676
2709
  | string string1
@@ -2891,25 +2924,22 @@ regexp_contents: none
2891
2924
  when nil then
2892
2925
  result = s(:evstr).line line
2893
2926
  else
2894
- debug 37
2927
+ debug 13
2895
2928
  raise "unknown string body: #{stmt.inspect}"
2896
2929
  end
2897
2930
  }
2898
2931
 
2899
2932
  string_dvar: tGVAR
2900
2933
  {
2901
- (id, line), = val
2902
- result = s(:gvar, id.to_sym).line line
2934
+ result = wrap :gvar, val[0]
2903
2935
  }
2904
2936
  | tIVAR
2905
2937
  {
2906
- (id, line), = val
2907
- result = s(:ivar, id.to_sym).line line
2938
+ result = wrap :ivar, val[0]
2908
2939
  }
2909
2940
  | tCVAR
2910
2941
  {
2911
- (id, line), = val
2912
- result = s(:cvar, id.to_sym).line line
2942
+ result = wrap :cvar, val[0]
2913
2943
  }
2914
2944
  | backref
2915
2945
 
@@ -2918,17 +2948,13 @@ regexp_contents: none
2918
2948
 
2919
2949
  ssym: tSYMBEG sym
2920
2950
  {
2921
- _, (id, line) = val
2922
-
2923
2951
  lexer.lex_state = EXPR_END
2924
- result = s(:lit, id.to_sym).line line
2952
+ result = wrap :lit, val[1]
2925
2953
  }
2926
2954
  | tSYMBOL
2927
2955
  {
2928
- (id, line), = val
2929
-
2930
2956
  lexer.lex_state = EXPR_END
2931
- result = s(:lit, id.to_sym).line line
2957
+ result = wrap :lit, val[0]
2932
2958
  }
2933
2959
 
2934
2960
  sym: fname | tIVAR | tGVAR | tCVAR
@@ -2949,7 +2975,7 @@ regexp_contents: none
2949
2975
  when :evstr then
2950
2976
  result = s(:dsym, "", result).line result.line
2951
2977
  else
2952
- debug 38
2978
+ debug 14
2953
2979
  end
2954
2980
  }
2955
2981
 
@@ -2965,6 +2991,12 @@ regexp_contents: none
2965
2991
  | tRATIONAL
2966
2992
  | tIMAGINARY
2967
2993
 
2994
+ #if V > 30
2995
+ nonlocal_var: tIVAR { result = wrap :ivar, val[0] }
2996
+ | tGVAR { result = wrap :gvar, val[0] }
2997
+ | tCVAR { result = wrap :cvar, val[0] }
2998
+ #endif
2999
+
2968
3000
  user_variable: tIDENTIFIER
2969
3001
  | tIVAR
2970
3002
  | tGVAR
@@ -3009,7 +3041,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3009
3041
  | keyword_variable
3010
3042
  {
3011
3043
  result = self.assignable val[0]
3012
- debug 39
3044
+ debug 15
3013
3045
  }
3014
3046
 
3015
3047
  backref: tNTH_REF
@@ -3039,11 +3071,15 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3039
3071
 
3040
3072
  f_opt_paren_args: f_paren_args
3041
3073
  | none
3074
+ {
3075
+ result = end_args val
3076
+ }
3042
3077
 
3043
3078
  f_paren_args: tLPAREN2 f_args rparen
3044
3079
  {
3045
3080
  result = end_args val
3046
3081
  }
3082
+ #if V == 30
3047
3083
  | tLPAREN2 f_arg tCOMMA args_forward rparen
3048
3084
  {
3049
3085
  result = end_args val
@@ -3052,6 +3088,7 @@ f_opt_paren_args: f_paren_args
3052
3088
  {
3053
3089
  result = end_args val
3054
3090
  }
3091
+ #endif
3055
3092
 
3056
3093
  f_arglist: f_paren_args
3057
3094
  | {
@@ -3077,6 +3114,9 @@ f_opt_paren_args: f_paren_args
3077
3114
  result = args val
3078
3115
  }
3079
3116
  | f_block_arg
3117
+ #if V > 30
3118
+ | args_forward
3119
+ #endif
3080
3120
 
3081
3121
  opt_args_tail: tCOMMA args_tail
3082
3122
  {
@@ -3287,17 +3327,33 @@ f_opt_paren_args: f_paren_args
3287
3327
  result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3288
3328
  }
3289
3329
 
3290
- f_opt: f_arg_asgn tEQL arg_value
3330
+ f_opt: f_arg_asgn
3331
+ #if V > 30
3332
+ f_eq
3333
+ #else
3334
+ tEQL
3335
+ #endif
3336
+ arg_value
3291
3337
  {
3292
3338
  lhs, _, rhs = val
3293
3339
  result = self.assignable lhs, rhs
3294
3340
  # TODO: detect duplicate names
3341
+ # TODO? p->cur_arg = 0;
3342
+ # TODO? p->ctxt.in_argdef = 1;
3295
3343
  }
3296
3344
 
3297
- f_block_opt: f_arg_asgn tEQL primary_value
3345
+ f_block_opt: f_arg_asgn
3346
+ #if V > 30
3347
+ f_eq
3348
+ #else
3349
+ tEQL
3350
+ #endif
3351
+ primary_value
3298
3352
  {
3299
3353
  lhs, _, rhs = val
3300
3354
  result = self.assignable lhs, rhs
3355
+ # TODO? p->cur_arg = 0;
3356
+ # TODO? p->ctxt.in_argdef = 1;
3301
3357
  }
3302
3358
 
3303
3359
  f_block_optarg: f_block_opt
@@ -3349,6 +3405,12 @@ f_opt_paren_args: f_paren_args
3349
3405
  self.env[identifier] = :lvar
3350
3406
  result = ["&#{identifier}".to_sym, line]
3351
3407
  }
3408
+ | blkarg_mark
3409
+ {
3410
+ (_, line), = val
3411
+
3412
+ result = [:&, line]
3413
+ }
3352
3414
 
3353
3415
  opt_f_block_arg: tCOMMA f_block_arg
3354
3416
  {
@@ -3395,10 +3457,17 @@ f_opt_paren_args: f_paren_args
3395
3457
  }
3396
3458
  | tLABEL arg_value
3397
3459
  {
3398
- (label, line), arg = val
3460
+ label, arg = val
3461
+
3462
+ lit = wrap :lit, label
3463
+ result = s(:array, lit, arg).line lit.line
3464
+ }
3465
+ | tLABEL
3466
+ {
3467
+ lit = wrap :lit, val[0]
3468
+ arg = nil
3399
3469
 
3400
- lit = s(:lit, label.to_sym).line line
3401
- result = s(:array, lit, arg).line line
3470
+ result = s(:array, lit, arg).line lit.line
3402
3471
  }
3403
3472
  | tSTRING_BEG string_contents tLABEL_END arg_value
3404
3473
  {
data/lib/ruby_parser.rb CHANGED
@@ -80,10 +80,12 @@ require "ruby25_parser"
80
80
  require "ruby26_parser"
81
81
  require "ruby27_parser"
82
82
  require "ruby30_parser"
83
+ require "ruby31_parser"
83
84
 
84
85
  class RubyParser # HACK
85
86
  VERSIONS.clear # also a HACK caused by racc namespace issues
86
87
 
88
+ class V31 < ::Ruby31Parser; end
87
89
  class V30 < ::Ruby30Parser; end
88
90
  class V27 < ::Ruby27Parser; end
89
91
  class V26 < ::Ruby26Parser; end