ruby-next-parser 3.1.1.0 → 3.1.1.3

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.
@@ -49,7 +49,7 @@ rule
49
49
 
50
50
  program: {
51
51
  @current_arg_stack.push(nil)
52
- @max_numparam_stack.push
52
+ @max_numparam_stack.push(static: true)
53
53
  }
54
54
  top_compstmt
55
55
  {
@@ -264,21 +264,19 @@ rule
264
264
  }
265
265
  | defn_head f_opt_paren_args tEQL command
266
266
  {
267
- _def_t, name_t = val[0]
267
+ def_t, (name_t, ctx) = val[0]
268
268
  endless_method_name(name_t)
269
269
 
270
- result = @builder.def_endless_method(*val[0],
270
+ result = @builder.def_endless_method(def_t, name_t,
271
271
  val[1], val[2], val[3])
272
272
 
273
- @lexer.cmdarg.pop
274
- @lexer.cond.pop
275
- @static_env.unextend
276
- @context.pop
273
+ local_pop
277
274
  @current_arg_stack.pop
275
+ @context.in_def = ctx.in_def
278
276
  }
279
277
  | defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
280
278
  {
281
- _def_t, name_t = val[0]
279
+ def_t, (name_t, ctx) = val[0]
282
280
  endless_method_name(name_t)
283
281
 
284
282
  rescue_body = @builder.rescue_body(val[4],
@@ -287,32 +285,28 @@ rule
287
285
 
288
286
  method_body = @builder.begin_body(val[3], [ rescue_body ])
289
287
 
290
- result = @builder.def_endless_method(*val[0],
288
+ result = @builder.def_endless_method(def_t, name_t,
291
289
  val[1], val[2], method_body)
292
290
 
293
- @lexer.cmdarg.pop
294
- @lexer.cond.pop
295
- @static_env.unextend
296
- @context.pop
291
+ local_pop
297
292
  @current_arg_stack.pop
293
+ @context.in_def = ctx.in_def
298
294
  }
299
295
  | defs_head f_opt_paren_args tEQL command
300
296
  {
301
- _def_t, _recv, _dot_t, name_t = val[0]
297
+ def_t, recv, dot_t, (name_t, ctx) = val[0]
302
298
  endless_method_name(name_t)
303
299
 
304
- result = @builder.def_endless_singleton(*val[0],
300
+ result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
305
301
  val[1], val[2], val[3])
306
302
 
307
- @lexer.cmdarg.pop
308
- @lexer.cond.pop
309
- @static_env.unextend
310
- @context.pop
303
+ local_pop
311
304
  @current_arg_stack.pop
305
+ @context.in_def = ctx.in_def
312
306
  }
313
307
  | defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
314
308
  {
315
- _def_t, _recv, _dot_t, name_t = val[0]
309
+ def_t, recv, dot_t, (name_t, ctx) = val[0]
316
310
  endless_method_name(name_t)
317
311
 
318
312
  rescue_body = @builder.rescue_body(val[4],
@@ -321,14 +315,12 @@ rule
321
315
 
322
316
  method_body = @builder.begin_body(val[3], [ rescue_body ])
323
317
 
324
- result = @builder.def_endless_singleton(*val[0],
318
+ result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
325
319
  val[1], val[2], method_body)
326
320
 
327
- @lexer.cmdarg.pop
328
- @lexer.cond.pop
329
- @static_env.unextend
330
- @context.pop
321
+ local_pop
331
322
  @current_arg_stack.pop
323
+ @context.in_def = ctx.in_def
332
324
  }
333
325
  | backref tOP_ASGN command_rhs
334
326
  {
@@ -369,13 +361,13 @@ rule
369
361
  @lexer.command_start = false
370
362
  @pattern_variables.push
371
363
 
372
- result = @lexer.in_kwarg
373
- @lexer.in_kwarg = true
364
+ result = @context.in_kwarg
365
+ @context.in_kwarg = true
374
366
  }
375
367
  p_top_expr_body
376
368
  {
377
369
  @pattern_variables.pop
378
- @lexer.in_kwarg = val[2]
370
+ @context.in_kwarg = val[2]
379
371
  result = @builder.match_pattern(val[0], val[1], val[3])
380
372
  }
381
373
  | arg kIN
@@ -384,13 +376,13 @@ rule
384
376
  @lexer.command_start = false
385
377
  @pattern_variables.push
386
378
 
387
- result = @lexer.in_kwarg
388
- @lexer.in_kwarg = true
379
+ result = @context.in_kwarg
380
+ @context.in_kwarg = true
389
381
  }
390
382
  p_top_expr_body
391
383
  {
392
384
  @pattern_variables.pop
393
- @lexer.in_kwarg = val[2]
385
+ @context.in_kwarg = val[2]
394
386
  result = @builder.match_pattern_p(val[0], val[1], val[3])
395
387
  }
396
388
  | arg =tLBRACE_ARG
@@ -408,29 +400,25 @@ rule
408
400
 
409
401
  def_name: fname
410
402
  {
411
- @static_env.extend_static
412
- @lexer.cmdarg.push(false)
413
- @lexer.cond.push(false)
403
+ local_push
414
404
  @current_arg_stack.push(nil)
415
405
 
416
- result = val[0]
406
+ result = [ val[0], @context.dup ]
407
+ @context.in_def = true
417
408
  }
418
409
 
419
- defn_head: kDEF def_name
410
+ defn_head: k_def def_name
420
411
  {
421
- @context.push(:def)
422
-
423
412
  result = [ val[0], val[1] ]
424
413
  }
425
414
 
426
- defs_head: kDEF singleton dot_or_colon
415
+ defs_head: k_def singleton dot_or_colon
427
416
  {
428
417
  @lexer.state = :expr_fname
418
+ @context.in_argdef = true
429
419
  }
430
420
  def_name
431
421
  {
432
- @context.push(:defs)
433
-
434
422
  result = [ val[0], val[1], val[2], val[4] ]
435
423
  }
436
424
 
@@ -447,12 +435,13 @@ rule
447
435
 
448
436
  cmd_brace_block: tLBRACE_ARG
449
437
  {
450
- @context.push(:block)
438
+ result = @context.dup
439
+ @context.in_block = true
451
440
  }
452
441
  brace_body tRCURLY
453
442
  {
443
+ @context.in_block = val[1].in_block
454
444
  result = [ val[0], *val[2], val[3] ]
455
- @context.pop
456
445
  }
457
446
 
458
447
  fcall: operation
@@ -933,9 +922,14 @@ rule
933
922
  {
934
923
  result = @builder.logical_op(:or, val[0], val[1], val[2])
935
924
  }
936
- | kDEFINED opt_nl arg
925
+ | kDEFINED opt_nl
937
926
  {
938
- result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
927
+ @context.in_defined = true
928
+ }
929
+ arg
930
+ {
931
+ @context.in_defined = false
932
+ result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[3] ], nil)
939
933
  }
940
934
  | arg tEH arg opt_nl tCOLON arg
941
935
  {
@@ -944,21 +938,19 @@ rule
944
938
  }
945
939
  | defn_head f_opt_paren_args tEQL arg
946
940
  {
947
- _def_t, name_t = val[0]
941
+ def_t, (name_t, ctx) = val[0]
948
942
  endless_method_name(name_t)
949
943
 
950
- result = @builder.def_endless_method(*val[0],
944
+ result = @builder.def_endless_method(def_t, name_t,
951
945
  val[1], val[2], val[3])
952
946
 
953
- @lexer.cmdarg.pop
954
- @lexer.cond.pop
955
- @static_env.unextend
956
- @context.pop
947
+ local_pop
957
948
  @current_arg_stack.pop
949
+ @context.in_def = ctx.in_def
958
950
  }
959
951
  | defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
960
952
  {
961
- _def_t, name_t = val[0]
953
+ def_t, (name_t, ctx) = val[0]
962
954
  endless_method_name(name_t)
963
955
 
964
956
  rescue_body = @builder.rescue_body(val[4],
@@ -967,32 +959,28 @@ rule
967
959
 
968
960
  method_body = @builder.begin_body(val[3], [ rescue_body ])
969
961
 
970
- result = @builder.def_endless_method(*val[0],
962
+ result = @builder.def_endless_method(def_t, name_t,
971
963
  val[1], val[2], method_body)
972
964
 
973
- @lexer.cmdarg.pop
974
- @lexer.cond.pop
975
- @static_env.unextend
976
- @context.pop
965
+ local_pop
977
966
  @current_arg_stack.pop
967
+ @context.in_def = ctx.in_def
978
968
  }
979
969
  | defs_head f_opt_paren_args tEQL arg
980
970
  {
981
- _def_t, _recv, _dot_t, name_t = val[0]
971
+ def_t, recv, dot_t, (name_t, ctx) = val[0]
982
972
  endless_method_name(name_t)
983
973
 
984
- result = @builder.def_endless_singleton(*val[0],
974
+ result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
985
975
  val[1], val[2], val[3])
986
976
 
987
- @lexer.cmdarg.pop
988
- @lexer.cond.pop
989
- @static_env.unextend
990
- @context.pop
977
+ local_pop
991
978
  @current_arg_stack.pop
979
+ @context.in_def = ctx.in_def
992
980
  }
993
981
  | defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
994
982
  {
995
- _def_t, _recv, _dot_t, name_t = val[0]
983
+ def_t, recv, dot_t, (name_t, ctx) = val[0]
996
984
  endless_method_name(name_t)
997
985
 
998
986
  rescue_body = @builder.rescue_body(val[4],
@@ -1001,14 +989,12 @@ rule
1001
989
 
1002
990
  method_body = @builder.begin_body(val[3], [ rescue_body ])
1003
991
 
1004
- result = @builder.def_endless_singleton(*val[0],
992
+ result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
1005
993
  val[1], val[2], method_body)
1006
994
 
1007
- @lexer.cmdarg.pop
1008
- @lexer.cond.pop
1009
- @static_env.unextend
1010
- @context.pop
995
+ local_pop
1011
996
  @current_arg_stack.pop
997
+ @context.in_def = ctx.in_def
1012
998
  }
1013
999
  | primary
1014
1000
 
@@ -1290,10 +1276,15 @@ rule
1290
1276
  {
1291
1277
  result = @builder.keyword_cmd(:yield, val[0])
1292
1278
  }
1293
- | kDEFINED opt_nl tLPAREN2 expr rparen
1279
+ | kDEFINED opt_nl tLPAREN2
1294
1280
  {
1281
+ @context.in_defined = true
1282
+ }
1283
+ expr rparen
1284
+ {
1285
+ @context.in_defined = false
1295
1286
  result = @builder.keyword_cmd(:defined?, val[0],
1296
- val[2], [ val[3] ], val[4])
1287
+ val[2], [ val[4] ], val[5])
1297
1288
  }
1298
1289
  | kNOT tLPAREN2 expr rparen
1299
1290
  {
@@ -1369,86 +1360,77 @@ rule
1369
1360
  {
1370
1361
  result = @builder.for(val[0], val[1], val[2], *val[3], val[4], val[5])
1371
1362
  }
1372
- | kCLASS cpath superclass
1363
+ | k_class cpath superclass
1373
1364
  {
1374
- @static_env.extend_static
1375
- @lexer.cmdarg.push(false)
1376
- @lexer.cond.push(false)
1377
- @context.push(:class)
1365
+ @context.in_class = true
1366
+ local_push
1378
1367
  }
1379
1368
  bodystmt kEND
1380
1369
  {
1381
- unless @context.class_definition_allowed?
1382
- diagnostic :error, :class_in_def, nil, val[0]
1370
+ k_class, ctx = val[0]
1371
+ if @context.in_def
1372
+ diagnostic :error, :class_in_def, nil, k_class
1383
1373
  end
1384
-
1385
1374
  lt_t, superclass = val[2]
1386
- result = @builder.def_class(val[0], val[1],
1375
+ result = @builder.def_class(k_class, val[1],
1387
1376
  lt_t, superclass,
1388
1377
  val[4], val[5])
1389
1378
 
1390
- @lexer.cmdarg.pop
1391
- @lexer.cond.pop
1392
- @static_env.unextend
1393
- @context.pop
1379
+ local_pop
1380
+ @context.in_class = ctx.in_class
1394
1381
  }
1395
- | kCLASS tLSHFT expr term
1382
+ | k_class tLSHFT expr term
1396
1383
  {
1397
- @static_env.extend_static
1398
- @lexer.cmdarg.push(false)
1399
- @lexer.cond.push(false)
1400
- @context.push(:sclass)
1384
+ @context.in_def = false
1385
+ @context.in_class = false
1386
+ local_push
1401
1387
  }
1402
1388
  bodystmt kEND
1403
1389
  {
1404
- result = @builder.def_sclass(val[0], val[1], val[2],
1390
+ k_class, ctx = val[0]
1391
+ result = @builder.def_sclass(k_class, val[1], val[2],
1405
1392
  val[5], val[6])
1406
1393
 
1407
- @lexer.cmdarg.pop
1408
- @lexer.cond.pop
1409
- @static_env.unextend
1410
- @context.pop
1394
+ local_pop
1395
+ @context.in_def = ctx.in_def
1396
+ @context.in_class = ctx.in_class
1411
1397
  }
1412
- | kMODULE cpath
1398
+ | k_module cpath
1413
1399
  {
1414
- @static_env.extend_static
1415
- @lexer.cmdarg.push(false)
1416
- @context.push(:module)
1400
+ @context.in_class = true
1401
+ local_push
1417
1402
  }
1418
1403
  bodystmt kEND
1419
1404
  {
1420
- unless @context.module_definition_allowed?
1421
- diagnostic :error, :module_in_def, nil, val[0]
1405
+ k_mod, ctx = val[0]
1406
+ if @context.in_def
1407
+ diagnostic :error, :module_in_def, nil, k_mod
1422
1408
  end
1423
-
1424
- result = @builder.def_module(val[0], val[1],
1409
+ result = @builder.def_module(k_mod, val[1],
1425
1410
  val[3], val[4])
1426
1411
 
1427
- @lexer.cmdarg.pop
1428
- @static_env.unextend
1429
- @context.pop
1412
+ local_pop
1413
+ @context.in_class = ctx.in_class
1430
1414
  }
1431
1415
  | defn_head f_arglist bodystmt kEND
1432
1416
  {
1433
- result = @builder.def_method(*val[0], val[1],
1417
+ def_t, (name_t, ctx) = val[0]
1418
+ result = @builder.def_method(def_t, name_t, val[1],
1434
1419
  val[2], val[3])
1435
1420
 
1436
- @lexer.cmdarg.pop
1437
- @lexer.cond.pop
1438
- @static_env.unextend
1439
- @context.pop
1421
+ local_pop
1440
1422
  @current_arg_stack.pop
1423
+ @context.in_def = ctx.in_def
1441
1424
  }
1442
1425
  | defs_head f_arglist bodystmt kEND
1443
1426
  {
1444
- result = @builder.def_singleton(*val[0], val[1],
1427
+ def_t, recv, dot_t, (name_t, ctx) = val[0]
1428
+ result = @builder.def_singleton(def_t, recv, dot_t, name_t, val[1],
1445
1429
  val[2], val[3])
1446
1430
 
1447
- @lexer.cmdarg.pop
1448
- @lexer.cond.pop
1449
- @static_env.unextend
1450
- @context.pop
1431
+ local_pop
1451
1432
  @current_arg_stack.pop
1433
+ @context.in_def = ctx.in_def
1452
1434
  }
1453
1435
  | kBREAK
1454
1436
  {
@@ -1473,9 +1455,25 @@ rule
1473
1455
 
1474
1456
  primary_value: primary
1475
1457
 
1458
+ k_class: kCLASS
1459
+ {
1460
+ result = [ val[0], @context.dup ]
1461
+ }
1462
+
1463
+ k_module: kMODULE
1464
+ {
1465
+ result = [ val[0], @context.dup ]
1466
+ }
1467
+
1468
+ k_def: kDEF
1469
+ {
1470
+ result = val[0]
1471
+ @context.in_argdef = true
1472
+ }
1473
+
1476
1474
  k_return: kRETURN
1477
1475
  {
1478
- if @context.in_class?
1476
+ if @context.in_class && !@context.in_def && !(context.in_block || context.in_lambda)
1479
1477
  diagnostic :error, :invalid_return, nil, val[0]
1480
1478
  end
1481
1479
  }
@@ -1561,6 +1559,15 @@ rule
1561
1559
  f_any_kwrest: f_kwrest
1562
1560
  | f_no_kwarg
1563
1561
 
1562
+
1563
+ f_eq: {
1564
+ @context.in_argdef = false
1565
+ }
1566
+ tEQL
1567
+ {
1568
+ result = val[1]
1569
+ }
1570
+
1564
1571
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1565
1572
  {
1566
1573
  result = val[0].concat(val[2]).concat(val[3])
@@ -1690,12 +1697,14 @@ opt_block_args_tail:
1690
1697
  {
1691
1698
  @max_numparam_stack.has_ordinary_params!
1692
1699
  @current_arg_stack.set(nil)
1700
+ @context.in_argdef = false
1693
1701
  result = @builder.args(val[0], val[1], val[2])
1694
1702
  }
1695
1703
  | tPIPE block_param opt_bv_decl tPIPE
1696
1704
  {
1697
1705
  @max_numparam_stack.has_ordinary_params!
1698
1706
  @current_arg_stack.set(nil)
1707
+ @context.in_argdef = false
1699
1708
  result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1700
1709
  }
1701
1710
 
@@ -1727,12 +1736,12 @@ opt_block_args_tail:
1727
1736
  lambda: tLAMBDA
1728
1737
  {
1729
1738
  @static_env.extend_dynamic
1730
- @max_numparam_stack.push
1731
- @context.push(:lambda)
1739
+ @max_numparam_stack.push(static: false)
1740
+ result = @context.dup
1741
+ @context.in_lambda = true
1732
1742
  }
1733
1743
  f_larglist
1734
1744
  {
1735
- @context.pop
1736
1745
  @lexer.cmdarg.push(false)
1737
1746
  }
1738
1747
  lambda_body
@@ -1744,6 +1753,7 @@ opt_block_args_tail:
1744
1753
  @max_numparam_stack.pop
1745
1754
  @static_env.unextend
1746
1755
  @lexer.cmdarg.pop
1756
+ @context.in_lambda = val[1].in_lambda
1747
1757
 
1748
1758
  result = @builder.block(lambda_call,
1749
1759
  begin_t, args, body, end_t)
@@ -1751,11 +1761,13 @@ opt_block_args_tail:
1751
1761
 
1752
1762
  f_larglist: tLPAREN2 f_args opt_bv_decl tRPAREN
1753
1763
  {
1764
+ @context.in_argdef = false
1754
1765
  @max_numparam_stack.has_ordinary_params!
1755
1766
  result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1756
1767
  }
1757
1768
  | f_args
1758
1769
  {
1770
+ @context.in_argdef = false
1759
1771
  if val[0].any?
1760
1772
  @max_numparam_stack.has_ordinary_params!
1761
1773
  end
@@ -1764,31 +1776,34 @@ opt_block_args_tail:
1764
1776
 
1765
1777
  lambda_body: tLAMBEG
1766
1778
  {
1767
- @context.push(:lambda)
1779
+ result = @context.dup
1780
+ @context.in_lambda = true
1768
1781
  }
1769
1782
  compstmt tRCURLY
1770
1783
  {
1784
+ @context.in_lambda = val[1].in_lambda
1771
1785
  result = [ val[0], val[2], val[3] ]
1772
- @context.pop
1773
1786
  }
1774
1787
  | kDO_LAMBDA
1775
1788
  {
1776
- @context.push(:lambda)
1789
+ result = @context.dup
1790
+ @context.in_lambda = true
1777
1791
  }
1778
1792
  bodystmt kEND
1779
1793
  {
1794
+ @context.in_lambda = val[1].in_lambda
1780
1795
  result = [ val[0], val[2], val[3] ]
1781
- @context.pop
1782
1796
  }
1783
1797
 
1784
1798
  do_block: kDO_BLOCK
1785
1799
  {
1786
- @context.push(:block)
1800
+ result = @context.dup
1801
+ @context.in_block = true
1787
1802
  }
1788
1803
  do_body kEND
1789
1804
  {
1805
+ @context.in_block = val[1].in_block
1790
1806
  result = [ val[0], *val[2], val[3] ]
1791
- @context.pop
1792
1807
  }
1793
1808
 
1794
1809
  block_call: command do_block
@@ -1874,26 +1889,28 @@ opt_block_args_tail:
1874
1889
 
1875
1890
  brace_block: tLCURLY
1876
1891
  {
1877
- @context.push(:block)
1892
+ result = @context.dup
1893
+ @context.in_block = true
1878
1894
  }
1879
1895
  brace_body tRCURLY
1880
1896
  {
1897
+ @context.in_block = val[1].in_block
1881
1898
  result = [ val[0], *val[2], val[3] ]
1882
- @context.pop
1883
1899
  }
1884
1900
  | kDO
1885
1901
  {
1886
- @context.push(:block)
1902
+ result = @context.dup
1903
+ @context.in_block = true
1887
1904
  }
1888
1905
  do_body kEND
1889
1906
  {
1907
+ @context.in_block = val[1].in_block
1890
1908
  result = [ val[0], *val[2], val[3] ]
1891
- @context.pop
1892
1909
  }
1893
1910
 
1894
1911
  brace_body: {
1895
1912
  @static_env.extend_dynamic
1896
- @max_numparam_stack.push
1913
+ @max_numparam_stack.push(static: false)
1897
1914
  }
1898
1915
  opt_block_param compstmt
1899
1916
  {
@@ -1906,7 +1923,7 @@ opt_block_args_tail:
1906
1923
 
1907
1924
  do_body: {
1908
1925
  @static_env.extend_dynamic
1909
- @max_numparam_stack.push
1926
+ @max_numparam_stack.push(static: false)
1910
1927
  }
1911
1928
  {
1912
1929
  @lexer.cmdarg.push(false)
@@ -1940,14 +1957,14 @@ opt_block_args_tail:
1940
1957
  @pattern_variables.push
1941
1958
  @pattern_hash_keys.push
1942
1959
 
1943
- result = @lexer.in_kwarg
1944
- @lexer.in_kwarg = true
1960
+ result = @context.in_kwarg
1961
+ @context.in_kwarg = true
1945
1962
  }
1946
1963
  p_top_expr then
1947
1964
  {
1948
1965
  @pattern_variables.pop
1949
1966
  @pattern_hash_keys.pop
1950
- @lexer.in_kwarg = val[1]
1967
+ @context.in_kwarg = val[1]
1951
1968
  }
1952
1969
  compstmt p_cases
1953
1970
  {
@@ -2089,13 +2106,13 @@ opt_block_args_tail:
2089
2106
  | tLBRACE
2090
2107
  {
2091
2108
  @pattern_hash_keys.push
2092
- result = @lexer.in_kwarg
2093
- @lexer.in_kwarg = false
2109
+ result = @context.in_kwarg
2110
+ @context.in_kwarg = false
2094
2111
  }
2095
2112
  p_kwargs rbrace
2096
2113
  {
2097
2114
  @pattern_hash_keys.pop
2098
- @lexer.in_kwarg = val[1]
2115
+ @context.in_kwarg = val[1]
2099
2116
  result = @builder.hash_pattern(val[0], val[2], val[3])
2100
2117
  }
2101
2118
  | tLBRACE rbrace
@@ -2238,6 +2255,10 @@ opt_block_args_tail:
2238
2255
  {
2239
2256
  result = [ @builder.match_rest(val[0], val[1]) ]
2240
2257
  }
2258
+ | kwrest_mark nonlocal_var
2259
+ {
2260
+ result = [ @builder.match_rest(val[0], val[1]) ]
2261
+ }
2241
2262
  | kwrest_mark
2242
2263
  {
2243
2264
  result = [ @builder.match_rest(val[0], nil) ]
@@ -2245,11 +2266,14 @@ opt_block_args_tail:
2245
2266
 
2246
2267
  p_kwnorest: kwrest_mark kNIL
2247
2268
  {
2248
- result = [ @builder.match_nil_pattern(val[0], val[1]) ]
2269
+ result = val
2249
2270
  }
2250
2271
 
2251
2272
  p_any_kwrest: p_kwrest
2252
2273
  | p_kwnorest
2274
+ {
2275
+ result = [ @builder.match_nil_pattern(val[0][0], val[0][1]) ]
2276
+ }
2253
2277
 
2254
2278
  p_value: p_primitive
2255
2279
  | p_primitive tDOT2 p_primitive
@@ -2704,6 +2728,7 @@ keyword_variable: kNIL
2704
2728
  f_opt_paren_args: f_paren_args
2705
2729
  | none
2706
2730
  {
2731
+ @context.in_argdef = false
2707
2732
  result = @builder.args(nil, [], nil)
2708
2733
  }
2709
2734
 
@@ -2712,18 +2737,19 @@ f_opt_paren_args: f_paren_args
2712
2737
  result = @builder.args(val[0], val[1], val[2])
2713
2738
 
2714
2739
  @lexer.state = :expr_value
2740
+ @context.in_argdef = false
2715
2741
  }
2716
2742
 
2717
2743
  f_arglist: f_paren_args
2718
2744
  | {
2719
- result = @lexer.in_kwarg
2720
- @lexer.in_kwarg = true
2721
- @context.push(:def_open_args)
2745
+ result = @context.dup
2746
+ @context.in_kwarg = true
2747
+ @context.in_argdef = true
2722
2748
  }
2723
2749
  f_args term
2724
2750
  {
2725
- @context.pop
2726
- @lexer.in_kwarg = val[0]
2751
+ @context.in_kwarg = val[0].in_kwarg
2752
+ @context.in_argdef = false
2727
2753
  result = @builder.args(nil, val[1], nil)
2728
2754
  }
2729
2755
 
@@ -2914,6 +2940,7 @@ f_opt_paren_args: f_paren_args
2914
2940
  @max_numparam_stack.has_ordinary_params!
2915
2941
 
2916
2942
  @current_arg_stack.set(val[0][0])
2943
+ @context.in_argdef = false
2917
2944
 
2918
2945
  result = val[0]
2919
2946
  }
@@ -2921,20 +2948,24 @@ f_opt_paren_args: f_paren_args
2921
2948
  f_kw: f_label arg_value
2922
2949
  {
2923
2950
  @current_arg_stack.set(nil)
2951
+ @context.in_argdef = true
2924
2952
  result = @builder.kwoptarg(val[0], val[1])
2925
2953
  }
2926
2954
  | f_label
2927
2955
  {
2928
2956
  @current_arg_stack.set(nil)
2957
+ @context.in_argdef = true
2929
2958
  result = @builder.kwarg(val[0])
2930
2959
  }
2931
2960
 
2932
2961
  f_block_kw: f_label primary_value
2933
2962
  {
2963
+ @context.in_argdef = true
2934
2964
  result = @builder.kwoptarg(val[0], val[1])
2935
2965
  }
2936
2966
  | f_label
2937
2967
  {
2968
+ @context.in_argdef = true
2938
2969
  result = @builder.kwarg(val[0])
2939
2970
  }
2940
2971
 
@@ -2958,9 +2989,9 @@ f_opt_paren_args: f_paren_args
2958
2989
 
2959
2990
  kwrest_mark: tPOW | tDSTAR
2960
2991
 
2961
- f_no_kwarg: kwrest_mark kNIL
2992
+ f_no_kwarg: p_kwnorest
2962
2993
  {
2963
- result = [ @builder.kwnilarg(val[0], val[1]) ]
2994
+ result = [ @builder.kwnilarg(val[0][0], val[0][1]) ]
2964
2995
  }
2965
2996
 
2966
2997
  f_kwrest: kwrest_mark tIDENTIFIER
@@ -2974,15 +3005,17 @@ f_opt_paren_args: f_paren_args
2974
3005
  result = [ @builder.kwrestarg(val[0]) ]
2975
3006
  }
2976
3007
 
2977
- f_opt: f_arg_asgn tEQL arg_value
3008
+ f_opt: f_arg_asgn f_eq arg_value
2978
3009
  {
2979
3010
  @current_arg_stack.set(0)
3011
+ @context.in_argdef = true
2980
3012
  result = @builder.optarg(val[0], val[1], val[2])
2981
3013
  }
2982
3014
 
2983
- f_block_opt: f_arg_asgn tEQL primary_value
3015
+ f_block_opt: f_arg_asgn f_eq primary_value
2984
3016
  {
2985
3017
  @current_arg_stack.set(0)
3018
+ @context.in_argdef = true
2986
3019
  result = @builder.optarg(val[0], val[1], val[2])
2987
3020
  }
2988
3021
 
@@ -3084,7 +3117,7 @@ f_opt_paren_args: f_paren_args
3084
3117
  }
3085
3118
 
3086
3119
  operation: tIDENTIFIER | tCONSTANT | tFID
3087
- operation2: tIDENTIFIER | tCONSTANT | tFID | op
3120
+ operation2: operation | op
3088
3121
  operation3: tIDENTIFIER | tFID | op
3089
3122
  dot_or_colon: call_op | tCOLON2
3090
3123
  call_op: tDOT
@@ -3133,10 +3166,10 @@ require 'parser/ruby-next/parser_ext'
3133
3166
 
3134
3167
  ---- inner
3135
3168
 
3136
- prepend Parser::NextExt
3169
+ prepend Parser::NextExt
3137
3170
 
3138
3171
  def version
3139
- 31
3172
+ 32
3140
3173
  end
3141
3174
 
3142
3175
  def default_encoding
@@ -3149,10 +3182,24 @@ require 'parser/ruby-next/parser_ext'
3149
3182
  end
3150
3183
  end
3151
3184
 
3185
+ def local_push
3186
+ @static_env.extend_static
3187
+ @lexer.cmdarg.push(false)
3188
+ @lexer.cond.push(false)
3189
+ @max_numparam_stack.push(static: true)
3190
+ end
3191
+
3192
+ def local_pop
3193
+ @static_env.unextend
3194
+ @lexer.cmdarg.pop
3195
+ @lexer.cond.pop
3196
+ @max_numparam_stack.pop
3197
+ end
3198
+
3152
3199
  def try_declare_numparam(node)
3153
3200
  name = node.children[0]
3154
3201
 
3155
- if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
3202
+ if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && @context.in_dynamic_block?
3156
3203
  # definitely an implicit param
3157
3204
  location = node.loc.expression
3158
3205
 
@@ -3160,27 +3207,25 @@ require 'parser/ruby-next/parser_ext'
3160
3207
  diagnostic :error, :ordinary_param_defined, nil, [nil, location]
3161
3208
  end
3162
3209
 
3163
- raw_context = context.stack.dup
3164
3210
  raw_max_numparam_stack = max_numparam_stack.stack.dup
3165
-
3166
3211
  # ignore current block scope
3167
- raw_context.pop
3168
3212
  raw_max_numparam_stack.pop
3169
3213
 
3170
- raw_context.reverse_each do |outer_scope|
3171
- if outer_scope == :block || outer_scope == :lambda
3172
- outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
3214
+ raw_max_numparam_stack.reverse_each do |outer_scope|
3215
+ if outer_scope[:static]
3216
+ # found an outer scope that can't have numparams
3217
+ # like def/class/etc
3218
+ break
3219
+ else
3220
+ outer_scope_has_numparams = outer_scope[:value] > 0
3173
3221
 
3174
3222
  if outer_scope_has_numparams
3175
3223
  diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
3176
3224
  else
3177
3225
  # for now it's ok, but an outer scope can also be a block
3226
+ # like proc { _1; proc { proc { proc { _2 }} }}
3178
3227
  # with numparams, so we need to continue
3179
3228
  end
3180
- else
3181
- # found an outer scope that can't have numparams
3182
- # like def/class/etc
3183
- break
3184
3229
  end
3185
3230
  end
3186
3231