ruby_parser 3.20.0 → 3.20.2

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/ruby3_parser.yy CHANGED
@@ -104,9 +104,9 @@ rule
104
104
  result = iter
105
105
  }
106
106
 
107
- begin_block: tLCURLY { result = lexer.lineno } top_compstmt tRCURLY
107
+ begin_block: tLCURLY top_compstmt tRCURLY
108
108
  {
109
- _, line, stmt, _ = val
109
+ (_, line), stmt, _ = val
110
110
  result = new_iter s(:preexe).line(line), 0, stmt
111
111
  }
112
112
 
@@ -229,6 +229,7 @@ rule
229
229
  | lhs tEQL mrhs
230
230
  {
231
231
  lhs, _, rhs = val
232
+
232
233
  result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
233
234
  }
234
235
  | mlhs tEQL mrhs_arg kRESCUE_MOD stmt
@@ -638,7 +639,7 @@ rule
638
639
  }
639
640
  | tSTAR
640
641
  {
641
- l = lexer.lineno
642
+ (_, l), = val
642
643
  result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
643
644
  }
644
645
  | tSTAR tCOMMA mlhs_post
@@ -1148,8 +1149,10 @@ rule
1148
1149
 
1149
1150
  paren_args: tLPAREN2 opt_call_args rparen
1150
1151
  {
1151
- _, args, _ = val
1152
+ _, args, (_, line_max) = val
1153
+
1152
1154
  result = args
1155
+ result.line_max = line_max if args
1153
1156
  }
1154
1157
  | tLPAREN2 args tCOMMA args_forward rparen
1155
1158
  {
@@ -1268,7 +1271,7 @@ rule
1268
1271
  args: arg_value
1269
1272
  {
1270
1273
  arg, = val
1271
- lineno = arg.line || lexer.lineno # HACK
1274
+ lineno = arg.line
1272
1275
 
1273
1276
  result = s(:array, arg).line lineno
1274
1277
  }
@@ -1277,6 +1280,13 @@ rule
1277
1280
  _, arg = val
1278
1281
  result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1279
1282
  }
1283
+ #if V >= 32
1284
+ | tSTAR
1285
+ {
1286
+ (_, line), = val
1287
+ result = s(:array, s(:splat).line(line)).line line
1288
+ }
1289
+ #endif
1280
1290
  | args tCOMMA arg_value
1281
1291
  {
1282
1292
  args, _, id = val
@@ -1284,11 +1294,16 @@ rule
1284
1294
  }
1285
1295
  | args tCOMMA tSTAR arg_value
1286
1296
  {
1287
- # TODO: the line number from tSTAR has been dropped
1288
- args, _, _, id = val
1289
- line = lexer.lineno
1297
+ args, _, (_, line), id = val
1290
1298
  result = self.list_append args, s(:splat, id).line(line)
1291
1299
  }
1300
+ #if V >= 32
1301
+ | args tCOMMA tSTAR
1302
+ {
1303
+ args, _, (_, line) = val
1304
+ result = self.list_append args, s(:splat).line(line)
1305
+ }
1306
+ #endif
1292
1307
 
1293
1308
  mrhs_arg: mrhs
1294
1309
  {
@@ -1305,7 +1320,6 @@ rule
1305
1320
  }
1306
1321
  | args tCOMMA tSTAR arg_value
1307
1322
  {
1308
- # TODO: make all tXXXX terminals include lexer.lineno
1309
1323
  arg, _, _, splat = val
1310
1324
  result = self.arg_concat arg, splat
1311
1325
  }
@@ -1334,7 +1348,6 @@ rule
1334
1348
  | k_begin
1335
1349
  {
1336
1350
  lexer.cmdarg.push false
1337
- result = self.lexer.lineno
1338
1351
  }
1339
1352
  bodystmt k_end
1340
1353
  {
@@ -1344,11 +1357,10 @@ rule
1344
1357
  | tLPAREN_ARG
1345
1358
  {
1346
1359
  lexer.lex_state = EXPR_ENDARG
1347
- result = lexer.lineno
1348
1360
  }
1349
1361
  rparen
1350
1362
  {
1351
- _, line, _ = val
1363
+ (_, line), _, _ = val
1352
1364
  result = s(:begin).line line
1353
1365
  }
1354
1366
  | tLPAREN_ARG
@@ -1364,9 +1376,8 @@ rule
1364
1376
  }
1365
1377
  | tLPAREN compstmt tRPAREN
1366
1378
  {
1367
- _, stmt, _ = val
1368
- result = stmt
1369
- result ||= s(:nil).line lexer.lineno
1379
+ (_, line), stmt, _ = val
1380
+ result = stmt || s(:nil).line(line)
1370
1381
  result.paren = true
1371
1382
  }
1372
1383
  | primary_value tCOLON2 tCONSTANT
@@ -1379,12 +1390,14 @@ rule
1379
1390
  {
1380
1391
  result = wrap :colon3, val[1]
1381
1392
  }
1382
- | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1393
+ | tLBRACK aref_args rbracket
1383
1394
  {
1384
- _, line, args, _ = val
1395
+ (_, line), args, (_, line_max) = val
1396
+
1385
1397
  result = args || s(:array)
1386
1398
  result.sexp_type = :array # aref_args is :args
1387
1399
  result.line line
1400
+ result.line_max = line_max
1388
1401
  }
1389
1402
  | tLBRACE
1390
1403
  {
@@ -1495,9 +1508,6 @@ rule
1495
1508
  result = new_for iter, var, body
1496
1509
  }
1497
1510
  | k_class
1498
- {
1499
- result = self.lexer.lineno
1500
- }
1501
1511
  cpath superclass
1502
1512
  {
1503
1513
  if (self.in_def || self.in_single > 0) then
@@ -1512,9 +1522,6 @@ rule
1512
1522
  self.lexer.ignore_body_comments
1513
1523
  }
1514
1524
  | k_class tLSHFT
1515
- {
1516
- result = self.lexer.lineno
1517
- }
1518
1525
  expr
1519
1526
  {
1520
1527
  result = self.in_def
@@ -1526,16 +1533,14 @@ rule
1526
1533
  self.in_single = 0
1527
1534
  self.env.extend
1528
1535
  }
1529
- bodystmt k_end
1536
+ bodystmt
1537
+ k_end
1530
1538
  {
1531
1539
  result = new_sclass val
1532
1540
  self.env.unextend
1533
1541
  self.lexer.ignore_body_comments
1534
1542
  }
1535
1543
  | k_module
1536
- {
1537
- result = self.lexer.lineno
1538
- }
1539
1544
  cpath
1540
1545
  {
1541
1546
  yyerror "module definition in method body" if
@@ -1677,20 +1682,33 @@ rule
1677
1682
  }
1678
1683
 
1679
1684
  f_marg: f_norm_arg
1685
+ {
1686
+ (sym, line), = val
1687
+
1688
+ result = s(:dummy, sym).line line
1689
+ }
1680
1690
  | tLPAREN f_margs rparen
1681
1691
  {
1682
- result = val[1]
1692
+ _, args, _ = val
1693
+ result = args
1683
1694
  }
1684
1695
 
1685
1696
  f_marg_list: f_marg
1686
1697
  {
1687
- sym, = val
1698
+ arg, = val
1699
+ line = arg.line
1700
+
1701
+ arg = arg.last if arg.sexp_type == :dummy
1688
1702
 
1689
- result = s(:array, sym).line lexer.lineno
1703
+ result = s(:array, arg).line line
1690
1704
  }
1691
1705
  | f_marg_list tCOMMA f_marg
1692
1706
  {
1693
- result = list_append val[0], val[2]
1707
+ args, _, arg = val
1708
+
1709
+ arg = arg.last if arg.sexp_type == :dummy
1710
+
1711
+ result = list_append args, arg
1694
1712
  }
1695
1713
 
1696
1714
  f_margs: f_marg_list
@@ -1733,8 +1751,8 @@ rule
1733
1751
  }
1734
1752
  | tSTAR
1735
1753
  {
1736
- result = args [:*]
1737
- result.line lexer.lineno # FIX: tSTAR -> line
1754
+ (_, line), = val
1755
+ result = args([:*]).line line
1738
1756
  }
1739
1757
 
1740
1758
  f_any_kwrest: f_kwrest
@@ -1849,7 +1867,9 @@ opt_block_args_tail: tCOMMA block_args_tail
1849
1867
  }
1850
1868
  | tOROP
1851
1869
  {
1852
- result = s(:args).line lexer.lineno
1870
+ (_, line), = val
1871
+
1872
+ result = s(:args).line line
1853
1873
  }
1854
1874
  | tPIPE block_param opt_bv_decl tPIPE
1855
1875
  {
@@ -1881,7 +1901,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1881
1901
  lambda: tLAMBDA
1882
1902
  {
1883
1903
  self.env.extend :dynamic
1884
- result = [lexer.lineno, lexer.lpar_beg]
1904
+ result = lexer.lpar_beg
1885
1905
  lexer.paren_nest += 1
1886
1906
  lexer.lpar_beg = lexer.paren_nest
1887
1907
  }
@@ -1891,7 +1911,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1891
1911
  }
1892
1912
  lambda_body
1893
1913
  {
1894
- _, (line, lpar), args, _cmdarg, body = val
1914
+ (_, line), lpar, args, _cmdarg, body = val
1895
1915
  lexer.lpar_beg = lpar
1896
1916
 
1897
1917
  lexer.cmdarg.pop
@@ -1975,13 +1995,19 @@ opt_block_args_tail: tCOMMA block_args_tail
1975
1995
  {
1976
1996
  call, args = val
1977
1997
 
1978
- result = call.concat args.sexp_body if args
1998
+ result = call
1999
+
2000
+ if args then
2001
+ call.concat args.sexp_body
2002
+ result.line_max = args.line_max
2003
+ end
1979
2004
  }
1980
2005
  | primary_value call_op operation2 opt_paren_args
1981
2006
  {
1982
- recv, call_op, (op, _line), args = val
2007
+ recv, call_op, (op, op_line), args = val
1983
2008
 
1984
2009
  result = new_call recv, op.to_sym, args, call_op
2010
+ result.line_max = op_line unless args
1985
2011
  }
1986
2012
  | primary_value tCOLON2 operation2 paren_args
1987
2013
  {
@@ -2009,7 +2035,8 @@ opt_block_args_tail: tCOMMA block_args_tail
2009
2035
  }
2010
2036
  | kSUPER
2011
2037
  {
2012
- result = s(:zsuper).line lexer.lineno
2038
+ (_, line), = val
2039
+ result = s(:zsuper).line line
2013
2040
  }
2014
2041
  | primary_value tLBRACK2 opt_call_args rbracket
2015
2042
  {
@@ -2019,11 +2046,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2019
2046
  brace_block: tLCURLY
2020
2047
  {
2021
2048
  self.env.extend :dynamic
2022
- result = self.lexer.lineno
2023
2049
  }
2024
- brace_body tRCURLY
2050
+ brace_body
2051
+ tRCURLY
2025
2052
  {
2026
- _, line, body, _ = val
2053
+ (_, line), _, body, _ = val
2027
2054
 
2028
2055
  result = body
2029
2056
  result.line line
@@ -2033,11 +2060,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2033
2060
  | k_do
2034
2061
  {
2035
2062
  self.env.extend :dynamic
2036
- result = self.lexer.lineno
2037
2063
  }
2038
- do_body kEND
2064
+ do_body
2065
+ kEND
2039
2066
  {
2040
- _, line, body, _ = val
2067
+ (_, line), _, body, _ = val
2041
2068
 
2042
2069
  result = body
2043
2070
  result.line line
@@ -2095,14 +2122,13 @@ opt_block_args_tail: tCOMMA block_args_tail
2095
2122
  }
2096
2123
 
2097
2124
  case_body: k_when
2098
- {
2099
- result = self.lexer.lineno
2100
- }
2101
2125
  case_args then compstmt cases
2102
2126
  {
2103
- result = new_when(val[2], val[4])
2104
- result.line val[1]
2105
- result << val[5] if val[5]
2127
+ (_, line), case_args, _then, body, cases = val
2128
+
2129
+ result = new_when case_args, body
2130
+ result.line line
2131
+ result << cases if cases
2106
2132
  }
2107
2133
 
2108
2134
  cases: opt_else | case_body
@@ -2341,6 +2367,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2341
2367
  result = new_array_pattern_tail both, nil, nil, nil
2342
2368
  result.line head.line
2343
2369
  }
2370
+ #if V < 32
2344
2371
  | p_args_head tSTAR tIDENTIFIER
2345
2372
  {
2346
2373
  head, _, (id, _line) = val
@@ -2367,6 +2394,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2367
2394
 
2368
2395
  result = new_array_pattern_tail(head, true, nil, post).line head.line
2369
2396
  }
2397
+ #else
2398
+ | p_args_head p_rest
2399
+ {
2400
+ head, (rest, _) = val
2401
+
2402
+ result = new_array_pattern_tail(head, true, rest, nil).line head.line
2403
+ }
2404
+ | p_args_head p_rest tCOMMA p_args_post
2405
+ {
2406
+ head, (rest, _), _, post = val
2407
+
2408
+ result = new_array_pattern_tail(head, true, rest, post).line head.line
2409
+ }
2410
+ #endif
2370
2411
  | p_args_tail
2371
2412
 
2372
2413
  p_args_head: p_arg tCOMMA
@@ -2751,15 +2792,17 @@ opt_block_args_tail: tCOMMA block_args_tail
2751
2792
 
2752
2793
  words: tWORDS_BEG tSPACE tSTRING_END
2753
2794
  {
2754
- (_, line), _, _ = val
2795
+ (_, line), _, (_, line_max) = val
2755
2796
 
2756
2797
  result = s(:array).line line
2798
+ result.line_max = line_max
2757
2799
  }
2758
2800
  | tWORDS_BEG word_list tSTRING_END
2759
2801
  {
2760
- (_, line), list, _ = val
2802
+ (_, line), list, (_, line_max) = val
2761
2803
 
2762
2804
  result = list.line line
2805
+ result.line_max = line_max
2763
2806
  }
2764
2807
 
2765
2808
  word_list: none
@@ -2779,15 +2822,17 @@ opt_block_args_tail: tCOMMA block_args_tail
2779
2822
 
2780
2823
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2781
2824
  {
2782
- (_, line), _, _ = val
2825
+ (_, line), _, (_, line_max) = val
2783
2826
 
2784
2827
  result = s(:array).line line
2828
+ result.line_max = line_max
2785
2829
  }
2786
2830
  | tSYMBOLS_BEG symbol_list tSTRING_END
2787
2831
  {
2788
- (_, line), list, _, = val
2789
- list.line line
2790
- result = list
2832
+ (_, line), list, (_, line_max), = val
2833
+
2834
+ result = list.line line
2835
+ result.line_max = line_max
2791
2836
  }
2792
2837
 
2793
2838
  symbol_list: none
@@ -2802,28 +2847,32 @@ opt_block_args_tail: tCOMMA block_args_tail
2802
2847
 
2803
2848
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2804
2849
  {
2805
- (_, line), _, _ = val
2850
+ (_, line), _, (_, line_max) = val
2806
2851
 
2807
2852
  result = s(:array).line line
2853
+ result.line_max = line_max
2808
2854
  }
2809
2855
  | tQWORDS_BEG qword_list tSTRING_END
2810
2856
  {
2811
- (_, line), list, _ = val
2857
+ (_, line), list, (_, line_max) = val
2812
2858
 
2813
2859
  result = list.line line
2860
+ result.line_max = line_max
2814
2861
  }
2815
2862
 
2816
2863
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2817
2864
  {
2818
- (_, line), _, _ = val
2865
+ (_, line), _, (_, line_max) = val
2819
2866
 
2820
2867
  result = s(:array).line line
2868
+ result.line_max = line_max
2821
2869
  }
2822
2870
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2823
2871
  {
2824
- (_, line), list, _ = val
2872
+ (_, line), list, (_, line_max) = val
2825
2873
 
2826
2874
  result = list.line line
2875
+ result.line_max = line_max
2827
2876
  }
2828
2877
 
2829
2878
  qword_list: none
@@ -2898,7 +2947,6 @@ regexp_contents: none
2898
2947
  lexer.brace_nest,
2899
2948
  lexer.string_nest, # TODO: remove
2900
2949
  lexer.lex_state,
2901
- lexer.lineno,
2902
2950
  ]
2903
2951
 
2904
2952
  lexer.cmdarg.push false
@@ -2913,9 +2961,9 @@ regexp_contents: none
2913
2961
  compstmt
2914
2962
  tSTRING_DEND
2915
2963
  {
2916
- _, memo, stmt, _ = val
2964
+ (_, line), memo, stmt, _ = val
2917
2965
 
2918
- lex_strterm, brace_nest, string_nest, oldlex_state, line = memo
2966
+ lex_strterm, brace_nest, string_nest, oldlex_state = memo
2919
2967
  # TODO: heredoc_indent
2920
2968
 
2921
2969
  lexer.lex_strterm = lex_strterm
@@ -2975,11 +3023,11 @@ regexp_contents: none
2975
3023
 
2976
3024
  dsym: tSYMBEG string_contents tSTRING_END
2977
3025
  {
2978
- _, result, _ = val
3026
+ (_, line), result, _ = val
2979
3027
 
2980
3028
  lexer.lex_state = EXPR_END
2981
3029
 
2982
- result ||= s(:str, "").line lexer.lineno
3030
+ result ||= s(:str, "").line line
2983
3031
 
2984
3032
  case result.sexp_type
2985
3033
  when :dstr then
@@ -3017,15 +3065,15 @@ regexp_contents: none
3017
3065
  | tCONSTANT
3018
3066
  | tCVAR
3019
3067
 
3020
- keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3021
- | kSELF { result = s(:self).line lexer.lineno }
3022
- | kTRUE { result = s(:true).line lexer.lineno }
3023
- | kFALSE { result = s(:false).line lexer.lineno }
3024
- | k__FILE__ { result = s(:str, self.file).line lexer.lineno }
3025
- | k__LINE__ { result = s(:lit, lexer.lineno).line lexer.lineno }
3068
+ keyword_variable: kNIL { (_, line), = val; result = s(:nil).line line }
3069
+ | kSELF { (_, line), = val; result = s(:self).line line }
3070
+ | kTRUE { (_, line), = val; result = s(:true).line line }
3071
+ | kFALSE { (_, line), = val; result = s(:false).line line }
3072
+ | k__FILE__ { (_, line), = val; result = s(:str, self.file).line line }
3073
+ | k__LINE__ { (_, line), = val; result = s(:lit, line).line line }
3026
3074
  | k__ENCODING__
3027
3075
  {
3028
- l = lexer.lineno
3076
+ (_, l), = val
3029
3077
  result =
3030
3078
  if defined? Encoding then
3031
3079
  s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
@@ -3200,12 +3248,12 @@ f_opt_paren_args: f_paren_args
3200
3248
  |
3201
3249
  {
3202
3250
  result = args val
3203
- # result.line lexer.lineno
3204
3251
  }
3205
3252
 
3206
3253
  args_forward: tBDOT3
3207
3254
  {
3208
- result = s(:forward_args).line lexer.lineno
3255
+ (_, line), = val
3256
+ result = s(:forward_args).line line
3209
3257
  }
3210
3258
 
3211
3259
  f_bad_arg: tCONSTANT
@@ -3259,7 +3307,14 @@ f_opt_paren_args: f_paren_args
3259
3307
  result = s(:args, list).line list.line
3260
3308
  end
3261
3309
 
3262
- result << (Sexp === item ? item : item.first)
3310
+ if Sexp === item then
3311
+ line_max = item.line_max
3312
+ else
3313
+ item, line_max = item
3314
+ end
3315
+
3316
+ result << item
3317
+ result.line_max = line_max
3263
3318
  }
3264
3319
 
3265
3320
  f_label: tLABEL
@@ -3336,9 +3391,10 @@ f_opt_paren_args: f_paren_args
3336
3391
  }
3337
3392
  | kwrest_mark
3338
3393
  {
3394
+ (_, line), = val
3339
3395
  id = :"**"
3340
- self.env[id] = :lvar # TODO: needed?!?
3341
- result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3396
+ self.env[id] = :lvar
3397
+ result = [id, line]
3342
3398
  }
3343
3399
 
3344
3400
  f_opt: f_arg_asgn
@@ -3404,9 +3460,10 @@ f_opt_paren_args: f_paren_args
3404
3460
  }
3405
3461
  | restarg_mark
3406
3462
  {
3463
+ (_, line), = val
3407
3464
  name = :"*"
3408
3465
  self.env[name] = :lvar
3409
- result = [name, lexer.lineno] # FIX: tSTAR to include lineno
3466
+ result = [name, line]
3410
3467
  }
3411
3468
 
3412
3469
  blkarg_mark: tAMPER2 | tAMPER
@@ -3497,6 +3554,13 @@ f_opt_paren_args: f_paren_args
3497
3554
  line = arg.line
3498
3555
  result = s(:array, s(:kwsplat, arg).line(line)).line line
3499
3556
  }
3557
+ #if V >= 32
3558
+ | tDSTAR
3559
+ {
3560
+ (_, line), = val
3561
+ result = s(:array, s(:kwsplat).line(line)).line line
3562
+ }
3563
+ #endif
3500
3564
 
3501
3565
  operation: tIDENTIFIER | tCONSTANT | tFID
3502
3566
  operation2: tIDENTIFIER | tCONSTANT | tFID | op
@@ -3511,11 +3575,10 @@ f_opt_paren_args: f_paren_args
3511
3575
  opt_terms: | terms
3512
3576
  opt_nl: | tNL
3513
3577
  rparen: opt_nl tRPAREN
3514
- # TODO:
3515
- # {
3516
- # _, close = val
3517
- # result = [close, lexer.lineno]
3518
- # }
3578
+ {
3579
+ _, close = val # TODO: include lineno in close?
3580
+ result = [close, lexer.lineno]
3581
+ }
3519
3582
  rbracket: opt_nl tRBRACK
3520
3583
  {
3521
3584
  _, close = val
data/lib/ruby_lexer.rb CHANGED
@@ -271,6 +271,8 @@ class RubyLexer
271
271
  nil # TODO
272
272
  end
273
273
 
274
+ # TODO: make all tXXXX terminals include lexer.lineno ... enforce it somehow?
275
+
274
276
  def process_brace_close text
275
277
  case matched
276
278
  when "}" then
@@ -2,7 +2,7 @@
2
2
  # encoding: UTF-8
3
3
  #--
4
4
  # This file is automatically generated. Do not modify it.
5
- # Generated by: oedipus_lex version 2.6.0.
5
+ # Generated by: oedipus_lex version 2.6.1.
6
6
  # Source: lib/ruby_lexer.rex
7
7
  #++
8
8
 
@@ -56,7 +56,7 @@ class RubyLexer
56
56
  return :tSTRING_DVAR, matched
57
57
  when scan(/#[{]/) then
58
58
  self.command_start = true
59
- return :tSTRING_DBEG, matched
59
+ return :tSTRING_DBEG, [matched, lineno]
60
60
  when scan(/#/) then
61
61
  string_buffer << "#"
62
62
  end
@@ -415,7 +415,7 @@ class RubyLexer
415
415
  return :tSTRING_DVAR, matched
416
416
  when scan(/#[{]/) then
417
417
  self.command_start = true
418
- return :tSTRING_DBEG, matched
418
+ return :tSTRING_DBEG, [matched, lineno]
419
419
  when scan(/#/) then
420
420
  # do nothing but swallow
421
421
  end