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/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
  {
@@ -1421,7 +1389,7 @@ rule
1421
1389
  }
1422
1390
  | kNOT tLPAREN2 rparen
1423
1391
  {
1424
- debug 19
1392
+ debug 9
1425
1393
  }
1426
1394
  | fcall brace_block
1427
1395
  {
@@ -1731,6 +1699,7 @@ rule
1731
1699
  f_any_kwrest: f_kwrest
1732
1700
  | f_no_kwarg
1733
1701
 
1702
+
1734
1703
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1735
1704
  {
1736
1705
  result = call_args val
@@ -1861,8 +1830,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1861
1830
 
1862
1831
  bvar: tIDENTIFIER
1863
1832
  {
1864
- (id, line), = val
1865
- result = s(:shadow, id.to_sym).line line
1833
+ result = wrap :shadow, val[0]
1866
1834
  }
1867
1835
  | f_bad_arg
1868
1836
 
@@ -2476,7 +2444,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2476
2444
  assignable [lhs.value, lhs.line]
2477
2445
  else
2478
2446
  # TODO or done?
2479
- debug 666
2447
+ debug 10
2480
2448
  end
2481
2449
 
2482
2450
  # TODO PAIR -> LIST ?
@@ -2485,9 +2453,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2485
2453
 
2486
2454
  p_kw_label: tLABEL
2487
2455
  {
2488
- (id, line), = val
2489
-
2490
- result = s(:lit, id.to_sym).line line
2456
+ result = wrap :lit, val[0]
2491
2457
  }
2492
2458
 
2493
2459
  p_kwrest: kwrest_mark tIDENTIFIER
@@ -2582,26 +2548,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2582
2548
 
2583
2549
  p_variable: tIDENTIFIER
2584
2550
  {
2585
- (id, line), = val
2586
-
2587
2551
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2588
2552
  # TODO: assignable(p, $1, 0, &@$);
2589
- result = s(:lvar, id.to_sym).line line
2553
+ result = wrap :lvar, val[0]
2590
2554
  }
2591
2555
 
2592
2556
  p_var_ref: tCARET tIDENTIFIER
2593
2557
  {
2594
- _, (id, line) = val
2595
-
2596
2558
  # TODO: check id against env for lvar or dvar
2597
-
2598
- result = s(:lvar, id.to_sym).line line
2559
+ result = wrap :lvar, val[1]
2599
2560
  }
2600
2561
 
2562
+
2601
2563
  p_const: tCOLON3 cname
2602
2564
  {
2603
- _, (id, line) = val
2604
- result = s(:colon3, id.to_sym).line line
2565
+ result = wrap :colon3, val[1]
2605
2566
  }
2606
2567
  | p_const tCOLON2 cname
2607
2568
  {
@@ -2613,8 +2574,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2613
2574
  | tCONSTANT
2614
2575
  {
2615
2576
  # TODO $$ = gettable(p, $1, &@$);
2616
- (id, line), = val
2617
- result = s(:const, id.to_sym).line line
2577
+ result = wrap :const, val[0]
2618
2578
  }
2619
2579
  ######################################################################
2620
2580
 
@@ -2672,7 +2632,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2672
2632
 
2673
2633
  string: tCHAR
2674
2634
  {
2675
- debug 36
2635
+ debug 12
2676
2636
  }
2677
2637
  | string1
2678
2638
  | string string1
@@ -2893,25 +2853,22 @@ regexp_contents: none
2893
2853
  when nil then
2894
2854
  result = s(:evstr).line line
2895
2855
  else
2896
- debug 37
2856
+ debug 13
2897
2857
  raise "unknown string body: #{stmt.inspect}"
2898
2858
  end
2899
2859
  }
2900
2860
 
2901
2861
  string_dvar: tGVAR
2902
2862
  {
2903
- (id, line), = val
2904
- result = s(:gvar, id.to_sym).line line
2863
+ result = wrap :gvar, val[0]
2905
2864
  }
2906
2865
  | tIVAR
2907
2866
  {
2908
- (id, line), = val
2909
- result = s(:ivar, id.to_sym).line line
2867
+ result = wrap :ivar, val[0]
2910
2868
  }
2911
2869
  | tCVAR
2912
2870
  {
2913
- (id, line), = val
2914
- result = s(:cvar, id.to_sym).line line
2871
+ result = wrap :cvar, val[0]
2915
2872
  }
2916
2873
  | backref
2917
2874
 
@@ -2920,17 +2877,13 @@ regexp_contents: none
2920
2877
 
2921
2878
  ssym: tSYMBEG sym
2922
2879
  {
2923
- _, (id, line) = val
2924
-
2925
2880
  lexer.lex_state = EXPR_END
2926
- result = s(:lit, id.to_sym).line line
2881
+ result = wrap :lit, val[1]
2927
2882
  }
2928
2883
  | tSYMBOL
2929
2884
  {
2930
- (id, line), = val
2931
-
2932
2885
  lexer.lex_state = EXPR_END
2933
- result = s(:lit, id.to_sym).line line
2886
+ result = wrap :lit, val[0]
2934
2887
  }
2935
2888
 
2936
2889
  sym: fname | tIVAR | tGVAR | tCVAR
@@ -2951,7 +2904,7 @@ regexp_contents: none
2951
2904
  when :evstr then
2952
2905
  result = s(:dsym, "", result).line result.line
2953
2906
  else
2954
- debug 38
2907
+ debug 14
2955
2908
  end
2956
2909
  }
2957
2910
 
@@ -2967,6 +2920,7 @@ regexp_contents: none
2967
2920
  | tRATIONAL
2968
2921
  | tIMAGINARY
2969
2922
 
2923
+
2970
2924
  user_variable: tIDENTIFIER
2971
2925
  | tIVAR
2972
2926
  | tGVAR
@@ -3011,7 +2965,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3011
2965
  | keyword_variable
3012
2966
  {
3013
2967
  result = self.assignable val[0]
3014
- debug 39
2968
+ debug 15
3015
2969
  }
3016
2970
 
3017
2971
  backref: tNTH_REF
@@ -3292,17 +3246,25 @@ f_opt_paren_args: f_paren_args
3292
3246
  result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3293
3247
  }
3294
3248
 
3295
- f_opt: f_arg_asgn tEQL arg_value
3249
+ f_opt: f_arg_asgn
3250
+ tEQL
3251
+ arg_value
3296
3252
  {
3297
3253
  lhs, _, rhs = val
3298
3254
  result = self.assignable lhs, rhs
3299
3255
  # TODO: detect duplicate names
3256
+ # TODO? p->cur_arg = 0;
3257
+ # TODO? p->ctxt.in_argdef = 1;
3300
3258
  }
3301
3259
 
3302
- f_block_opt: f_arg_asgn tEQL primary_value
3260
+ f_block_opt: f_arg_asgn
3261
+ tEQL
3262
+ primary_value
3303
3263
  {
3304
3264
  lhs, _, rhs = val
3305
3265
  result = self.assignable lhs, rhs
3266
+ # TODO? p->cur_arg = 0;
3267
+ # TODO? p->ctxt.in_argdef = 1;
3306
3268
  }
3307
3269
 
3308
3270
  f_block_optarg: f_block_opt
@@ -3354,6 +3316,12 @@ f_opt_paren_args: f_paren_args
3354
3316
  self.env[identifier] = :lvar
3355
3317
  result = ["&#{identifier}".to_sym, line]
3356
3318
  }
3319
+ | blkarg_mark
3320
+ {
3321
+ (_, line), = val
3322
+
3323
+ result = [:&, line]
3324
+ }
3357
3325
 
3358
3326
  opt_f_block_arg: tCOMMA f_block_arg
3359
3327
  {
@@ -3400,10 +3368,17 @@ f_opt_paren_args: f_paren_args
3400
3368
  }
3401
3369
  | tLABEL arg_value
3402
3370
  {
3403
- (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
3404
3380
 
3405
- lit = s(:lit, label.to_sym).line line
3406
- result = s(:array, lit, arg).line line
3381
+ result = s(:array, lit, arg).line lit.line
3407
3382
  }
3408
3383
  | tSTRING_BEG string_contents tLABEL_END arg_value
3409
3384
  {