ruby-next-parser 3.0.0.3 → 3.1.1.0

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.
@@ -17,7 +17,8 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
17
17
  tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DBEG
18
18
  tSTRING_DVAR tSTRING_END tSTRING_DEND tSTRING tSYMBOL
19
19
  tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA tLAMBEG tCHARACTER
20
- tRATIONAL tIMAGINARY tLABEL_END tANDDOT tMETHREF tBDOT2 tBDOT3
20
+ tRATIONAL tIMAGINARY tLABEL_END tANDDOT tBDOT2 tBDOT3
21
+ tMETHREF
21
22
 
22
23
  prechigh
23
24
  right tBANG tTILDE tUPLUS
@@ -261,6 +262,74 @@ rule
261
262
  val[0], val[1], val[2]),
262
263
  val[3], val[4])
263
264
  }
265
+ | defn_head f_opt_paren_args tEQL command
266
+ {
267
+ _def_t, name_t = val[0]
268
+ endless_method_name(name_t)
269
+
270
+ result = @builder.def_endless_method(*val[0],
271
+ val[1], val[2], val[3])
272
+
273
+ @lexer.cmdarg.pop
274
+ @lexer.cond.pop
275
+ @static_env.unextend
276
+ @context.pop
277
+ @current_arg_stack.pop
278
+ }
279
+ | defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
280
+ {
281
+ _def_t, name_t = val[0]
282
+ endless_method_name(name_t)
283
+
284
+ rescue_body = @builder.rescue_body(val[4],
285
+ nil, nil, nil,
286
+ nil, val[5])
287
+
288
+ method_body = @builder.begin_body(val[3], [ rescue_body ])
289
+
290
+ result = @builder.def_endless_method(*val[0],
291
+ val[1], val[2], method_body)
292
+
293
+ @lexer.cmdarg.pop
294
+ @lexer.cond.pop
295
+ @static_env.unextend
296
+ @context.pop
297
+ @current_arg_stack.pop
298
+ }
299
+ | defs_head f_opt_paren_args tEQL command
300
+ {
301
+ _def_t, _recv, _dot_t, name_t = val[0]
302
+ endless_method_name(name_t)
303
+
304
+ result = @builder.def_endless_singleton(*val[0],
305
+ val[1], val[2], val[3])
306
+
307
+ @lexer.cmdarg.pop
308
+ @lexer.cond.pop
309
+ @static_env.unextend
310
+ @context.pop
311
+ @current_arg_stack.pop
312
+ }
313
+ | defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
314
+ {
315
+ _def_t, _recv, _dot_t, name_t = val[0]
316
+ endless_method_name(name_t)
317
+
318
+ rescue_body = @builder.rescue_body(val[4],
319
+ nil, nil, nil,
320
+ nil, val[5])
321
+
322
+ method_body = @builder.begin_body(val[3], [ rescue_body ])
323
+
324
+ result = @builder.def_endless_singleton(*val[0],
325
+ val[1], val[2], method_body)
326
+
327
+ @lexer.cmdarg.pop
328
+ @lexer.cond.pop
329
+ @static_env.unextend
330
+ @context.pop
331
+ @current_arg_stack.pop
332
+ }
264
333
  | backref tOP_ASGN command_rhs
265
334
  {
266
335
  @builder.op_assign(val[0], val[1], val[2])
@@ -303,7 +372,7 @@ rule
303
372
  result = @lexer.in_kwarg
304
373
  @lexer.in_kwarg = true
305
374
  }
306
- p_expr
375
+ p_top_expr_body
307
376
  {
308
377
  @pattern_variables.pop
309
378
  @lexer.in_kwarg = val[2]
@@ -318,7 +387,7 @@ rule
318
387
  result = @lexer.in_kwarg
319
388
  @lexer.in_kwarg = true
320
389
  }
321
- p_expr
390
+ p_top_expr_body
322
391
  {
323
392
  @pattern_variables.pop
324
393
  @lexer.in_kwarg = val[2]
@@ -1091,6 +1160,14 @@ rule
1091
1160
  {
1092
1161
  result = @builder.block_pass(val[0], val[1])
1093
1162
  }
1163
+ | tAMPER
1164
+ {
1165
+ if !@static_env.declared_anonymous_blockarg?
1166
+ diagnostic :error, :no_anonymous_blockarg, nil, val[0]
1167
+ end
1168
+
1169
+ result = @builder.block_pass(val[0], nil)
1170
+ }
1094
1171
 
1095
1172
  opt_block_arg: tCOMMA block_arg
1096
1173
  {
@@ -1950,6 +2027,7 @@ opt_block_args_tail:
1950
2027
  }
1951
2028
 
1952
2029
  p_expr_basic: p_value
2030
+ | p_variable
1953
2031
  | p_const p_lparen p_args rparen
1954
2032
  {
1955
2033
  @pattern_hash_keys.pop
@@ -2046,23 +2124,13 @@ opt_block_args_tail:
2046
2124
  {
2047
2125
  result = [ *val[0], val[1] ]
2048
2126
  }
2049
- | p_args_head tSTAR tIDENTIFIER
2050
- {
2051
- match_rest = @builder.match_rest(val[1], val[2])
2052
- result = [ *val[0], match_rest ]
2053
- }
2054
- | p_args_head tSTAR tIDENTIFIER tCOMMA p_args_post
2127
+ | p_args_head p_rest
2055
2128
  {
2056
- match_rest = @builder.match_rest(val[1], val[2])
2057
- result = [ *val[0], match_rest, *val[4] ]
2058
- }
2059
- | p_args_head tSTAR
2060
- {
2061
- result = [ *val[0], @builder.match_rest(val[1]) ]
2129
+ result = [ *val[0], val[1] ]
2062
2130
  }
2063
- | p_args_head tSTAR tCOMMA p_args_post
2131
+ | p_args_head p_rest tCOMMA p_args_post
2064
2132
  {
2065
- result = [ *val[0], @builder.match_rest(val[1]), *val[3] ]
2133
+ result = [ *val[0], val[1], *val[3] ]
2066
2134
  }
2067
2135
  | p_args_tail
2068
2136
 
@@ -2101,6 +2169,11 @@ opt_block_args_tail:
2101
2169
  {
2102
2170
  result = @builder.match_rest(val[0], val[1])
2103
2171
  }
2172
+ | tSTAR nonlocal_var
2173
+ {
2174
+ non_lvar = @builder.accessible(val[1])
2175
+ result = @builder.match_rest(val[0], non_lvar)
2176
+ }
2104
2177
  | tSTAR
2105
2178
  {
2106
2179
  result = @builder.match_rest(val[0])
@@ -2195,8 +2268,8 @@ opt_block_args_tail:
2195
2268
  {
2196
2269
  result = @builder.range_exclusive(val[0], val[1], nil)
2197
2270
  }
2198
- | p_variable
2199
2271
  | p_var_ref
2272
+ | p_expr_ref
2200
2273
  | p_const
2201
2274
  | tBDOT2 p_primitive
2202
2275
  {
@@ -2223,7 +2296,12 @@ opt_block_args_tail:
2223
2296
 
2224
2297
  p_variable: tIDENTIFIER
2225
2298
  {
2226
- result = @builder.match_var(val[0])
2299
+ result = @builder.assignable(@builder.match_var(val[0]))
2300
+ }
2301
+ | nonlocal_var
2302
+ {
2303
+ non_lvar = @builder.accessible(val[0])
2304
+ result = @builder.assignable(@builder.match_var(non_lvar))
2227
2305
  }
2228
2306
 
2229
2307
  p_var_ref: tCARET tIDENTIFIER
@@ -2237,6 +2315,18 @@ opt_block_args_tail:
2237
2315
  result = @builder.pin(val[0], lvar)
2238
2316
  }
2239
2317
 
2318
+ | tCARET nonlocal_var
2319
+ {
2320
+ non_lvar = @builder.accessible(val[1])
2321
+ result = @builder.pin(val[0], non_lvar)
2322
+ }
2323
+
2324
+ p_expr_ref: tCARET tLPAREN expr_value tRPAREN
2325
+ {
2326
+ expr = @builder.begin(val[1], val[2], val[3])
2327
+ result = @builder.pin(val[0], expr)
2328
+ }
2329
+
2240
2330
  p_const: tCOLON3 cname
2241
2331
  {
2242
2332
  result = @builder.const_global(val[0], val[1])
@@ -2508,6 +2598,19 @@ regexp_contents: # nothing
2508
2598
  result = @builder.complex(val[0])
2509
2599
  }
2510
2600
 
2601
+ nonlocal_var: tIVAR
2602
+ {
2603
+ result = @builder.ivar(val[0])
2604
+ }
2605
+ | tGVAR
2606
+ {
2607
+ result = @builder.gvar(val[0])
2608
+ }
2609
+ | tCVAR
2610
+ {
2611
+ result = @builder.cvar(val[0])
2612
+ }
2613
+
2511
2614
  user_variable: tIDENTIFIER
2512
2615
  {
2513
2616
  result = @builder.ident(val[0])
@@ -2560,46 +2663,6 @@ keyword_variable: kNIL
2560
2663
 
2561
2664
  var_ref: user_variable
2562
2665
  {
2563
- if (node = val[0]) && node.type == :ident
2564
- name = node.children[0]
2565
-
2566
- if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
2567
- # definitely an implicit param
2568
- location = node.loc.expression
2569
-
2570
- if max_numparam_stack.has_ordinary_params?
2571
- diagnostic :error, :ordinary_param_defined, nil, [nil, location]
2572
- end
2573
-
2574
- raw_context = context.stack.dup
2575
- raw_max_numparam_stack = max_numparam_stack.stack.dup
2576
-
2577
- # ignore current block scope
2578
- raw_context.pop
2579
- raw_max_numparam_stack.pop
2580
-
2581
- raw_context.reverse_each do |outer_scope|
2582
- if outer_scope == :block || outer_scope == :lambda
2583
- outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
2584
-
2585
- if outer_scope_has_numparams
2586
- diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
2587
- else
2588
- # for now it's ok, but an outer scope can also be a block
2589
- # with numparams, so we need to continue
2590
- end
2591
- else
2592
- # found an outer scope that can't have numparams
2593
- # like def/class/etc
2594
- break
2595
- end
2596
- end
2597
-
2598
- static_env.declare(name)
2599
- max_numparam_stack.register(name[1].to_i)
2600
- end
2601
- end
2602
-
2603
2666
  result = @builder.accessible(val[0])
2604
2667
  }
2605
2668
  | keyword_variable
@@ -2648,20 +2711,6 @@ f_opt_paren_args: f_paren_args
2648
2711
  {
2649
2712
  result = @builder.args(val[0], val[1], val[2])
2650
2713
 
2651
- @lexer.state = :expr_value
2652
- }
2653
- | tLPAREN2 f_arg tCOMMA args_forward rparen
2654
- {
2655
- args = [ *val[1], @builder.forward_arg(val[3]) ]
2656
- result = @builder.args(val[0], args, val[4])
2657
-
2658
- @static_env.declare_forward_args
2659
- }
2660
- | tLPAREN2 args_forward rparen
2661
- {
2662
- result = @builder.forward_only_args(val[0], val[1], val[2])
2663
- @static_env.declare_forward_args
2664
-
2665
2714
  @lexer.state = :expr_value
2666
2715
  }
2667
2716
 
@@ -2669,9 +2718,11 @@ f_opt_paren_args: f_paren_args
2669
2718
  | {
2670
2719
  result = @lexer.in_kwarg
2671
2720
  @lexer.in_kwarg = true
2721
+ @context.push(:def_open_args)
2672
2722
  }
2673
2723
  f_args term
2674
2724
  {
2725
+ @context.pop
2675
2726
  @lexer.in_kwarg = val[0]
2676
2727
  result = @builder.args(nil, val[1], nil)
2677
2728
  }
@@ -2692,6 +2743,11 @@ f_opt_paren_args: f_paren_args
2692
2743
  {
2693
2744
  result = [ val[0] ]
2694
2745
  }
2746
+ | args_forward
2747
+ {
2748
+ @static_env.declare_forward_args
2749
+ result = [ @builder.forward_arg(val[0]) ]
2750
+ }
2695
2751
 
2696
2752
  opt_args_tail: tCOMMA args_tail
2697
2753
  {
@@ -2969,6 +3025,12 @@ f_opt_paren_args: f_paren_args
2969
3025
 
2970
3026
  result = @builder.blockarg(val[0], val[1])
2971
3027
  }
3028
+ | blkarg_mark
3029
+ {
3030
+ @static_env.declare_anonymous_blockarg
3031
+
3032
+ result = @builder.blockarg(val[0], nil)
3033
+ }
2972
3034
 
2973
3035
  opt_f_block_arg: tCOMMA f_block_arg
2974
3036
  {
@@ -2989,24 +3051,7 @@ f_opt_paren_args: f_paren_args
2989
3051
  {
2990
3052
  result = []
2991
3053
  }
2992
- | assoc_items trailer
2993
-
2994
- assoc_items : assoc_item
2995
- {
2996
- result = [ val[0] ]
2997
- }
2998
- | assoc_items tCOMMA assoc_item
2999
- {
3000
- result = val[0] << val[2]
3001
- }
3002
-
3003
- assoc_item: assoc
3004
- |
3005
- tIDENTIFIER
3006
- {
3007
- lvar = @builder.accessible(@builder.ident(val[0]))
3008
- result = @builder.ipair(lvar)
3009
- }
3054
+ | assocs trailer
3010
3055
 
3011
3056
  assocs: assoc
3012
3057
  {
@@ -3027,8 +3072,7 @@ f_opt_paren_args: f_paren_args
3027
3072
  }
3028
3073
  | tLABEL
3029
3074
  {
3030
- lvar = @builder.accessible(@builder.ident(val[0]))
3031
- result = @builder.ipair_keyword(lvar)
3075
+ result = @builder.pair_label(val[0])
3032
3076
  }
3033
3077
  | tSTRING_BEG string_contents tLABEL_END arg_value
3034
3078
  {
@@ -3092,7 +3136,7 @@ require 'parser/ruby-next/parser_ext'
3092
3136
  prepend Parser::NextExt
3093
3137
 
3094
3138
  def version
3095
- 30
3139
+ 31
3096
3140
  end
3097
3141
 
3098
3142
  def default_encoding
@@ -3100,7 +3144,51 @@ require 'parser/ruby-next/parser_ext'
3100
3144
  end
3101
3145
 
3102
3146
  def endless_method_name(name_t)
3103
- if name_t[0].end_with?('=')
3147
+ if !%w[=== == != <= >=].include?(name_t[0]) && name_t[0].end_with?('=')
3104
3148
  diagnostic :error, :endless_setter, nil, name_t
3105
3149
  end
3106
3150
  end
3151
+
3152
+ def try_declare_numparam(node)
3153
+ name = node.children[0]
3154
+
3155
+ if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
3156
+ # definitely an implicit param
3157
+ location = node.loc.expression
3158
+
3159
+ if max_numparam_stack.has_ordinary_params?
3160
+ diagnostic :error, :ordinary_param_defined, nil, [nil, location]
3161
+ end
3162
+
3163
+ raw_context = context.stack.dup
3164
+ raw_max_numparam_stack = max_numparam_stack.stack.dup
3165
+
3166
+ # ignore current block scope
3167
+ raw_context.pop
3168
+ raw_max_numparam_stack.pop
3169
+
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
3173
+
3174
+ if outer_scope_has_numparams
3175
+ diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
3176
+ else
3177
+ # for now it's ok, but an outer scope can also be a block
3178
+ # with numparams, so we need to continue
3179
+ end
3180
+ else
3181
+ # found an outer scope that can't have numparams
3182
+ # like def/class/etc
3183
+ break
3184
+ end
3185
+ end
3186
+
3187
+ static_env.declare(name)
3188
+ max_numparam_stack.register(name[1].to_i)
3189
+
3190
+ true
3191
+ else
3192
+ false
3193
+ end
3194
+ end
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.0.0.3
4
+ version: 3.1.1.0
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: 2020-12-24 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.7.2.0
19
+ version: 3.0.3.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.7.2.0
26
+ version: 3.0.3.1
27
27
  description: "\n Parser extension to support edge and experimental Ruby syntax\n
28
28
  \ "
29
29
  email:
@@ -46,9 +46,9 @@ homepage: http://github.com/ruby-next/parser
46
46
  licenses:
47
47
  - MIT
48
48
  metadata:
49
- homepage_uri: http://github.com/parser/ruby-next
50
- source_code_uri: http://github.com/parser/ruby-next
51
- post_install_message:
49
+ homepage_uri: http://github.com/ruby-next/parser
50
+ source_code_uri: http://github.com/ruby-next/parser
51
+ post_install_message:
52
52
  rdoc_options: []
53
53
  require_paths:
54
54
  - lib
@@ -63,8 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.0.6
67
- signing_key:
66
+ rubygems_version: 3.2.22
67
+ signing_key:
68
68
  specification_version: 4
69
69
  summary: Parser extension to support edge and experimental Ruby syntax
70
70
  test_files: []