parser 3.0.0.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.
- checksums.yaml +4 -4
- data/lib/parser/all.rb +1 -0
- data/lib/parser/builders/default.rb +72 -11
- data/lib/parser/current.rb +13 -4
- data/lib/parser/lexer/dedenter.rb +7 -1
- data/lib/parser/lexer.rb +12208 -11279
- data/lib/parser/messages.rb +2 -0
- data/lib/parser/ruby27.rb +2929 -2886
- data/lib/parser/ruby30.rb +46 -42
- data/lib/parser/ruby31.rb +8283 -0
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/source/buffer.rb +5 -0
- data/lib/parser/source/comment/associator.rb +17 -4
- data/lib/parser/source/comment.rb +13 -0
- data/lib/parser/source/tree_rewriter.rb +27 -0
- data/lib/parser/version.rb +1 -1
- metadata +7 -6
data/lib/parser/ruby30.rb
CHANGED
@@ -23,10 +23,54 @@ module Parser
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def endless_method_name(name_t)
|
26
|
-
if name_t[0].end_with?('=')
|
26
|
+
if !%w[=== == != <= >=].include?(name_t[0]) && name_t[0].end_with?('=')
|
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
|