parser 3.0.2.0 → 3.0.3.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.
@@ -76,9 +76,11 @@ module Parser
76
76
  :duplicate_variable_name => 'duplicate variable name %{name}',
77
77
  :duplicate_pattern_key => 'duplicate hash pattern key %{name}',
78
78
  :endless_setter => 'setter method cannot be defined in an endless method definition',
79
+ :invalid_id_to_get => 'identifier %{identifier} is not valid to get',
79
80
 
80
81
  # Parser warnings
81
82
  :useless_else => 'else without rescue is useless',
83
+ :duplicate_hash_key => 'key is duplicated and overwritten',
82
84
 
83
85
  # Parser errors that are not Ruby errors
84
86
  :invalid_encoding => 'literal contains escape sequences incompatible with UTF-8',
data/lib/parser/ruby27.rb CHANGED
@@ -21,6 +21,50 @@ module Parser
21
21
  def default_encoding
22
22
  Encoding::UTF_8
23
23
  end
24
+
25
+ def try_declare_numparam(node)
26
+ name = node.children[0]
27
+
28
+ if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
29
+ # definitely an implicit param
30
+ location = node.loc.expression
31
+
32
+ if max_numparam_stack.has_ordinary_params?
33
+ diagnostic :error, :ordinary_param_defined, nil, [nil, location]
34
+ end
35
+
36
+ raw_context = context.stack.dup
37
+ raw_max_numparam_stack = max_numparam_stack.stack.dup
38
+
39
+ # ignore current block scope
40
+ raw_context.pop
41
+ raw_max_numparam_stack.pop
42
+
43
+ raw_context.reverse_each do |outer_scope|
44
+ if outer_scope == :block || outer_scope == :lambda
45
+ outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
46
+
47
+ if outer_scope_has_numparams
48
+ diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
49
+ else
50
+ # for now it's ok, but an outer scope can also be a block
51
+ # with numparams, so we need to continue
52
+ end
53
+ else
54
+ # found an outer scope that can't have numparams
55
+ # like def/class/etc
56
+ break
57
+ end
58
+ end
59
+
60
+ static_env.declare(name)
61
+ max_numparam_stack.register(name[1].to_i)
62
+
63
+ true
64
+ else
65
+ false
66
+ end
67
+ end
24
68
  ##### State transition tables begin ###
25
69
 
26
70
  clist = [
@@ -6739,7 +6783,7 @@ def _reduce_522(val, _values, result)
6739
6783
  end
6740
6784
 
6741
6785
  def _reduce_523(val, _values, result)
6742
- result = @builder.match_var(val[0])
6786
+ result = @builder.assignable(@builder.match_var(val[0]))
6743
6787
 
6744
6788
  result
6745
6789
  end
@@ -7181,46 +7225,6 @@ def _reduce_596(val, _values, result)
7181
7225
  end
7182
7226
 
7183
7227
  def _reduce_597(val, _values, result)
7184
- if (node = val[0]) && node.type == :ident
7185
- name = node.children[0]
7186
-
7187
- if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
7188
- # definitely an implicit param
7189
- location = node.loc.expression
7190
-
7191
- if max_numparam_stack.has_ordinary_params?
7192
- diagnostic :error, :ordinary_param_defined, nil, [nil, location]
7193
- end
7194
-
7195
- raw_context = context.stack.dup
7196
- raw_max_numparam_stack = max_numparam_stack.stack.dup
7197
-
7198
- # ignore current block scope
7199
- raw_context.pop
7200
- raw_max_numparam_stack.pop
7201
-
7202
- raw_context.reverse_each do |outer_scope|
7203
- if outer_scope == :block || outer_scope == :lambda
7204
- outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
7205
-
7206
- if outer_scope_has_numparams
7207
- diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
7208
- else
7209
- # for now it's ok, but an outer scope can also be a block
7210
- # with numparams, so we need to continue
7211
- end
7212
- else
7213
- # found an outer scope that can't have numparams
7214
- # like def/class/etc
7215
- break
7216
- end
7217
- end
7218
-
7219
- static_env.declare(name)
7220
- max_numparam_stack.register(name[1].to_i)
7221
- end
7222
- end
7223
-
7224
7228
  result = @builder.accessible(val[0])
7225
7229
 
7226
7230
  result
data/lib/parser/ruby30.rb CHANGED
@@ -27,6 +27,50 @@ module Parser
27
27
  diagnostic :error, :endless_setter, nil, name_t
28
28
  end
29
29
  end
30
+
31
+ def try_declare_numparam(node)
32
+ name = node.children[0]
33
+
34
+ if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
35
+ # definitely an implicit param
36
+ location = node.loc.expression
37
+
38
+ if max_numparam_stack.has_ordinary_params?
39
+ diagnostic :error, :ordinary_param_defined, nil, [nil, location]
40
+ end
41
+
42
+ raw_context = context.stack.dup
43
+ raw_max_numparam_stack = max_numparam_stack.stack.dup
44
+
45
+ # ignore current block scope
46
+ raw_context.pop
47
+ raw_max_numparam_stack.pop
48
+
49
+ raw_context.reverse_each do |outer_scope|
50
+ if outer_scope == :block || outer_scope == :lambda
51
+ outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
52
+
53
+ if outer_scope_has_numparams
54
+ diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
55
+ else
56
+ # for now it's ok, but an outer scope can also be a block
57
+ # with numparams, so we need to continue
58
+ end
59
+ else
60
+ # found an outer scope that can't have numparams
61
+ # like def/class/etc
62
+ break
63
+ end
64
+ end
65
+
66
+ static_env.declare(name)
67
+ max_numparam_stack.register(name[1].to_i)
68
+
69
+ true
70
+ else
71
+ false
72
+ end
73
+ end
30
74
  ##### State transition tables begin ###
31
75
 
32
76
  clist = [
@@ -6932,7 +6976,7 @@ end
6932
6976
  # reduce 533 omitted
6933
6977
 
6934
6978
  def _reduce_534(val, _values, result)
6935
- result = @builder.match_var(val[0])
6979
+ result = @builder.assignable(@builder.match_var(val[0]))
6936
6980
 
6937
6981
  result
6938
6982
  end
@@ -7374,46 +7418,6 @@ def _reduce_607(val, _values, result)
7374
7418
  end
7375
7419
 
7376
7420
  def _reduce_608(val, _values, result)
7377
- if (node = val[0]) && node.type == :ident
7378
- name = node.children[0]
7379
-
7380
- if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
7381
- # definitely an implicit param
7382
- location = node.loc.expression
7383
-
7384
- if max_numparam_stack.has_ordinary_params?
7385
- diagnostic :error, :ordinary_param_defined, nil, [nil, location]
7386
- end
7387
-
7388
- raw_context = context.stack.dup
7389
- raw_max_numparam_stack = max_numparam_stack.stack.dup
7390
-
7391
- # ignore current block scope
7392
- raw_context.pop
7393
- raw_max_numparam_stack.pop
7394
-
7395
- raw_context.reverse_each do |outer_scope|
7396
- if outer_scope == :block || outer_scope == :lambda
7397
- outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
7398
-
7399
- if outer_scope_has_numparams
7400
- diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
7401
- else
7402
- # for now it's ok, but an outer scope can also be a block
7403
- # with numparams, so we need to continue
7404
- end
7405
- else
7406
- # found an outer scope that can't have numparams
7407
- # like def/class/etc
7408
- break
7409
- end
7410
- end
7411
-
7412
- static_env.declare(name)
7413
- max_numparam_stack.register(name[1].to_i)
7414
- end
7415
- end
7416
-
7417
7421
  result = @builder.accessible(val[0])
7418
7422
 
7419
7423
  result