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/ruby31_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
  }
@@ -1267,9 +1267,7 @@ rule
1267
1267
  }
1268
1268
  | args tCOMMA tSTAR arg_value
1269
1269
  {
1270
- # TODO: the line number from tSTAR has been dropped
1271
- args, _, _, id = val
1272
- line = lexer.lineno
1270
+ args, _, (_, line), id = val
1273
1271
  result = self.list_append args, s(:splat, id).line(line)
1274
1272
  }
1275
1273
 
@@ -1288,7 +1286,6 @@ rule
1288
1286
  }
1289
1287
  | args tCOMMA tSTAR arg_value
1290
1288
  {
1291
- # TODO: make all tXXXX terminals include lexer.lineno
1292
1289
  arg, _, _, splat = val
1293
1290
  result = self.arg_concat arg, splat
1294
1291
  }
@@ -1317,7 +1314,6 @@ rule
1317
1314
  | k_begin
1318
1315
  {
1319
1316
  lexer.cmdarg.push false
1320
- result = self.lexer.lineno
1321
1317
  }
1322
1318
  bodystmt k_end
1323
1319
  {
@@ -1327,11 +1323,10 @@ rule
1327
1323
  | tLPAREN_ARG
1328
1324
  {
1329
1325
  lexer.lex_state = EXPR_ENDARG
1330
- result = lexer.lineno
1331
1326
  }
1332
1327
  rparen
1333
1328
  {
1334
- _, line, _ = val
1329
+ (_, line), _, _ = val
1335
1330
  result = s(:begin).line line
1336
1331
  }
1337
1332
  | tLPAREN_ARG
@@ -1347,9 +1342,8 @@ rule
1347
1342
  }
1348
1343
  | tLPAREN compstmt tRPAREN
1349
1344
  {
1350
- _, stmt, _ = val
1351
- result = stmt
1352
- result ||= s(:nil).line lexer.lineno
1345
+ (_, line), stmt, _ = val
1346
+ result = stmt || s(:nil).line(line)
1353
1347
  result.paren = true
1354
1348
  }
1355
1349
  | primary_value tCOLON2 tCONSTANT
@@ -1362,9 +1356,9 @@ rule
1362
1356
  {
1363
1357
  result = wrap :colon3, val[1]
1364
1358
  }
1365
- | tLBRACK { result = lexer.lineno } aref_args rbracket
1359
+ | tLBRACK aref_args rbracket
1366
1360
  {
1367
- _, line, args, (_, line_max) = val
1361
+ (_, line), args, (_, line_max) = val
1368
1362
 
1369
1363
  result = args || s(:array)
1370
1364
  result.sexp_type = :array # aref_args is :args
@@ -1480,9 +1474,6 @@ rule
1480
1474
  result = new_for iter, var, body
1481
1475
  }
1482
1476
  | k_class
1483
- {
1484
- result = self.lexer.lineno
1485
- }
1486
1477
  cpath superclass
1487
1478
  {
1488
1479
  if (self.in_def || self.in_single > 0) then
@@ -1497,9 +1488,6 @@ rule
1497
1488
  self.lexer.ignore_body_comments
1498
1489
  }
1499
1490
  | k_class tLSHFT
1500
- {
1501
- result = self.lexer.lineno
1502
- }
1503
1491
  expr
1504
1492
  {
1505
1493
  result = self.in_def
@@ -1511,16 +1499,14 @@ rule
1511
1499
  self.in_single = 0
1512
1500
  self.env.extend
1513
1501
  }
1514
- bodystmt k_end
1502
+ bodystmt
1503
+ k_end
1515
1504
  {
1516
1505
  result = new_sclass val
1517
1506
  self.env.unextend
1518
1507
  self.lexer.ignore_body_comments
1519
1508
  }
1520
1509
  | k_module
1521
- {
1522
- result = self.lexer.lineno
1523
- }
1524
1510
  cpath
1525
1511
  {
1526
1512
  yyerror "module definition in method body" if
@@ -1662,20 +1648,33 @@ rule
1662
1648
  }
1663
1649
 
1664
1650
  f_marg: f_norm_arg
1651
+ {
1652
+ (sym, line), = val
1653
+
1654
+ result = s(:dummy, sym).line line
1655
+ }
1665
1656
  | tLPAREN f_margs rparen
1666
1657
  {
1667
- result = val[1]
1658
+ _, args, _ = val
1659
+ result = args
1668
1660
  }
1669
1661
 
1670
1662
  f_marg_list: f_marg
1671
1663
  {
1672
- sym, = val
1664
+ arg, = val
1665
+ line = arg.line
1673
1666
 
1674
- result = s(:array, sym).line lexer.lineno
1667
+ arg = arg.last if arg.sexp_type == :dummy
1668
+
1669
+ result = s(:array, arg).line line
1675
1670
  }
1676
1671
  | f_marg_list tCOMMA f_marg
1677
1672
  {
1678
- result = list_append val[0], val[2]
1673
+ args, _, arg = val
1674
+
1675
+ arg = arg.last if arg.sexp_type == :dummy
1676
+
1677
+ result = list_append args, arg
1679
1678
  }
1680
1679
 
1681
1680
  f_margs: f_marg_list
@@ -1718,8 +1717,8 @@ rule
1718
1717
  }
1719
1718
  | tSTAR
1720
1719
  {
1721
- result = args [:*]
1722
- result.line lexer.lineno # FIX: tSTAR -> line
1720
+ (_, line), = val
1721
+ result = args([:*]).line line
1723
1722
  }
1724
1723
 
1725
1724
  f_any_kwrest: f_kwrest
@@ -1832,7 +1831,9 @@ opt_block_args_tail: tCOMMA block_args_tail
1832
1831
  }
1833
1832
  | tOROP
1834
1833
  {
1835
- result = s(:args).line lexer.lineno
1834
+ (_, line), = val
1835
+
1836
+ result = s(:args).line line
1836
1837
  }
1837
1838
  | tPIPE block_param opt_bv_decl tPIPE
1838
1839
  {
@@ -1864,7 +1865,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1864
1865
  lambda: tLAMBDA
1865
1866
  {
1866
1867
  self.env.extend :dynamic
1867
- result = [lexer.lineno, lexer.lpar_beg]
1868
+ result = lexer.lpar_beg
1868
1869
  lexer.paren_nest += 1
1869
1870
  lexer.lpar_beg = lexer.paren_nest
1870
1871
  }
@@ -1874,7 +1875,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1874
1875
  }
1875
1876
  lambda_body
1876
1877
  {
1877
- _, (line, lpar), args, _cmdarg, body = val
1878
+ (_, line), lpar, args, _cmdarg, body = val
1878
1879
  lexer.lpar_beg = lpar
1879
1880
 
1880
1881
  lexer.cmdarg.pop
@@ -1998,7 +1999,8 @@ opt_block_args_tail: tCOMMA block_args_tail
1998
1999
  }
1999
2000
  | kSUPER
2000
2001
  {
2001
- result = s(:zsuper).line lexer.lineno
2002
+ (_, line), = val
2003
+ result = s(:zsuper).line line
2002
2004
  }
2003
2005
  | primary_value tLBRACK2 opt_call_args rbracket
2004
2006
  {
@@ -2008,11 +2010,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2008
2010
  brace_block: tLCURLY
2009
2011
  {
2010
2012
  self.env.extend :dynamic
2011
- result = self.lexer.lineno
2012
2013
  }
2013
- brace_body tRCURLY
2014
+ brace_body
2015
+ tRCURLY
2014
2016
  {
2015
- _, line, body, _ = val
2017
+ (_, line), _, body, _ = val
2016
2018
 
2017
2019
  result = body
2018
2020
  result.line line
@@ -2022,11 +2024,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2022
2024
  | k_do
2023
2025
  {
2024
2026
  self.env.extend :dynamic
2025
- result = self.lexer.lineno
2026
2027
  }
2027
- do_body kEND
2028
+ do_body
2029
+ kEND
2028
2030
  {
2029
- _, line, body, _ = val
2031
+ (_, line), _, body, _ = val
2030
2032
 
2031
2033
  result = body
2032
2034
  result.line line
@@ -2084,14 +2086,13 @@ opt_block_args_tail: tCOMMA block_args_tail
2084
2086
  }
2085
2087
 
2086
2088
  case_body: k_when
2087
- {
2088
- result = self.lexer.lineno
2089
- }
2090
2089
  case_args then compstmt cases
2091
2090
  {
2092
- result = new_when(val[2], val[4])
2093
- result.line val[1]
2094
- result << val[5] if val[5]
2091
+ (_, line), case_args, _then, body, cases = val
2092
+
2093
+ result = new_when case_args, body
2094
+ result.line line
2095
+ result << cases if cases
2095
2096
  }
2096
2097
 
2097
2098
  cases: opt_else | case_body
@@ -2882,7 +2883,6 @@ regexp_contents: none
2882
2883
  lexer.brace_nest,
2883
2884
  lexer.string_nest, # TODO: remove
2884
2885
  lexer.lex_state,
2885
- lexer.lineno,
2886
2886
  ]
2887
2887
 
2888
2888
  lexer.cmdarg.push false
@@ -2897,9 +2897,9 @@ regexp_contents: none
2897
2897
  compstmt
2898
2898
  tSTRING_DEND
2899
2899
  {
2900
- _, memo, stmt, _ = val
2900
+ (_, line), memo, stmt, _ = val
2901
2901
 
2902
- lex_strterm, brace_nest, string_nest, oldlex_state, line = memo
2902
+ lex_strterm, brace_nest, string_nest, oldlex_state = memo
2903
2903
  # TODO: heredoc_indent
2904
2904
 
2905
2905
  lexer.lex_strterm = lex_strterm
@@ -2959,11 +2959,11 @@ regexp_contents: none
2959
2959
 
2960
2960
  dsym: tSYMBEG string_contents tSTRING_END
2961
2961
  {
2962
- _, result, _ = val
2962
+ (_, line), result, _ = val
2963
2963
 
2964
2964
  lexer.lex_state = EXPR_END
2965
2965
 
2966
- result ||= s(:str, "").line lexer.lineno
2966
+ result ||= s(:str, "").line line
2967
2967
 
2968
2968
  case result.sexp_type
2969
2969
  when :dstr then
@@ -2999,15 +2999,15 @@ regexp_contents: none
2999
2999
  | tCONSTANT
3000
3000
  | tCVAR
3001
3001
 
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 }
3002
+ keyword_variable: kNIL { (_, line), = val; result = s(:nil).line line }
3003
+ | kSELF { (_, line), = val; result = s(:self).line line }
3004
+ | kTRUE { (_, line), = val; result = s(:true).line line }
3005
+ | kFALSE { (_, line), = val; result = s(:false).line line }
3006
+ | k__FILE__ { (_, line), = val; result = s(:str, self.file).line line }
3007
+ | k__LINE__ { (_, line), = val; result = s(:lit, line).line line }
3008
3008
  | k__ENCODING__
3009
3009
  {
3010
- l = lexer.lineno
3010
+ (_, l), = val
3011
3011
  result =
3012
3012
  if defined? Encoding then
3013
3013
  s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
@@ -3170,12 +3170,12 @@ f_opt_paren_args: f_paren_args
3170
3170
  |
3171
3171
  {
3172
3172
  result = args val
3173
- # result.line lexer.lineno
3174
3173
  }
3175
3174
 
3176
3175
  args_forward: tBDOT3
3177
3176
  {
3178
- result = s(:forward_args).line lexer.lineno
3177
+ (_, line), = val
3178
+ result = s(:forward_args).line line
3179
3179
  }
3180
3180
 
3181
3181
  f_bad_arg: tCONSTANT
@@ -3313,9 +3313,10 @@ f_opt_paren_args: f_paren_args
3313
3313
  }
3314
3314
  | kwrest_mark
3315
3315
  {
3316
+ (_, line), = val
3316
3317
  id = :"**"
3317
- self.env[id] = :lvar # TODO: needed?!?
3318
- result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3318
+ self.env[id] = :lvar
3319
+ result = [id, line]
3319
3320
  }
3320
3321
 
3321
3322
  f_opt: f_arg_asgn
@@ -3373,9 +3374,10 @@ f_opt_paren_args: f_paren_args
3373
3374
  }
3374
3375
  | restarg_mark
3375
3376
  {
3377
+ (_, line), = val
3376
3378
  name = :"*"
3377
3379
  self.env[name] = :lvar
3378
- result = [name, lexer.lineno] # FIX: tSTAR to include lineno
3380
+ result = [name, line]
3379
3381
  }
3380
3382
 
3381
3383
  blkarg_mark: tAMPER2 | tAMPER
@@ -3480,11 +3482,10 @@ f_opt_paren_args: f_paren_args
3480
3482
  opt_terms: | terms
3481
3483
  opt_nl: | tNL
3482
3484
  rparen: opt_nl tRPAREN
3483
- # TODO:
3484
- # {
3485
- # _, close = val
3486
- # result = [close, lexer.lineno]
3487
- # }
3485
+ {
3486
+ _, close = val # TODO: include lineno in close?
3487
+ result = [close, lexer.lineno]
3488
+ }
3488
3489
  rbracket: opt_nl tRBRACK
3489
3490
  {
3490
3491
  _, close = val