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/ruby_parser.yy CHANGED
@@ -767,8 +767,7 @@ rule
767
767
 
768
768
  cpath: tCOLON3 cname
769
769
  {
770
- _, (name, line) = val
771
- result = s(:colon3, name.to_sym).line line
770
+ result = wrap :colon3, val[1]
772
771
  }
773
772
  | cname
774
773
  {
@@ -793,9 +792,7 @@ rule
793
792
 
794
793
  fitem: fname
795
794
  {
796
- (id, line), = val
797
-
798
- result = s(:lit, id.to_sym).line line
795
+ result = wrap :lit, val[0]
799
796
  }
800
797
  | symbol
801
798
 
@@ -864,9 +861,9 @@ rule
864
861
  }
865
862
  | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
866
863
  {
867
- _, (lhs, line), op, rhs = val
864
+ _, lhs, op, rhs = val
868
865
 
869
- lhs = s(:colon3, lhs.to_sym).line line
866
+ lhs = wrap :colon3, lhs
870
867
  result = new_const_op_asgn [lhs, op, rhs]
871
868
  }
872
869
  | backref tOP_ASGN arg_rhs
@@ -1336,9 +1333,7 @@ rule
1336
1333
  }
1337
1334
  | tCOLON3 tCONSTANT
1338
1335
  {
1339
- _, (id, line) = val
1340
-
1341
- result = s(:colon3, id.to_sym).line line
1336
+ result = wrap :colon3, val[1]
1342
1337
  }
1343
1338
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1344
1339
  {
@@ -1362,15 +1357,21 @@ rule
1362
1357
  }
1363
1358
  | kYIELD tLPAREN2 call_args rparen
1364
1359
  {
1365
- result = new_yield val[2]
1360
+ (_, line), _, args, _ = val
1361
+
1362
+ result = new_yield(args).line line
1366
1363
  }
1367
1364
  | kYIELD tLPAREN2 rparen
1368
1365
  {
1369
- result = new_yield
1366
+ (_, line), _, _ = val
1367
+
1368
+ result = new_yield.line line
1370
1369
  }
1371
1370
  | kYIELD
1372
1371
  {
1373
- result = new_yield
1372
+ (_, line), = val
1373
+
1374
+ result = new_yield.line line
1374
1375
  }
1375
1376
  | kDEFINED opt_nl tLPAREN2 expr rparen
1376
1377
  {
@@ -1840,8 +1841,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1840
1841
 
1841
1842
  bvar: tIDENTIFIER
1842
1843
  {
1843
- (id, line), = val
1844
- result = s(:shadow, id.to_sym).line line
1844
+ result = wrap :shadow, val[0]
1845
1845
  }
1846
1846
  | f_bad_arg
1847
1847
 
@@ -2452,9 +2452,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2452
2452
 
2453
2453
  p_kw_label: tLABEL
2454
2454
  {
2455
- (id, line), = val
2456
-
2457
- result = s(:lit, id.to_sym).line line
2455
+ result = wrap :lit, val[0]
2458
2456
  }
2459
2457
 
2460
2458
  p_kwrest: kwrest_mark tIDENTIFIER
@@ -2546,26 +2544,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2546
2544
 
2547
2545
  p_variable: tIDENTIFIER
2548
2546
  {
2549
- (id, line), = val
2550
-
2551
2547
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2552
2548
  # TODO: assignable(p, $1, 0, &@$);
2553
- result = s(:lvar, id.to_sym).line line
2549
+ result = wrap :lvar, val[0]
2554
2550
  }
2555
2551
 
2556
2552
  p_var_ref: tCARET tIDENTIFIER
2557
2553
  {
2558
- _, (id, line) = val
2559
-
2560
2554
  # TODO: check id against env for lvar or dvar
2561
-
2562
- result = s(:lvar, id.to_sym).line line
2555
+ result = wrap :lvar, val[1]
2563
2556
  }
2564
2557
 
2565
2558
  p_const: tCOLON3 cname
2566
2559
  {
2567
- _, (id, line) = val
2568
- result = s(:colon3, id.to_sym).line line
2560
+ result = wrap :colon3, val[1]
2569
2561
  }
2570
2562
  | p_const tCOLON2 cname
2571
2563
  {
@@ -2577,8 +2569,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2577
2569
  | tCONSTANT
2578
2570
  {
2579
2571
  # TODO $$ = gettable(p, $1, &@$);
2580
- (id, line), = val
2581
- result = s(:const, id.to_sym).line line
2572
+ result = wrap :const, val[0]
2582
2573
  }
2583
2574
  ######################################################################
2584
2575
  #endif
@@ -2865,18 +2856,15 @@ regexp_contents: none
2865
2856
 
2866
2857
  string_dvar: tGVAR
2867
2858
  {
2868
- (id, line), = val
2869
- result = s(:gvar, id.to_sym).line line
2859
+ result = wrap :gvar, val[0]
2870
2860
  }
2871
2861
  | tIVAR
2872
2862
  {
2873
- (id, line), = val
2874
- result = s(:ivar, id.to_sym).line line
2863
+ result = wrap :ivar, val[0]
2875
2864
  }
2876
2865
  | tCVAR
2877
2866
  {
2878
- (id, line), = val
2879
- result = s(:cvar, id.to_sym).line line
2867
+ result = wrap :cvar, val[0]
2880
2868
  }
2881
2869
  | backref
2882
2870
 
@@ -2885,17 +2873,13 @@ regexp_contents: none
2885
2873
 
2886
2874
  ssym: tSYMBEG sym
2887
2875
  {
2888
- _, (id, line) = val
2889
-
2890
2876
  lexer.lex_state = EXPR_END
2891
- result = s(:lit, id.to_sym).line line
2877
+ result = wrap :lit, val[1]
2892
2878
  }
2893
2879
  | tSYMBOL
2894
2880
  {
2895
- (id, line), = val
2896
-
2897
2881
  lexer.lex_state = EXPR_END
2898
- result = s(:lit, id.to_sym).line line
2882
+ result = wrap :lit, val[0]
2899
2883
  }
2900
2884
 
2901
2885
  sym: fname | tIVAR | tGVAR | tCVAR
@@ -3416,10 +3400,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3416
3400
  }
3417
3401
  | tLABEL arg_value
3418
3402
  {
3419
- (label, line), arg = val
3403
+ label, arg = val
3420
3404
 
3421
- lit = s(:lit, label.to_sym).line line
3422
- result = s(:array, lit, arg).line line
3405
+ lit = wrap :lit, label
3406
+ result = s(:array, lit, arg).line lit.line
3423
3407
  }
3424
3408
  #if V >= 22
3425
3409
  | tSTRING_BEG string_contents tLABEL_END arg_value
@@ -30,7 +30,7 @@ class Sexp
30
30
  end
31
31
 
32
32
  module RubyParserStuff
33
- VERSION = "3.18.0"
33
+ VERSION = "3.19.1"
34
34
 
35
35
  attr_accessor :lexer, :in_def, :in_single, :file
36
36
  attr_accessor :in_kwarg
@@ -218,11 +218,15 @@ module RubyParserStuff
218
218
  self.args args
219
219
  end
220
220
 
221
+ def attrset_id? id
222
+ id =~ /^\[\]=$|^\w+=$/
223
+ end
224
+
221
225
  def endless_method_name defn_or_defs
222
226
  name = defn_or_defs[1]
223
227
  name = defn_or_defs[2] unless Symbol === name
224
228
 
225
- if name.end_with? "=" then
229
+ if attrset_id? name then
226
230
  yyerror "setter method cannot be defined in an endless method definition"
227
231
  end
228
232
 
@@ -978,6 +982,49 @@ module RubyParserStuff
978
982
  [result, in_def]
979
983
  end
980
984
 
985
+ def new_endless_defn val
986
+ (name, line, in_def), args, _, body, _, resbody = val
987
+
988
+ result =
989
+ if resbody then
990
+ s(:defn, name, args,
991
+ new_rescue(body,
992
+ new_resbody(s(:array).line(line),
993
+ resbody))).line line
994
+ else
995
+ s(:defn, name, args, body).line line
996
+ end
997
+
998
+ local_pop in_def
999
+ endless_method_name result
1000
+
1001
+ result.comments = self.comments.pop
1002
+
1003
+ result
1004
+ end
1005
+
1006
+ def new_endless_defs val
1007
+ (recv, (name, line, in_def)), args, _, body, _, resbody = val
1008
+
1009
+ result =
1010
+ if resbody then
1011
+ s(:defs, recv, name, args,
1012
+ new_rescue(body,
1013
+ new_resbody(s(:array).line(line),
1014
+ resbody))).line line
1015
+ else
1016
+ s(:defs, recv, name, args, body).line(line)
1017
+ end
1018
+
1019
+ self.in_single -= 1
1020
+ local_pop in_def
1021
+ endless_method_name result
1022
+
1023
+ result.comments = self.comments.pop
1024
+
1025
+ result
1026
+ end
1027
+
981
1028
  def new_defs val
982
1029
  _, recv, (name, line), in_def, args, body, _ = val
983
1030
 
@@ -1613,6 +1660,12 @@ module RubyParserStuff
1613
1660
 
1614
1661
  alias remove_whitespace_width whitespace_width
1615
1662
 
1663
+ def wrap type, node
1664
+ value, line = node
1665
+ value = value.to_sym if value.respond_to? :to_sym
1666
+ s(type, value).line line
1667
+ end
1668
+
1616
1669
  class Keyword
1617
1670
  include RubyLexer::State::Values
1618
1671