ruby-next-parser 3.2.2.0 → 3.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,6 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
18
18
  tSTRING_DVAR tSTRING_END tSTRING_DEND tSTRING tSYMBOL
19
19
  tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA tLAMBEG tCHARACTER
20
20
  tRATIONAL tIMAGINARY tLABEL_END tANDDOT tBDOT2 tBDOT3
21
- tMETHREF
22
21
 
23
22
  prechigh
24
23
  right tBANG tTILDE tUPLUS
@@ -262,7 +261,7 @@ rule
262
261
  val[0], val[1], val[2]),
263
262
  val[3], val[4])
264
263
  }
265
- | defn_head f_opt_paren_args tEQL command
264
+ | defn_head f_opt_paren_args tEQL endless_command
266
265
  {
267
266
  def_t, (name_t, ctx) = val[0]
268
267
  endless_method_name(name_t)
@@ -274,25 +273,7 @@ rule
274
273
  @current_arg_stack.pop
275
274
  @context.in_def = ctx.in_def
276
275
  }
277
- | defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
278
- {
279
- def_t, (name_t, ctx) = val[0]
280
- endless_method_name(name_t)
281
-
282
- rescue_body = @builder.rescue_body(val[4],
283
- nil, nil, nil,
284
- nil, val[5])
285
-
286
- method_body = @builder.begin_body(val[3], [ rescue_body ])
287
-
288
- result = @builder.def_endless_method(def_t, name_t,
289
- val[1], val[2], method_body)
290
-
291
- local_pop
292
- @current_arg_stack.pop
293
- @context.in_def = ctx.in_def
294
- }
295
- | defs_head f_opt_paren_args tEQL command
276
+ | defs_head f_opt_paren_args tEQL endless_command
296
277
  {
297
278
  def_t, recv, dot_t, (name_t, ctx) = val[0]
298
279
  endless_method_name(name_t)
@@ -304,27 +285,23 @@ rule
304
285
  @current_arg_stack.pop
305
286
  @context.in_def = ctx.in_def
306
287
  }
307
- | defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
288
+ | backref tOP_ASGN command_rhs
308
289
  {
309
- def_t, recv, dot_t, (name_t, ctx) = val[0]
310
- endless_method_name(name_t)
290
+ @builder.op_assign(val[0], val[1], val[2])
291
+ }
311
292
 
312
- rescue_body = @builder.rescue_body(val[4],
293
+ endless_command: command
294
+ | endless_command kRESCUE_MOD arg
295
+ {
296
+ rescue_body = @builder.rescue_body(val[1],
313
297
  nil, nil, nil,
314
- nil, val[5])
315
-
316
- method_body = @builder.begin_body(val[3], [ rescue_body ])
317
-
318
- result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
319
- val[1], val[2], method_body)
298
+ nil, val[2])
320
299
 
321
- local_pop
322
- @current_arg_stack.pop
323
- @context.in_def = ctx.in_def
300
+ result = @builder.begin_body(val[0], [ rescue_body ])
324
301
  }
325
- | backref tOP_ASGN command_rhs
302
+ | kNOT opt_nl endless_command
326
303
  {
327
- @builder.op_assign(val[0], val[1], val[2])
304
+ result = @builder.not_op(val[0], nil, val[2], nil)
328
305
  }
329
306
 
330
307
  command_rhs: command_call =tOP_ASGN
@@ -355,39 +332,19 @@ rule
355
332
  {
356
333
  result = @builder.not_op(val[0], nil, val[1], nil)
357
334
  }
358
- | arg tASSOC
359
- {
360
- @lexer.state = :expr_beg
361
- @lexer.command_start = false
362
- @pattern_variables.push
363
- @pattern_hash_keys.push
364
-
365
- result = @context.in_kwarg
366
- @context.in_kwarg = true
367
- }
368
- p_top_expr_body
335
+ | arg tASSOC p_in_kwarg p_pvtbl p_pktbl p_top_expr_body
369
336
  {
370
337
  @pattern_variables.pop
371
338
  @pattern_hash_keys.pop
372
339
  @context.in_kwarg = val[2]
373
- result = @builder.match_pattern(val[0], val[1], val[3])
340
+ result = @builder.match_pattern(val[0], val[1], val[5])
374
341
  }
375
- | arg kIN
376
- {
377
- @lexer.state = :expr_beg
378
- @lexer.command_start = false
379
- @pattern_variables.push
380
- @pattern_hash_keys.push
381
-
382
- result = @context.in_kwarg
383
- @context.in_kwarg = true
384
- }
385
- p_top_expr_body
342
+ | arg kIN p_in_kwarg p_pvtbl p_pktbl p_top_expr_body
386
343
  {
387
344
  @pattern_variables.pop
388
345
  @pattern_hash_keys.pop
389
346
  @context.in_kwarg = val[2]
390
- result = @builder.match_pattern_p(val[0], val[1], val[3])
347
+ result = @builder.match_pattern_p(val[0], val[1], val[5])
391
348
  }
392
349
  | arg =tLBRACE_ARG
393
350
 
@@ -409,6 +366,7 @@ rule
409
366
 
410
367
  result = [ val[0], @context.dup ]
411
368
  @context.in_def = true
369
+ @context.cant_return = false
412
370
  }
413
371
 
414
372
  defn_head: k_def def_name
@@ -492,6 +450,14 @@ rule
492
450
  result = @builder.block(method_call,
493
451
  begin_t, args, body, end_t)
494
452
  }
453
+ | primary_value tCOLON2 tCONSTANT tLCURLY brace_body tRCURLY
454
+ {
455
+ method_call = @builder.call_method(val[0], val[1], val[2],
456
+ nil, [], nil)
457
+
458
+ args, body = val[4]
459
+ result = @builder.block(method_call, val[3], args, body, val[5])
460
+ }
495
461
  | kSUPER command_args
496
462
  {
497
463
  result = @builder.keyword_cmd(:super, val[0],
@@ -926,13 +892,9 @@ rule
926
892
  {
927
893
  result = @builder.logical_op(:or, val[0], val[1], val[2])
928
894
  }
929
- | kDEFINED opt_nl
930
- {
931
- @context.in_defined = true
932
- }
933
- arg
895
+ | kDEFINED opt_nl begin_defined arg
934
896
  {
935
- @context.in_defined = false
897
+ @context.in_defined = val[2].in_defined
936
898
  result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[3] ], nil)
937
899
  }
938
900
  | arg tEH arg opt_nl tCOLON arg
@@ -940,7 +902,7 @@ rule
940
902
  result = @builder.ternary(val[0], val[1],
941
903
  val[2], val[4], val[5])
942
904
  }
943
- | defn_head f_opt_paren_args tEQL arg
905
+ | defn_head f_opt_paren_args tEQL endless_arg
944
906
  {
945
907
  def_t, (name_t, ctx) = val[0]
946
908
  endless_method_name(name_t)
@@ -952,25 +914,7 @@ rule
952
914
  @current_arg_stack.pop
953
915
  @context.in_def = ctx.in_def
954
916
  }
955
- | defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
956
- {
957
- def_t, (name_t, ctx) = val[0]
958
- endless_method_name(name_t)
959
-
960
- rescue_body = @builder.rescue_body(val[4],
961
- nil, nil, nil,
962
- nil, val[5])
963
-
964
- method_body = @builder.begin_body(val[3], [ rescue_body ])
965
-
966
- result = @builder.def_endless_method(def_t, name_t,
967
- val[1], val[2], method_body)
968
-
969
- local_pop
970
- @current_arg_stack.pop
971
- @context.in_def = ctx.in_def
972
- }
973
- | defs_head f_opt_paren_args tEQL arg
917
+ | defs_head f_opt_paren_args tEQL endless_arg
974
918
  {
975
919
  def_t, recv, dot_t, (name_t, ctx) = val[0]
976
920
  endless_method_name(name_t)
@@ -982,25 +926,21 @@ rule
982
926
  @current_arg_stack.pop
983
927
  @context.in_def = ctx.in_def
984
928
  }
985
- | defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
986
- {
987
- def_t, recv, dot_t, (name_t, ctx) = val[0]
988
- endless_method_name(name_t)
929
+ | primary
989
930
 
990
- rescue_body = @builder.rescue_body(val[4],
931
+ endless_arg: arg=kRESCUE_MOD
932
+ | endless_arg kRESCUE_MOD arg
933
+ {
934
+ rescue_body = @builder.rescue_body(val[1],
991
935
  nil, nil, nil,
992
- nil, val[5])
993
-
994
- method_body = @builder.begin_body(val[3], [ rescue_body ])
995
-
996
- result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
997
- val[1], val[2], method_body)
936
+ nil, val[2])
998
937
 
999
- local_pop
1000
- @current_arg_stack.pop
1001
- @context.in_def = ctx.in_def
938
+ result = @builder.begin_body(val[0], [ rescue_body ])
939
+ }
940
+ | kNOT opt_nl endless_arg
941
+ {
942
+ result = @builder.not_op(val[0], nil, val[2], nil)
1002
943
  }
1003
- | primary
1004
944
 
1005
945
  relop: tGT | tLT | tGEQ | tLEQ
1006
946
 
@@ -1013,6 +953,11 @@ rule
1013
953
  result = @builder.binary_op(val[0], val[1], val[2])
1014
954
  }
1015
955
 
956
+ begin_defined: none
957
+ {
958
+ result = @context.dup
959
+ }
960
+
1016
961
  arg_value: arg
1017
962
 
1018
963
  aref_args: none
@@ -1156,6 +1101,11 @@ rule
1156
1101
  diagnostic :error, :no_anonymous_blockarg, nil, val[0]
1157
1102
  end
1158
1103
 
1104
+ if @context.in_dynamic_block? && context.in_def &&
1105
+ @static_env.declared_anonymous_blockarg_in_current_scpe? && @static_env.parent_has_anonymous_blockarg?
1106
+ diagnostic :error, :ambiguous_anonymous_blockarg, nil, val[0]
1107
+ end
1108
+
1159
1109
  result = @builder.block_pass(val[0], nil)
1160
1110
  }
1161
1111
 
@@ -1172,7 +1122,17 @@ rule
1172
1122
  {
1173
1123
  result = [ val[0] ]
1174
1124
  }
1175
- | tSTAR arg_value
1125
+ | arg_splat
1126
+ | args tCOMMA arg_value
1127
+ {
1128
+ result = val[0] << val[2]
1129
+ }
1130
+ | args tCOMMA arg_splat
1131
+ {
1132
+ result = val[0].concat(val[2])
1133
+ }
1134
+
1135
+ arg_splat: tSTAR arg_value
1176
1136
  {
1177
1137
  result = [ @builder.splat(val[0], val[1]) ]
1178
1138
  }
@@ -1182,23 +1142,12 @@ rule
1182
1142
  diagnostic :error, :no_anonymous_restarg, nil, val[0]
1183
1143
  end
1184
1144
 
1185
- result = [ @builder.forwarded_restarg(val[0]) ]
1186
- }
1187
- | args tCOMMA arg_value
1188
- {
1189
- result = val[0] << val[2]
1190
- }
1191
- | args tCOMMA tSTAR arg_value
1192
- {
1193
- result = val[0] << @builder.splat(val[2], val[3])
1194
- }
1195
- | args tCOMMA tSTAR
1196
- {
1197
- if !@static_env.declared_anonymous_restarg?
1198
- diagnostic :error, :no_anonymous_restarg, nil, val[2]
1145
+ if @context.in_dynamic_block? && context.in_def &&
1146
+ @static_env.declared_anonymous_restarg_in_current_scope? && @static_env.parent_has_anonymous_restarg?
1147
+ diagnostic :error, :ambiguous_anonymous_restarg, nil, val[0]
1199
1148
  end
1200
1149
 
1201
- result = val[0] << @builder.forwarded_restarg(val[2])
1150
+ result = [ @builder.forwarded_restarg(val[0]) ]
1202
1151
  }
1203
1152
 
1204
1153
  mrhs_arg: mrhs
@@ -1244,22 +1193,14 @@ rule
1244
1193
 
1245
1194
  result = @builder.begin_keyword(val[0], val[2], val[3])
1246
1195
  }
1247
- | tLPAREN_ARG stmt
1196
+ | tLPAREN_ARG compstmt
1248
1197
  {
1249
1198
  @lexer.state = :expr_endarg
1250
1199
  }
1251
- rparen
1200
+ tRPAREN
1252
1201
  {
1253
1202
  result = @builder.begin(val[0], val[1], val[3])
1254
1203
  }
1255
- | tLPAREN_ARG
1256
- {
1257
- @lexer.state = :expr_endarg
1258
- }
1259
- opt_nl tRPAREN
1260
- {
1261
- result = @builder.begin(val[0], nil, val[3])
1262
- }
1263
1204
  | tLPAREN compstmt tRPAREN
1264
1205
  {
1265
1206
  result = @builder.begin(val[0], val[1], val[2])
@@ -1296,13 +1237,9 @@ rule
1296
1237
  {
1297
1238
  result = @builder.keyword_cmd(:yield, val[0])
1298
1239
  }
1299
- | kDEFINED opt_nl tLPAREN2
1300
- {
1301
- @context.in_defined = true
1302
- }
1303
- expr rparen
1240
+ | kDEFINED opt_nl tLPAREN2 begin_defined expr rparen
1304
1241
  {
1305
- @context.in_defined = false
1242
+ @context.in_defined = val[3].in_defined
1306
1243
  result = @builder.keyword_cmd(:defined?, val[0],
1307
1244
  val[2], [ val[4] ], val[5])
1308
1245
  }
@@ -1383,6 +1320,7 @@ rule
1383
1320
  | k_class cpath superclass
1384
1321
  {
1385
1322
  @context.in_class = true
1323
+ @context.cant_return = true
1386
1324
  local_push
1387
1325
  }
1388
1326
  bodystmt kEND
@@ -1398,11 +1336,13 @@ rule
1398
1336
 
1399
1337
  local_pop
1400
1338
  @context.in_class = ctx.in_class
1339
+ @context.cant_return = ctx.cant_return
1401
1340
  }
1402
- | k_class tLSHFT expr term
1341
+ | k_class tLSHFT expr_value term
1403
1342
  {
1404
1343
  @context.in_def = false
1405
1344
  @context.in_class = false
1345
+ @context.cant_return = true
1406
1346
  local_push
1407
1347
  }
1408
1348
  bodystmt kEND
@@ -1414,10 +1354,12 @@ rule
1414
1354
  local_pop
1415
1355
  @context.in_def = ctx.in_def
1416
1356
  @context.in_class = ctx.in_class
1357
+ @context.cant_return = ctx.cant_return
1417
1358
  }
1418
1359
  | k_module cpath
1419
1360
  {
1420
1361
  @context.in_class = true
1362
+ @context.cant_return = true
1421
1363
  local_push
1422
1364
  }
1423
1365
  bodystmt kEND
@@ -1431,6 +1373,7 @@ rule
1431
1373
 
1432
1374
  local_pop
1433
1375
  @context.in_class = ctx.in_class
1376
+ @context.cant_return = ctx.cant_return
1434
1377
  }
1435
1378
  | defn_head f_arglist bodystmt kEND
1436
1379
  {
@@ -1468,10 +1411,6 @@ rule
1468
1411
  {
1469
1412
  result = @builder.keyword_cmd(:retry, val[0])
1470
1413
  }
1471
- | primary_value tMETHREF operation2
1472
- {
1473
- result = @builder.method_ref(val[0], val[1], val[2])
1474
- }
1475
1414
 
1476
1415
  primary_value: primary
1477
1416
 
@@ -1493,7 +1432,7 @@ rule
1493
1432
 
1494
1433
  k_return: kRETURN
1495
1434
  {
1496
- if @context.in_class && !@context.in_def && !(context.in_block || context.in_lambda)
1435
+ if @context.cant_return && !(context.in_block || context.in_lambda)
1497
1436
  diagnostic :error, :invalid_return, nil, val[0]
1498
1437
  end
1499
1438
  }
@@ -1970,17 +1909,26 @@ opt_block_args_tail:
1970
1909
  }
1971
1910
  | case_body
1972
1911
 
1973
- p_case_body: kIN
1912
+ p_pvtbl: none
1974
1913
  {
1975
- @lexer.state = :expr_beg
1976
- @lexer.command_start = false
1977
1914
  @pattern_variables.push
1915
+ }
1916
+
1917
+ p_pktbl: none
1918
+ {
1978
1919
  @pattern_hash_keys.push
1920
+ }
1979
1921
 
1922
+ p_in_kwarg: none
1923
+ {
1980
1924
  result = @context.in_kwarg
1925
+
1926
+ @lexer.state = :expr_beg
1927
+ @lexer.command_start = false
1981
1928
  @context.in_kwarg = true
1982
1929
  }
1983
- p_top_expr then
1930
+
1931
+ p_case_body: kIN p_in_kwarg p_pvtbl p_pktbl p_top_expr then
1984
1932
  {
1985
1933
  @pattern_variables.pop
1986
1934
  @pattern_hash_keys.pop
@@ -1988,8 +1936,8 @@ opt_block_args_tail:
1988
1936
  }
1989
1937
  compstmt p_cases
1990
1938
  {
1991
- result = [ @builder.in_pattern(val[0], *val[2], val[3], val[5]),
1992
- *val[6] ]
1939
+ result = [ @builder.in_pattern(val[0], *val[4], val[5], val[7]),
1940
+ *val[8] ]
1993
1941
  }
1994
1942
 
1995
1943
  p_cases: opt_else
@@ -2465,6 +2413,9 @@ opt_block_args_tail:
2465
2413
  result = @builder.regexp_compose(val[0], val[1], val[2], opts)
2466
2414
  }
2467
2415
 
2416
+ words_sep: tSPACE
2417
+ | words_sep tSPACE
2418
+
2468
2419
  words: tWORDS_BEG word_list tSTRING_END
2469
2420
  {
2470
2421
  result = @builder.words_compose(val[0], val[1], val[2])
@@ -2474,7 +2425,7 @@ opt_block_args_tail:
2474
2425
  {
2475
2426
  result = []
2476
2427
  }
2477
- | word_list word tSPACE
2428
+ | word_list word words_sep
2478
2429
  {
2479
2430
  result = val[0] << @builder.word(val[1])
2480
2431
  }
@@ -2497,7 +2448,7 @@ opt_block_args_tail:
2497
2448
  {
2498
2449
  result = []
2499
2450
  }
2500
- | symbol_list word tSPACE
2451
+ | symbol_list word words_sep
2501
2452
  {
2502
2453
  result = val[0] << @builder.word(val[1])
2503
2454
  }
@@ -2516,7 +2467,7 @@ opt_block_args_tail:
2516
2467
  {
2517
2468
  result = []
2518
2469
  }
2519
- | qword_list tSTRING_CONTENT tSPACE
2470
+ | qword_list tSTRING_CONTENT words_sep
2520
2471
  {
2521
2472
  result = val[0] << @builder.string_internal(val[1])
2522
2473
  }
@@ -2525,7 +2476,7 @@ opt_block_args_tail:
2525
2476
  {
2526
2477
  result = []
2527
2478
  }
2528
- | qsym_list tSTRING_CONTENT tSPACE
2479
+ | qsym_list tSTRING_CONTENT words_sep
2529
2480
  {
2530
2481
  result = val[0] << @builder.symbol_internal(val[1])
2531
2482
  }
@@ -2570,7 +2521,7 @@ regexp_contents: # nothing
2570
2521
  @lexer.cmdarg.push(false)
2571
2522
  @lexer.cond.push(false)
2572
2523
  }
2573
- compstmt tSTRING_DEND
2524
+ compstmt string_dend
2574
2525
  {
2575
2526
  @lexer.cmdarg.pop
2576
2527
  @lexer.cond.pop
@@ -2578,17 +2529,11 @@ regexp_contents: # nothing
2578
2529
  result = @builder.begin(val[0], val[2], val[3])
2579
2530
  }
2580
2531
 
2581
- string_dvar: tGVAR
2582
- {
2583
- result = @builder.gvar(val[0])
2584
- }
2585
- | tIVAR
2586
- {
2587
- result = @builder.ivar(val[0])
2588
- }
2589
- | tCVAR
2532
+ string_dend: tSTRING_DEND
2533
+
2534
+ string_dvar: nonlocal_var
2590
2535
  {
2591
- result = @builder.cvar(val[0])
2536
+ result = @builder.accessible(val[0])
2592
2537
  }
2593
2538
  | backref
2594
2539
 
@@ -3134,6 +3079,11 @@ f_opt_paren_args: f_paren_args
3134
3079
  diagnostic :error, :no_anonymous_kwrestarg, nil, val[0]
3135
3080
  end
3136
3081
 
3082
+ if @context.in_dynamic_block? && context.in_def &&
3083
+ @static_env.declared_anonymous_kwrestarg_in_current_scope? && @static_env.parent_has_anonymous_kwrestarg?
3084
+ diagnostic :error, :ambiguous_anonymous_kwrestarg, nil, val[0]
3085
+ end
3086
+
3137
3087
  result = @builder.forwarded_kwrestarg(val[0])
3138
3088
  }
3139
3089
 
@@ -3190,7 +3140,7 @@ require 'parser/ruby-next/parser_ext'
3190
3140
  prepend Parser::NextExt
3191
3141
 
3192
3142
  def version
3193
- 33
3143
+ 34
3194
3144
  end
3195
3145
 
3196
3146
  def default_encoding
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-next-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2.0
4
+ version: 3.4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-04 00:00:00.000000000 Z
11
+ date: 2025-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -35,9 +35,6 @@ files:
35
35
  - lib/parser/ruby-next/AST_FORMAT.md
36
36
  - lib/parser/ruby-next/ast/processor.rb
37
37
  - lib/parser/ruby-next/builder.rb
38
- - lib/parser/ruby-next/lexer-F0.rb
39
- - lib/parser/ruby-next/lexer-F1.rb
40
- - lib/parser/ruby-next/lexer.rl
41
38
  - lib/parser/ruby-next/meta.rb
42
39
  - lib/parser/ruby-next/parser_ext.rb
43
40
  - lib/parser/ruby-next/version.rb
@@ -49,7 +46,7 @@ licenses:
49
46
  metadata:
50
47
  homepage_uri: http://github.com/ruby-next/parser
51
48
  source_code_uri: http://github.com/ruby-next/parser
52
- post_install_message:
49
+ post_install_message:
53
50
  rdoc_options: []
54
51
  require_paths:
55
52
  - lib
@@ -64,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
61
  - !ruby/object:Gem::Version
65
62
  version: '0'
66
63
  requirements: []
67
- rubygems_version: 3.4.20
68
- signing_key:
64
+ rubygems_version: 3.4.19
65
+ signing_key:
69
66
  specification_version: 4
70
67
  summary: Parser extension to support edge and experimental Ruby syntax
71
68
  test_files: []