ruby-next-parser 3.1.1.0 → 3.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
926
+ {
927
+ @context.in_defined = true
928
+ }
929
+ arg
937
930
  {
938
- result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
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
@@ -2704,6 +2721,7 @@ keyword_variable: kNIL
2704
2721
  f_opt_paren_args: f_paren_args
2705
2722
  | none
2706
2723
  {
2724
+ @context.in_argdef = false
2707
2725
  result = @builder.args(nil, [], nil)
2708
2726
  }
2709
2727
 
@@ -2712,18 +2730,19 @@ f_opt_paren_args: f_paren_args
2712
2730
  result = @builder.args(val[0], val[1], val[2])
2713
2731
 
2714
2732
  @lexer.state = :expr_value
2733
+ @context.in_argdef = false
2715
2734
  }
2716
2735
 
2717
2736
  f_arglist: f_paren_args
2718
2737
  | {
2719
- result = @lexer.in_kwarg
2720
- @lexer.in_kwarg = true
2721
- @context.push(:def_open_args)
2738
+ result = @context.dup
2739
+ @context.in_kwarg = true
2740
+ @context.in_argdef = true
2722
2741
  }
2723
2742
  f_args term
2724
2743
  {
2725
- @context.pop
2726
- @lexer.in_kwarg = val[0]
2744
+ @context.in_kwarg = val[0].in_kwarg
2745
+ @context.in_argdef = false
2727
2746
  result = @builder.args(nil, val[1], nil)
2728
2747
  }
2729
2748
 
@@ -2914,6 +2933,7 @@ f_opt_paren_args: f_paren_args
2914
2933
  @max_numparam_stack.has_ordinary_params!
2915
2934
 
2916
2935
  @current_arg_stack.set(val[0][0])
2936
+ @context.in_argdef = false
2917
2937
 
2918
2938
  result = val[0]
2919
2939
  }
@@ -2921,20 +2941,24 @@ f_opt_paren_args: f_paren_args
2921
2941
  f_kw: f_label arg_value
2922
2942
  {
2923
2943
  @current_arg_stack.set(nil)
2944
+ @context.in_argdef = true
2924
2945
  result = @builder.kwoptarg(val[0], val[1])
2925
2946
  }
2926
2947
  | f_label
2927
2948
  {
2928
2949
  @current_arg_stack.set(nil)
2950
+ @context.in_argdef = true
2929
2951
  result = @builder.kwarg(val[0])
2930
2952
  }
2931
2953
 
2932
2954
  f_block_kw: f_label primary_value
2933
2955
  {
2956
+ @context.in_argdef = true
2934
2957
  result = @builder.kwoptarg(val[0], val[1])
2935
2958
  }
2936
2959
  | f_label
2937
2960
  {
2961
+ @context.in_argdef = true
2938
2962
  result = @builder.kwarg(val[0])
2939
2963
  }
2940
2964
 
@@ -2974,15 +2998,17 @@ f_opt_paren_args: f_paren_args
2974
2998
  result = [ @builder.kwrestarg(val[0]) ]
2975
2999
  }
2976
3000
 
2977
- f_opt: f_arg_asgn tEQL arg_value
3001
+ f_opt: f_arg_asgn f_eq arg_value
2978
3002
  {
2979
3003
  @current_arg_stack.set(0)
3004
+ @context.in_argdef = true
2980
3005
  result = @builder.optarg(val[0], val[1], val[2])
2981
3006
  }
2982
3007
 
2983
- f_block_opt: f_arg_asgn tEQL primary_value
3008
+ f_block_opt: f_arg_asgn f_eq primary_value
2984
3009
  {
2985
3010
  @current_arg_stack.set(0)
3011
+ @context.in_argdef = true
2986
3012
  result = @builder.optarg(val[0], val[1], val[2])
2987
3013
  }
2988
3014
 
@@ -3133,10 +3159,10 @@ require 'parser/ruby-next/parser_ext'
3133
3159
 
3134
3160
  ---- inner
3135
3161
 
3136
- prepend Parser::NextExt
3162
+ prepend Parser::NextExt
3137
3163
 
3138
3164
  def version
3139
- 31
3165
+ 32
3140
3166
  end
3141
3167
 
3142
3168
  def default_encoding
@@ -3149,10 +3175,24 @@ require 'parser/ruby-next/parser_ext'
3149
3175
  end
3150
3176
  end
3151
3177
 
3178
+ def local_push
3179
+ @static_env.extend_static
3180
+ @lexer.cmdarg.push(false)
3181
+ @lexer.cond.push(false)
3182
+ @max_numparam_stack.push(static: true)
3183
+ end
3184
+
3185
+ def local_pop
3186
+ @static_env.unextend
3187
+ @lexer.cmdarg.pop
3188
+ @lexer.cond.pop
3189
+ @max_numparam_stack.pop
3190
+ end
3191
+
3152
3192
  def try_declare_numparam(node)
3153
3193
  name = node.children[0]
3154
3194
 
3155
- if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
3195
+ if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && @context.in_dynamic_block?
3156
3196
  # definitely an implicit param
3157
3197
  location = node.loc.expression
3158
3198
 
@@ -3160,27 +3200,25 @@ require 'parser/ruby-next/parser_ext'
3160
3200
  diagnostic :error, :ordinary_param_defined, nil, [nil, location]
3161
3201
  end
3162
3202
 
3163
- raw_context = context.stack.dup
3164
3203
  raw_max_numparam_stack = max_numparam_stack.stack.dup
3165
-
3166
3204
  # ignore current block scope
3167
- raw_context.pop
3168
3205
  raw_max_numparam_stack.pop
3169
3206
 
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
3207
+ raw_max_numparam_stack.reverse_each do |outer_scope|
3208
+ if outer_scope[:static]
3209
+ # found an outer scope that can't have numparams
3210
+ # like def/class/etc
3211
+ break
3212
+ else
3213
+ outer_scope_has_numparams = outer_scope[:value] > 0
3173
3214
 
3174
3215
  if outer_scope_has_numparams
3175
3216
  diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
3176
3217
  else
3177
3218
  # for now it's ok, but an outer scope can also be a block
3219
+ # like proc { _1; proc { proc { proc { _2 }} }}
3178
3220
  # with numparams, so we need to continue
3179
3221
  end
3180
- else
3181
- # found an outer scope that can't have numparams
3182
- # like def/class/etc
3183
- break
3184
3222
  end
3185
3223
  end
3186
3224