ruby_parser 3.18.1 → 3.19.0

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
  {
@@ -1425,7 +1428,7 @@ rule
1425
1428
  }
1426
1429
  | kNOT tLPAREN2 rparen
1427
1430
  {
1428
- debug 19
1431
+ debug 9
1429
1432
  }
1430
1433
  | fcall brace_block
1431
1434
  {
@@ -1735,6 +1738,10 @@ rule
1735
1738
  f_any_kwrest: f_kwrest
1736
1739
  | f_no_kwarg
1737
1740
 
1741
+ #if V > 30
1742
+ f_eq: tEQL # TODO: self.in_argdef = false
1743
+ #endif
1744
+
1738
1745
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1739
1746
  {
1740
1747
  result = call_args val
@@ -1865,8 +1872,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1865
1872
 
1866
1873
  bvar: tIDENTIFIER
1867
1874
  {
1868
- (id, line), = val
1869
- result = s(:shadow, id.to_sym).line line
1875
+ result = wrap :shadow, val[0]
1870
1876
  }
1871
1877
  | f_bad_arg
1872
1878
 
@@ -2205,6 +2211,9 @@ opt_block_args_tail: tCOMMA block_args_tail
2205
2211
  p_lbracket: tLBRACK2 { push_pktbl }
2206
2212
 
2207
2213
  p_expr_basic: p_value
2214
+ #if V > 30
2215
+ | p_variable
2216
+ #endif
2208
2217
  | p_const p_lparen p_args tRPAREN
2209
2218
  {
2210
2219
  lhs, _, args, _ = val
@@ -2480,7 +2489,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2480
2489
  assignable [lhs.value, lhs.line]
2481
2490
  else
2482
2491
  # TODO or done?
2483
- debug 666
2492
+ debug 10
2484
2493
  end
2485
2494
 
2486
2495
  # TODO PAIR -> LIST ?
@@ -2489,10 +2498,15 @@ opt_block_args_tail: tCOMMA block_args_tail
2489
2498
 
2490
2499
  p_kw_label: tLABEL
2491
2500
  {
2492
- (id, line), = val
2493
-
2494
- result = s(:lit, id.to_sym).line line
2501
+ result = wrap :lit, val[0]
2495
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
2508
+ }
2509
+ #endif
2496
2510
 
2497
2511
  p_kwrest: kwrest_mark tIDENTIFIER
2498
2512
  {
@@ -2551,8 +2565,13 @@ opt_block_args_tail: tCOMMA block_args_tail
2551
2565
 
2552
2566
  result = s(:dot3, v1, nil).line v1.line
2553
2567
  }
2568
+ #if V == 30
2554
2569
  | p_variable
2570
+ #endif
2555
2571
  | p_var_ref
2572
+ #if V > 30
2573
+ | p_expr_ref
2574
+ #endif
2556
2575
  | p_const
2557
2576
  | tBDOT2 p_primitive
2558
2577
  {
@@ -2586,26 +2605,35 @@ opt_block_args_tail: tCOMMA block_args_tail
2586
2605
 
2587
2606
  p_variable: tIDENTIFIER
2588
2607
  {
2589
- (id, line), = val
2590
-
2591
2608
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2592
2609
  # TODO: assignable(p, $1, 0, &@$);
2593
- result = s(:lvar, id.to_sym).line line
2610
+ result = wrap :lvar, val[0]
2594
2611
  }
2595
2612
 
2596
2613
  p_var_ref: tCARET tIDENTIFIER
2597
2614
  {
2598
- _, (id, line) = val
2599
-
2600
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
2601
2625
 
2602
- 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
2603
2631
  }
2632
+ #endif
2604
2633
 
2605
2634
  p_const: tCOLON3 cname
2606
2635
  {
2607
- _, (id, line) = val
2608
- result = s(:colon3, id.to_sym).line line
2636
+ result = wrap :colon3, val[1]
2609
2637
  }
2610
2638
  | p_const tCOLON2 cname
2611
2639
  {
@@ -2617,8 +2645,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2617
2645
  | tCONSTANT
2618
2646
  {
2619
2647
  # TODO $$ = gettable(p, $1, &@$);
2620
- (id, line), = val
2621
- result = s(:const, id.to_sym).line line
2648
+ result = wrap :const, val[0]
2622
2649
  }
2623
2650
  ######################################################################
2624
2651
 
@@ -2676,7 +2703,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2676
2703
 
2677
2704
  string: tCHAR
2678
2705
  {
2679
- debug 36
2706
+ debug 12
2680
2707
  }
2681
2708
  | string1
2682
2709
  | string string1
@@ -2897,25 +2924,22 @@ regexp_contents: none
2897
2924
  when nil then
2898
2925
  result = s(:evstr).line line
2899
2926
  else
2900
- debug 37
2927
+ debug 13
2901
2928
  raise "unknown string body: #{stmt.inspect}"
2902
2929
  end
2903
2930
  }
2904
2931
 
2905
2932
  string_dvar: tGVAR
2906
2933
  {
2907
- (id, line), = val
2908
- result = s(:gvar, id.to_sym).line line
2934
+ result = wrap :gvar, val[0]
2909
2935
  }
2910
2936
  | tIVAR
2911
2937
  {
2912
- (id, line), = val
2913
- result = s(:ivar, id.to_sym).line line
2938
+ result = wrap :ivar, val[0]
2914
2939
  }
2915
2940
  | tCVAR
2916
2941
  {
2917
- (id, line), = val
2918
- result = s(:cvar, id.to_sym).line line
2942
+ result = wrap :cvar, val[0]
2919
2943
  }
2920
2944
  | backref
2921
2945
 
@@ -2924,17 +2948,13 @@ regexp_contents: none
2924
2948
 
2925
2949
  ssym: tSYMBEG sym
2926
2950
  {
2927
- _, (id, line) = val
2928
-
2929
2951
  lexer.lex_state = EXPR_END
2930
- result = s(:lit, id.to_sym).line line
2952
+ result = wrap :lit, val[1]
2931
2953
  }
2932
2954
  | tSYMBOL
2933
2955
  {
2934
- (id, line), = val
2935
-
2936
2956
  lexer.lex_state = EXPR_END
2937
- result = s(:lit, id.to_sym).line line
2957
+ result = wrap :lit, val[0]
2938
2958
  }
2939
2959
 
2940
2960
  sym: fname | tIVAR | tGVAR | tCVAR
@@ -2955,7 +2975,7 @@ regexp_contents: none
2955
2975
  when :evstr then
2956
2976
  result = s(:dsym, "", result).line result.line
2957
2977
  else
2958
- debug 38
2978
+ debug 14
2959
2979
  end
2960
2980
  }
2961
2981
 
@@ -2971,6 +2991,12 @@ regexp_contents: none
2971
2991
  | tRATIONAL
2972
2992
  | tIMAGINARY
2973
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
+
2974
3000
  user_variable: tIDENTIFIER
2975
3001
  | tIVAR
2976
3002
  | tGVAR
@@ -3015,7 +3041,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3015
3041
  | keyword_variable
3016
3042
  {
3017
3043
  result = self.assignable val[0]
3018
- debug 39
3044
+ debug 15
3019
3045
  }
3020
3046
 
3021
3047
  backref: tNTH_REF
@@ -3053,6 +3079,7 @@ f_opt_paren_args: f_paren_args
3053
3079
  {
3054
3080
  result = end_args val
3055
3081
  }
3082
+ #if V == 30
3056
3083
  | tLPAREN2 f_arg tCOMMA args_forward rparen
3057
3084
  {
3058
3085
  result = end_args val
@@ -3061,6 +3088,7 @@ f_opt_paren_args: f_paren_args
3061
3088
  {
3062
3089
  result = end_args val
3063
3090
  }
3091
+ #endif
3064
3092
 
3065
3093
  f_arglist: f_paren_args
3066
3094
  | {
@@ -3086,6 +3114,9 @@ f_opt_paren_args: f_paren_args
3086
3114
  result = args val
3087
3115
  }
3088
3116
  | f_block_arg
3117
+ #if V > 30
3118
+ | args_forward
3119
+ #endif
3089
3120
 
3090
3121
  opt_args_tail: tCOMMA args_tail
3091
3122
  {
@@ -3296,17 +3327,33 @@ f_opt_paren_args: f_paren_args
3296
3327
  result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3297
3328
  }
3298
3329
 
3299
- 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
3300
3337
  {
3301
3338
  lhs, _, rhs = val
3302
3339
  result = self.assignable lhs, rhs
3303
3340
  # TODO: detect duplicate names
3341
+ # TODO? p->cur_arg = 0;
3342
+ # TODO? p->ctxt.in_argdef = 1;
3304
3343
  }
3305
3344
 
3306
- 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
3307
3352
  {
3308
3353
  lhs, _, rhs = val
3309
3354
  result = self.assignable lhs, rhs
3355
+ # TODO? p->cur_arg = 0;
3356
+ # TODO? p->ctxt.in_argdef = 1;
3310
3357
  }
3311
3358
 
3312
3359
  f_block_optarg: f_block_opt
@@ -3358,6 +3405,12 @@ f_opt_paren_args: f_paren_args
3358
3405
  self.env[identifier] = :lvar
3359
3406
  result = ["&#{identifier}".to_sym, line]
3360
3407
  }
3408
+ | blkarg_mark
3409
+ {
3410
+ (_, line), = val
3411
+
3412
+ result = [:&, line]
3413
+ }
3361
3414
 
3362
3415
  opt_f_block_arg: tCOMMA f_block_arg
3363
3416
  {
@@ -3404,10 +3457,17 @@ f_opt_paren_args: f_paren_args
3404
3457
  }
3405
3458
  | tLABEL arg_value
3406
3459
  {
3407
- (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
3408
3469
 
3409
- lit = s(:lit, label.to_sym).line line
3410
- result = s(:array, lit, arg).line line
3470
+ result = s(:array, lit, arg).line lit.line
3411
3471
  }
3412
3472
  | tSTRING_BEG string_contents tLABEL_END arg_value
3413
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