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/ruby30_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
 
@@ -605,7 +605,7 @@ rule
605
605
  }
606
606
  | tSTAR
607
607
  {
608
- l = lexer.lineno
608
+ (_, l), = val
609
609
  result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
610
610
  }
611
611
  | tSTAR tCOMMA mlhs_post
@@ -1230,7 +1230,7 @@ rule
1230
1230
  args: arg_value
1231
1231
  {
1232
1232
  arg, = val
1233
- lineno = arg.line || lexer.lineno # HACK
1233
+ lineno = arg.line
1234
1234
 
1235
1235
  result = s(:array, arg).line lineno
1236
1236
  }
@@ -1246,9 +1246,7 @@ rule
1246
1246
  }
1247
1247
  | args tCOMMA tSTAR arg_value
1248
1248
  {
1249
- # TODO: the line number from tSTAR has been dropped
1250
- args, _, _, id = val
1251
- line = lexer.lineno
1249
+ args, _, (_, line), id = val
1252
1250
  result = self.list_append args, s(:splat, id).line(line)
1253
1251
  }
1254
1252
 
@@ -1267,7 +1265,6 @@ rule
1267
1265
  }
1268
1266
  | args tCOMMA tSTAR arg_value
1269
1267
  {
1270
- # TODO: make all tXXXX terminals include lexer.lineno
1271
1268
  arg, _, _, splat = val
1272
1269
  result = self.arg_concat arg, splat
1273
1270
  }
@@ -1296,7 +1293,6 @@ rule
1296
1293
  | k_begin
1297
1294
  {
1298
1295
  lexer.cmdarg.push false
1299
- result = self.lexer.lineno
1300
1296
  }
1301
1297
  bodystmt k_end
1302
1298
  {
@@ -1306,11 +1302,10 @@ rule
1306
1302
  | tLPAREN_ARG
1307
1303
  {
1308
1304
  lexer.lex_state = EXPR_ENDARG
1309
- result = lexer.lineno
1310
1305
  }
1311
1306
  rparen
1312
1307
  {
1313
- _, line, _ = val
1308
+ (_, line), _, _ = val
1314
1309
  result = s(:begin).line line
1315
1310
  }
1316
1311
  | tLPAREN_ARG
@@ -1326,9 +1321,8 @@ rule
1326
1321
  }
1327
1322
  | tLPAREN compstmt tRPAREN
1328
1323
  {
1329
- _, stmt, _ = val
1330
- result = stmt
1331
- result ||= s(:nil).line lexer.lineno
1324
+ (_, line), stmt, _ = val
1325
+ result = stmt || s(:nil).line(line)
1332
1326
  result.paren = true
1333
1327
  }
1334
1328
  | primary_value tCOLON2 tCONSTANT
@@ -1341,9 +1335,9 @@ rule
1341
1335
  {
1342
1336
  result = wrap :colon3, val[1]
1343
1337
  }
1344
- | tLBRACK { result = lexer.lineno } aref_args rbracket
1338
+ | tLBRACK aref_args rbracket
1345
1339
  {
1346
- _, line, args, (_, line_max) = val
1340
+ (_, line), args, (_, line_max) = val
1347
1341
 
1348
1342
  result = args || s(:array)
1349
1343
  result.sexp_type = :array # aref_args is :args
@@ -1459,9 +1453,6 @@ rule
1459
1453
  result = new_for iter, var, body
1460
1454
  }
1461
1455
  | k_class
1462
- {
1463
- result = self.lexer.lineno
1464
- }
1465
1456
  cpath superclass
1466
1457
  {
1467
1458
  if (self.in_def || self.in_single > 0) then
@@ -1476,9 +1467,6 @@ rule
1476
1467
  self.lexer.ignore_body_comments
1477
1468
  }
1478
1469
  | k_class tLSHFT
1479
- {
1480
- result = self.lexer.lineno
1481
- }
1482
1470
  expr
1483
1471
  {
1484
1472
  result = self.in_def
@@ -1490,16 +1478,14 @@ rule
1490
1478
  self.in_single = 0
1491
1479
  self.env.extend
1492
1480
  }
1493
- bodystmt k_end
1481
+ bodystmt
1482
+ k_end
1494
1483
  {
1495
1484
  result = new_sclass val
1496
1485
  self.env.unextend
1497
1486
  self.lexer.ignore_body_comments
1498
1487
  }
1499
1488
  | k_module
1500
- {
1501
- result = self.lexer.lineno
1502
- }
1503
1489
  cpath
1504
1490
  {
1505
1491
  yyerror "module definition in method body" if
@@ -1641,20 +1627,33 @@ rule
1641
1627
  }
1642
1628
 
1643
1629
  f_marg: f_norm_arg
1630
+ {
1631
+ (sym, line), = val
1632
+
1633
+ result = s(:dummy, sym).line line
1634
+ }
1644
1635
  | tLPAREN f_margs rparen
1645
1636
  {
1646
- result = val[1]
1637
+ _, args, _ = val
1638
+ result = args
1647
1639
  }
1648
1640
 
1649
1641
  f_marg_list: f_marg
1650
1642
  {
1651
- sym, = val
1643
+ arg, = val
1644
+ line = arg.line
1652
1645
 
1653
- result = s(:array, sym).line lexer.lineno
1646
+ arg = arg.last if arg.sexp_type == :dummy
1647
+
1648
+ result = s(:array, arg).line line
1654
1649
  }
1655
1650
  | f_marg_list tCOMMA f_marg
1656
1651
  {
1657
- result = list_append val[0], val[2]
1652
+ args, _, arg = val
1653
+
1654
+ arg = arg.last if arg.sexp_type == :dummy
1655
+
1656
+ result = list_append args, arg
1658
1657
  }
1659
1658
 
1660
1659
  f_margs: f_marg_list
@@ -1697,8 +1696,8 @@ rule
1697
1696
  }
1698
1697
  | tSTAR
1699
1698
  {
1700
- result = args [:*]
1701
- result.line lexer.lineno # FIX: tSTAR -> line
1699
+ (_, line), = val
1700
+ result = args([:*]).line line
1702
1701
  }
1703
1702
 
1704
1703
  f_any_kwrest: f_kwrest
@@ -1810,7 +1809,9 @@ opt_block_args_tail: tCOMMA block_args_tail
1810
1809
  }
1811
1810
  | tOROP
1812
1811
  {
1813
- result = s(:args).line lexer.lineno
1812
+ (_, line), = val
1813
+
1814
+ result = s(:args).line line
1814
1815
  }
1815
1816
  | tPIPE block_param opt_bv_decl tPIPE
1816
1817
  {
@@ -1842,7 +1843,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1842
1843
  lambda: tLAMBDA
1843
1844
  {
1844
1845
  self.env.extend :dynamic
1845
- result = [lexer.lineno, lexer.lpar_beg]
1846
+ result = lexer.lpar_beg
1846
1847
  lexer.paren_nest += 1
1847
1848
  lexer.lpar_beg = lexer.paren_nest
1848
1849
  }
@@ -1852,7 +1853,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1852
1853
  }
1853
1854
  lambda_body
1854
1855
  {
1855
- _, (line, lpar), args, _cmdarg, body = val
1856
+ (_, line), lpar, args, _cmdarg, body = val
1856
1857
  lexer.lpar_beg = lpar
1857
1858
 
1858
1859
  lexer.cmdarg.pop
@@ -1976,7 +1977,8 @@ opt_block_args_tail: tCOMMA block_args_tail
1976
1977
  }
1977
1978
  | kSUPER
1978
1979
  {
1979
- result = s(:zsuper).line lexer.lineno
1980
+ (_, line), = val
1981
+ result = s(:zsuper).line line
1980
1982
  }
1981
1983
  | primary_value tLBRACK2 opt_call_args rbracket
1982
1984
  {
@@ -1986,11 +1988,11 @@ opt_block_args_tail: tCOMMA block_args_tail
1986
1988
  brace_block: tLCURLY
1987
1989
  {
1988
1990
  self.env.extend :dynamic
1989
- result = self.lexer.lineno
1990
1991
  }
1991
- brace_body tRCURLY
1992
+ brace_body
1993
+ tRCURLY
1992
1994
  {
1993
- _, line, body, _ = val
1995
+ (_, line), _, body, _ = val
1994
1996
 
1995
1997
  result = body
1996
1998
  result.line line
@@ -2000,11 +2002,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2000
2002
  | k_do
2001
2003
  {
2002
2004
  self.env.extend :dynamic
2003
- result = self.lexer.lineno
2004
2005
  }
2005
- do_body kEND
2006
+ do_body
2007
+ kEND
2006
2008
  {
2007
- _, line, body, _ = val
2009
+ (_, line), _, body, _ = val
2008
2010
 
2009
2011
  result = body
2010
2012
  result.line line
@@ -2062,14 +2064,13 @@ opt_block_args_tail: tCOMMA block_args_tail
2062
2064
  }
2063
2065
 
2064
2066
  case_body: k_when
2065
- {
2066
- result = self.lexer.lineno
2067
- }
2068
2067
  case_args then compstmt cases
2069
2068
  {
2070
- result = new_when(val[2], val[4])
2071
- result.line val[1]
2072
- result << val[5] if val[5]
2069
+ (_, line), case_args, _then, body, cases = val
2070
+
2071
+ result = new_when case_args, body
2072
+ result.line line
2073
+ result << cases if cases
2073
2074
  }
2074
2075
 
2075
2076
  cases: opt_else | case_body
@@ -2844,7 +2845,6 @@ regexp_contents: none
2844
2845
  lexer.brace_nest,
2845
2846
  lexer.string_nest, # TODO: remove
2846
2847
  lexer.lex_state,
2847
- lexer.lineno,
2848
2848
  ]
2849
2849
 
2850
2850
  lexer.cmdarg.push false
@@ -2859,9 +2859,9 @@ regexp_contents: none
2859
2859
  compstmt
2860
2860
  tSTRING_DEND
2861
2861
  {
2862
- _, memo, stmt, _ = val
2862
+ (_, line), memo, stmt, _ = val
2863
2863
 
2864
- lex_strterm, brace_nest, string_nest, oldlex_state, line = memo
2864
+ lex_strterm, brace_nest, string_nest, oldlex_state = memo
2865
2865
  # TODO: heredoc_indent
2866
2866
 
2867
2867
  lexer.lex_strterm = lex_strterm
@@ -2921,11 +2921,11 @@ regexp_contents: none
2921
2921
 
2922
2922
  dsym: tSYMBEG string_contents tSTRING_END
2923
2923
  {
2924
- _, result, _ = val
2924
+ (_, line), result, _ = val
2925
2925
 
2926
2926
  lexer.lex_state = EXPR_END
2927
2927
 
2928
- result ||= s(:str, "").line lexer.lineno
2928
+ result ||= s(:str, "").line line
2929
2929
 
2930
2930
  case result.sexp_type
2931
2931
  when :dstr then
@@ -2958,15 +2958,15 @@ regexp_contents: none
2958
2958
  | tCONSTANT
2959
2959
  | tCVAR
2960
2960
 
2961
- keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2962
- | kSELF { result = s(:self).line lexer.lineno }
2963
- | kTRUE { result = s(:true).line lexer.lineno }
2964
- | kFALSE { result = s(:false).line lexer.lineno }
2965
- | k__FILE__ { result = s(:str, self.file).line lexer.lineno }
2966
- | k__LINE__ { result = s(:lit, lexer.lineno).line lexer.lineno }
2961
+ keyword_variable: kNIL { (_, line), = val; result = s(:nil).line line }
2962
+ | kSELF { (_, line), = val; result = s(:self).line line }
2963
+ | kTRUE { (_, line), = val; result = s(:true).line line }
2964
+ | kFALSE { (_, line), = val; result = s(:false).line line }
2965
+ | k__FILE__ { (_, line), = val; result = s(:str, self.file).line line }
2966
+ | k__LINE__ { (_, line), = val; result = s(:lit, line).line line }
2967
2967
  | k__ENCODING__
2968
2968
  {
2969
- l = lexer.lineno
2969
+ (_, l), = val
2970
2970
  result =
2971
2971
  if defined? Encoding then
2972
2972
  s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
@@ -3136,12 +3136,12 @@ f_opt_paren_args: f_paren_args
3136
3136
  |
3137
3137
  {
3138
3138
  result = args val
3139
- # result.line lexer.lineno
3140
3139
  }
3141
3140
 
3142
3141
  args_forward: tBDOT3
3143
3142
  {
3144
- result = s(:forward_args).line lexer.lineno
3143
+ (_, line), = val
3144
+ result = s(:forward_args).line line
3145
3145
  }
3146
3146
 
3147
3147
  f_bad_arg: tCONSTANT
@@ -3279,9 +3279,10 @@ f_opt_paren_args: f_paren_args
3279
3279
  }
3280
3280
  | kwrest_mark
3281
3281
  {
3282
+ (_, line), = val
3282
3283
  id = :"**"
3283
- self.env[id] = :lvar # TODO: needed?!?
3284
- result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
3284
+ self.env[id] = :lvar
3285
+ result = [id, line]
3285
3286
  }
3286
3287
 
3287
3288
  f_opt: f_arg_asgn
@@ -3339,9 +3340,10 @@ f_opt_paren_args: f_paren_args
3339
3340
  }
3340
3341
  | restarg_mark
3341
3342
  {
3343
+ (_, line), = val
3342
3344
  name = :"*"
3343
3345
  self.env[name] = :lvar
3344
- result = [name, lexer.lineno] # FIX: tSTAR to include lineno
3346
+ result = [name, line]
3345
3347
  }
3346
3348
 
3347
3349
  blkarg_mark: tAMPER2 | tAMPER
@@ -3446,11 +3448,10 @@ f_opt_paren_args: f_paren_args
3446
3448
  opt_terms: | terms
3447
3449
  opt_nl: | tNL
3448
3450
  rparen: opt_nl tRPAREN
3449
- # TODO:
3450
- # {
3451
- # _, close = val
3452
- # result = [close, lexer.lineno]
3453
- # }
3451
+ {
3452
+ _, close = val # TODO: include lineno in close?
3453
+ result = [close, lexer.lineno]
3454
+ }
3454
3455
  rbracket: opt_nl tRBRACK
3455
3456
  {
3456
3457
  _, close = val