ruby_parser 3.20.1 → 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/ruby32_parser.y CHANGED
@@ -96,9 +96,9 @@ rule
96
96
  result = iter
97
97
  }
98
98
 
99
- begin_block: tLCURLY { result = lexer.lineno } top_compstmt tRCURLY
99
+ begin_block: tLCURLY top_compstmt tRCURLY
100
100
  {
101
- _, line, stmt, _ = val
101
+ (_, line), stmt, _ = val
102
102
  result = new_iter s(:preexe).line(line), 0, stmt
103
103
  }
104
104
 
@@ -621,7 +621,7 @@ rule
621
621
  }
622
622
  | tSTAR
623
623
  {
624
- l = lexer.lineno
624
+ (_, l), = val
625
625
  result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
626
626
  }
627
627
  | tSTAR tCOMMA mlhs_post
@@ -1251,7 +1251,7 @@ rule
1251
1251
  args: arg_value
1252
1252
  {
1253
1253
  arg, = val
1254
- lineno = arg.line || lexer.lineno # HACK
1254
+ lineno = arg.line
1255
1255
 
1256
1256
  result = s(:array, arg).line lineno
1257
1257
  }
@@ -1260,6 +1260,11 @@ rule
1260
1260
  _, arg = val
1261
1261
  result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1262
1262
  }
1263
+ | tSTAR
1264
+ {
1265
+ (_, line), = val
1266
+ result = s(:array, s(:splat).line(line)).line line
1267
+ }
1263
1268
  | args tCOMMA arg_value
1264
1269
  {
1265
1270
  args, _, id = val
@@ -1267,11 +1272,14 @@ rule
1267
1272
  }
1268
1273
  | args tCOMMA tSTAR arg_value
1269
1274
  {
1270
- # TODO: the line number from tSTAR has been dropped
1271
- args, _, _, id = val
1272
- line = lexer.lineno
1275
+ args, _, (_, line), id = val
1273
1276
  result = self.list_append args, s(:splat, id).line(line)
1274
1277
  }
1278
+ | args tCOMMA tSTAR
1279
+ {
1280
+ args, _, (_, line) = val
1281
+ result = self.list_append args, s(:splat).line(line)
1282
+ }
1275
1283
 
1276
1284
  mrhs_arg: mrhs
1277
1285
  {
@@ -1288,7 +1296,6 @@ rule
1288
1296
  }
1289
1297
  | args tCOMMA tSTAR arg_value
1290
1298
  {
1291
- # TODO: make all tXXXX terminals include lexer.lineno
1292
1299
  arg, _, _, splat = val
1293
1300
  result = self.arg_concat arg, splat
1294
1301
  }
@@ -1317,7 +1324,6 @@ rule
1317
1324
  | k_begin
1318
1325
  {
1319
1326
  lexer.cmdarg.push false
1320
- result = self.lexer.lineno
1321
1327
  }
1322
1328
  bodystmt k_end
1323
1329
  {
@@ -1327,11 +1333,10 @@ rule
1327
1333
  | tLPAREN_ARG
1328
1334
  {
1329
1335
  lexer.lex_state = EXPR_ENDARG
1330
- result = lexer.lineno
1331
1336
  }
1332
1337
  rparen
1333
1338
  {
1334
- _, line, _ = val
1339
+ (_, line), _, _ = val
1335
1340
  result = s(:begin).line line
1336
1341
  }
1337
1342
  | tLPAREN_ARG
@@ -1347,9 +1352,8 @@ rule
1347
1352
  }
1348
1353
  | tLPAREN compstmt tRPAREN
1349
1354
  {
1350
- _, stmt, _ = val
1351
- result = stmt
1352
- result ||= s(:nil).line lexer.lineno
1355
+ (_, line), stmt, _ = val
1356
+ result = stmt || s(:nil).line(line)
1353
1357
  result.paren = true
1354
1358
  }
1355
1359
  | primary_value tCOLON2 tCONSTANT
@@ -1362,9 +1366,9 @@ rule
1362
1366
  {
1363
1367
  result = wrap :colon3, val[1]
1364
1368
  }
1365
- | tLBRACK { result = lexer.lineno } aref_args rbracket
1369
+ | tLBRACK aref_args rbracket
1366
1370
  {
1367
- _, line, args, (_, line_max) = val
1371
+ (_, line), args, (_, line_max) = val
1368
1372
 
1369
1373
  result = args || s(:array)
1370
1374
  result.sexp_type = :array # aref_args is :args
@@ -1480,9 +1484,6 @@ rule
1480
1484
  result = new_for iter, var, body
1481
1485
  }
1482
1486
  | k_class
1483
- {
1484
- result = self.lexer.lineno
1485
- }
1486
1487
  cpath superclass
1487
1488
  {
1488
1489
  if (self.in_def || self.in_single > 0) then
@@ -1497,9 +1498,6 @@ rule
1497
1498
  self.lexer.ignore_body_comments
1498
1499
  }
1499
1500
  | k_class tLSHFT
1500
- {
1501
- result = self.lexer.lineno
1502
- }
1503
1501
  expr
1504
1502
  {
1505
1503
  result = self.in_def
@@ -1511,16 +1509,14 @@ rule
1511
1509
  self.in_single = 0
1512
1510
  self.env.extend
1513
1511
  }
1514
- bodystmt k_end
1512
+ bodystmt
1513
+ k_end
1515
1514
  {
1516
1515
  result = new_sclass val
1517
1516
  self.env.unextend
1518
1517
  self.lexer.ignore_body_comments
1519
1518
  }
1520
1519
  | k_module
1521
- {
1522
- result = self.lexer.lineno
1523
- }
1524
1520
  cpath
1525
1521
  {
1526
1522
  yyerror "module definition in method body" if
@@ -1662,20 +1658,33 @@ rule
1662
1658
  }
1663
1659
 
1664
1660
  f_marg: f_norm_arg
1661
+ {
1662
+ (sym, line), = val
1663
+
1664
+ result = s(:dummy, sym).line line
1665
+ }
1665
1666
  | tLPAREN f_margs rparen
1666
1667
  {
1667
- result = val[1]
1668
+ _, args, _ = val
1669
+ result = args
1668
1670
  }
1669
1671
 
1670
1672
  f_marg_list: f_marg
1671
1673
  {
1672
- sym, = val
1674
+ arg, = val
1675
+ line = arg.line
1676
+
1677
+ arg = arg.last if arg.sexp_type == :dummy
1673
1678
 
1674
- result = s(:array, sym).line lexer.lineno
1679
+ result = s(:array, arg).line line
1675
1680
  }
1676
1681
  | f_marg_list tCOMMA f_marg
1677
1682
  {
1678
- result = list_append val[0], val[2]
1683
+ args, _, arg = val
1684
+
1685
+ arg = arg.last if arg.sexp_type == :dummy
1686
+
1687
+ result = list_append args, arg
1679
1688
  }
1680
1689
 
1681
1690
  f_margs: f_marg_list
@@ -1718,8 +1727,8 @@ rule
1718
1727
  }
1719
1728
  | tSTAR
1720
1729
  {
1721
- result = args [:*]
1722
- result.line lexer.lineno # FIX: tSTAR -> line
1730
+ (_, line), = val
1731
+ result = args([:*]).line line
1723
1732
  }
1724
1733
 
1725
1734
  f_any_kwrest: f_kwrest
@@ -1832,7 +1841,9 @@ opt_block_args_tail: tCOMMA block_args_tail
1832
1841
  }
1833
1842
  | tOROP
1834
1843
  {
1835
- result = s(:args).line lexer.lineno
1844
+ (_, line), = val
1845
+
1846
+ result = s(:args).line line
1836
1847
  }
1837
1848
  | tPIPE block_param opt_bv_decl tPIPE
1838
1849
  {
@@ -1864,7 +1875,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1864
1875
  lambda: tLAMBDA
1865
1876
  {
1866
1877
  self.env.extend :dynamic
1867
- result = [lexer.lineno, lexer.lpar_beg]
1878
+ result = lexer.lpar_beg
1868
1879
  lexer.paren_nest += 1
1869
1880
  lexer.lpar_beg = lexer.paren_nest
1870
1881
  }
@@ -1874,7 +1885,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1874
1885
  }
1875
1886
  lambda_body
1876
1887
  {
1877
- _, (line, lpar), args, _cmdarg, body = val
1888
+ (_, line), lpar, args, _cmdarg, body = val
1878
1889
  lexer.lpar_beg = lpar
1879
1890
 
1880
1891
  lexer.cmdarg.pop
@@ -1998,7 +2009,8 @@ opt_block_args_tail: tCOMMA block_args_tail
1998
2009
  }
1999
2010
  | kSUPER
2000
2011
  {
2001
- result = s(:zsuper).line lexer.lineno
2012
+ (_, line), = val
2013
+ result = s(:zsuper).line line
2002
2014
  }
2003
2015
  | primary_value tLBRACK2 opt_call_args rbracket
2004
2016
  {
@@ -2008,11 +2020,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2008
2020
  brace_block: tLCURLY
2009
2021
  {
2010
2022
  self.env.extend :dynamic
2011
- result = self.lexer.lineno
2012
2023
  }
2013
- brace_body tRCURLY
2024
+ brace_body
2025
+ tRCURLY
2014
2026
  {
2015
- _, line, body, _ = val
2027
+ (_, line), _, body, _ = val
2016
2028
 
2017
2029
  result = body
2018
2030
  result.line line
@@ -2022,11 +2034,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2022
2034
  | k_do
2023
2035
  {
2024
2036
  self.env.extend :dynamic
2025
- result = self.lexer.lineno
2026
2037
  }
2027
- do_body kEND
2038
+ do_body
2039
+ kEND
2028
2040
  {
2029
- _, line, body, _ = val
2041
+ (_, line), _, body, _ = val
2030
2042
 
2031
2043
  result = body
2032
2044
  result.line line
@@ -2084,14 +2096,13 @@ opt_block_args_tail: tCOMMA block_args_tail
2084
2096
  }
2085
2097
 
2086
2098
  case_body: k_when
2087
- {
2088
- result = self.lexer.lineno
2089
- }
2090
2099
  case_args then compstmt cases
2091
2100
  {
2092
- result = new_when(val[2], val[4])
2093
- result.line val[1]
2094
- result << val[5] if val[5]
2101
+ (_, line), case_args, _then, body, cases = val
2102
+
2103
+ result = new_when case_args, body
2104
+ result.line line
2105
+ result << cases if cases
2095
2106
  }
2096
2107
 
2097
2108
  cases: opt_else | case_body
@@ -2328,31 +2339,17 @@ opt_block_args_tail: tCOMMA block_args_tail
2328
2339
  result = new_array_pattern_tail both, nil, nil, nil
2329
2340
  result.line head.line
2330
2341
  }
2331
- | p_args_head tSTAR tIDENTIFIER
2332
- {
2333
- head, _, (id, _line) = val
2334
-
2335
- result = new_array_pattern_tail head, true, id.to_sym, nil
2336
- result.line head.line
2337
- }
2338
- | p_args_head tSTAR tIDENTIFIER tCOMMA p_args_post
2342
+ | p_args_head p_rest
2339
2343
  {
2340
- head, _, (id, _line), _, post = val
2344
+ head, (rest, _) = val
2341
2345
 
2342
- result = new_array_pattern_tail head, true, id.to_sym, post
2343
- result.line head.line
2346
+ result = new_array_pattern_tail(head, true, rest, nil).line head.line
2344
2347
  }
2345
- | p_args_head tSTAR
2348
+ | p_args_head p_rest tCOMMA p_args_post
2346
2349
  {
2347
- expr, _ = val
2350
+ head, (rest, _), _, post = val
2348
2351
 
2349
- result = new_array_pattern_tail(expr, true, nil, nil).line expr.line
2350
- }
2351
- | p_args_head tSTAR tCOMMA p_args_post
2352
- {
2353
- head, _, _, post = val
2354
-
2355
- result = new_array_pattern_tail(head, true, nil, post).line head.line
2352
+ result = new_array_pattern_tail(head, true, rest, post).line head.line
2356
2353
  }
2357
2354
  | p_args_tail
2358
2355
 
@@ -2882,7 +2879,6 @@ regexp_contents: none
2882
2879
  lexer.brace_nest,
2883
2880
  lexer.string_nest, # TODO: remove
2884
2881
  lexer.lex_state,
2885
- lexer.lineno,
2886
2882
  ]
2887
2883
 
2888
2884
  lexer.cmdarg.push false
@@ -2897,9 +2893,9 @@ regexp_contents: none
2897
2893
  compstmt
2898
2894
  tSTRING_DEND
2899
2895
  {
2900
- _, memo, stmt, _ = val
2896
+ (_, line), memo, stmt, _ = val
2901
2897
 
2902
- lex_strterm, brace_nest, string_nest, oldlex_state, line = memo
2898
+ lex_strterm, brace_nest, string_nest, oldlex_state = memo
2903
2899
  # TODO: heredoc_indent
2904
2900
 
2905
2901
  lexer.lex_strterm = lex_strterm
@@ -2959,11 +2955,11 @@ regexp_contents: none
2959
2955
 
2960
2956
  dsym: tSYMBEG string_contents tSTRING_END
2961
2957
  {
2962
- _, result, _ = val
2958
+ (_, line), result, _ = val
2963
2959
 
2964
2960
  lexer.lex_state = EXPR_END
2965
2961
 
2966
- result ||= s(:str, "").line lexer.lineno
2962
+ result ||= s(:str, "").line line
2967
2963
 
2968
2964
  case result.sexp_type
2969
2965
  when :dstr then
@@ -2999,15 +2995,15 @@ regexp_contents: none
2999
2995
  | tCONSTANT
3000
2996
  | tCVAR
3001
2997
 
3002
- keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3003
- | kSELF { result = s(:self).line lexer.lineno }
3004
- | kTRUE { result = s(:true).line lexer.lineno }
3005
- | kFALSE { result = s(:false).line lexer.lineno }
3006
- | k__FILE__ { result = s(:str, self.file).line lexer.lineno }
3007
- | k__LINE__ { result = s(:lit, lexer.lineno).line lexer.lineno }
2998
+ keyword_variable: kNIL { (_, line), = val; result = s(:nil).line line }
2999
+ | kSELF { (_, line), = val; result = s(:self).line line }
3000
+ | kTRUE { (_, line), = val; result = s(:true).line line }
3001
+ | kFALSE { (_, line), = val; result = s(:false).line line }
3002
+ | k__FILE__ { (_, line), = val; result = s(:str, self.file).line line }
3003
+ | k__LINE__ { (_, line), = val; result = s(:lit, line).line line }
3008
3004
  | k__ENCODING__
3009
3005
  {
3010
- l = lexer.lineno
3006
+ (_, l), = val
3011
3007
  result =
3012
3008
  if defined? Encoding then
3013
3009
  s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
@@ -3170,12 +3166,12 @@ f_opt_paren_args: f_paren_args
3170
3166
  |
3171
3167
  {
3172
3168
  result = args val
3173
- # result.line lexer.lineno
3174
3169
  }
3175
3170
 
3176
3171
  args_forward: tBDOT3
3177
3172
  {
3178
- result = s(:forward_args).line lexer.lineno
3173
+ (_, line), = val
3174
+ result = s(:forward_args).line line
3179
3175
  }
3180
3176
 
3181
3177
  f_bad_arg: tCONSTANT
@@ -3313,9 +3309,10 @@ f_opt_paren_args: f_paren_args
3313
3309
  }
3314
3310
  | kwrest_mark
3315
3311
  {
3312
+ (_, line), = val
3316
3313
  id = :"**"
3317
- self.env[id] = :lvar # TODO: needed?!?
3318
- result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3314
+ self.env[id] = :lvar
3315
+ result = [id, line]
3319
3316
  }
3320
3317
 
3321
3318
  f_opt: f_arg_asgn
@@ -3373,9 +3370,10 @@ f_opt_paren_args: f_paren_args
3373
3370
  }
3374
3371
  | restarg_mark
3375
3372
  {
3373
+ (_, line), = val
3376
3374
  name = :"*"
3377
3375
  self.env[name] = :lvar
3378
- result = [name, lexer.lineno] # FIX: tSTAR to include lineno
3376
+ result = [name, line]
3379
3377
  }
3380
3378
 
3381
3379
  blkarg_mark: tAMPER2 | tAMPER
@@ -3466,6 +3464,11 @@ f_opt_paren_args: f_paren_args
3466
3464
  line = arg.line
3467
3465
  result = s(:array, s(:kwsplat, arg).line(line)).line line
3468
3466
  }
3467
+ | tDSTAR
3468
+ {
3469
+ (_, line), = val
3470
+ result = s(:array, s(:kwsplat).line(line)).line line
3471
+ }
3469
3472
 
3470
3473
  operation: tIDENTIFIER | tCONSTANT | tFID
3471
3474
  operation2: tIDENTIFIER | tCONSTANT | tFID | op
@@ -3480,11 +3483,10 @@ f_opt_paren_args: f_paren_args
3480
3483
  opt_terms: | terms
3481
3484
  opt_nl: | tNL
3482
3485
  rparen: opt_nl tRPAREN
3483
- # TODO:
3484
- # {
3485
- # _, close = val
3486
- # result = [close, lexer.lineno]
3487
- # }
3486
+ {
3487
+ _, close = val # TODO: include lineno in close?
3488
+ result = [close, lexer.lineno]
3489
+ }
3488
3490
  rbracket: opt_nl tRBRACK
3489
3491
  {
3490
3492
  _, close = val