parser 3.0.3.0 → 3.1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parser/all.rb +1 -0
- data/lib/parser/builders/default.rb +29 -5
- data/lib/parser/context.rb +22 -41
- data/lib/parser/current.rb +16 -7
- data/lib/parser/lexer/dedenter.rb +1 -1
- data/lib/parser/lexer/explanation.rb +1 -1
- data/lib/parser/lexer.rb +11527 -11221
- data/lib/parser/macruby.rb +2476 -2448
- data/lib/parser/max_numparam_stack.rb +5 -5
- data/lib/parser/messages.rb +2 -0
- data/lib/parser/ruby18.rb +2155 -2114
- data/lib/parser/ruby19.rb +2458 -2424
- data/lib/parser/ruby20.rb +2634 -2598
- data/lib/parser/ruby21.rb +2700 -2667
- data/lib/parser/ruby22.rb +2533 -2491
- data/lib/parser/ruby23.rb +2616 -2571
- data/lib/parser/ruby24.rb +2651 -2609
- data/lib/parser/ruby25.rb +2545 -2513
- data/lib/parser/ruby26.rb +2669 -2624
- data/lib/parser/ruby27.rb +3181 -3133
- data/lib/parser/ruby30.rb +3476 -3444
- data/lib/parser/ruby31.rb +3872 -3801
- data/lib/parser/ruby32.rb +8330 -0
- data/lib/parser/rubymotion.rb +2454 -2415
- data/lib/parser/runner.rb +6 -0
- data/lib/parser/static_environment.rb +9 -0
- data/lib/parser/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a38198be7971a87e3fbc2514f45120238a8004b1b267382a481ea971c8d9ec
|
4
|
+
data.tar.gz: ec1a2a51e94eb30280b31e5f26cb28cb1e50b94a9d3a11ae35616b79eaf11b52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e37d66e7c76e0af7d9ad1e9c3c635741436f92d0eef67032fdad83c38090c90cdb9be49018e20786ae540b24d18628695ab4b372a94c96e93b1ce36418e41da5
|
7
|
+
data.tar.gz: 9ad75e610252fb6db157948fb162b0907baedeac7c4107574b78b3869c2490afabec269ab31303ceec2a3a7f17659eb06b43e9b6677b279fb412abade076b93a
|
data/lib/parser/all.rb
CHANGED
@@ -714,7 +714,7 @@ module Parser
|
|
714
714
|
node.updated(:gvasgn)
|
715
715
|
|
716
716
|
when :const
|
717
|
-
|
717
|
+
if @parser.context.in_def
|
718
718
|
diagnostic :error, :dynamic_const, nil, node.loc.expression
|
719
719
|
end
|
720
720
|
|
@@ -879,8 +879,14 @@ module Parser
|
|
879
879
|
|
880
880
|
def args(begin_t, args, end_t, check_args=true)
|
881
881
|
args = check_duplicate_args(args) if check_args
|
882
|
-
|
883
|
-
|
882
|
+
validate_no_forward_arg_after_restarg(args)
|
883
|
+
|
884
|
+
map = collection_map(begin_t, args, end_t)
|
885
|
+
if !self.class.emit_forward_arg && args.length == 1 && args[0].type == :forward_arg
|
886
|
+
n(:forward_args, [], map)
|
887
|
+
else
|
888
|
+
n(:args, args, map)
|
889
|
+
end
|
884
890
|
end
|
885
891
|
|
886
892
|
def numargs(max_numparam)
|
@@ -967,9 +973,12 @@ module Parser
|
|
967
973
|
end
|
968
974
|
|
969
975
|
def blockarg(amper_t, name_t)
|
970
|
-
|
976
|
+
if !name_t.nil?
|
977
|
+
check_reserved_for_numparam(value(name_t), loc(name_t))
|
978
|
+
end
|
971
979
|
|
972
|
-
|
980
|
+
arg_name = name_t ? value(name_t).to_sym : nil
|
981
|
+
n(:blockarg, [ arg_name ],
|
973
982
|
arg_prefix_map(amper_t, name_t))
|
974
983
|
end
|
975
984
|
|
@@ -1744,6 +1753,21 @@ module Parser
|
|
1744
1753
|
end
|
1745
1754
|
end
|
1746
1755
|
|
1756
|
+
def validate_no_forward_arg_after_restarg(args)
|
1757
|
+
restarg = nil
|
1758
|
+
forward_arg = nil
|
1759
|
+
args.each do |arg|
|
1760
|
+
case arg.type
|
1761
|
+
when :restarg then restarg = arg
|
1762
|
+
when :forward_arg then forward_arg = arg
|
1763
|
+
end
|
1764
|
+
end
|
1765
|
+
|
1766
|
+
if !forward_arg.nil? && !restarg.nil?
|
1767
|
+
diagnostic :error, :forward_arg_after_restarg, nil, forward_arg.loc.expression, [restarg.loc.expression]
|
1768
|
+
end
|
1769
|
+
end
|
1770
|
+
|
1747
1771
|
def check_assignment_to_numparam(name, loc)
|
1748
1772
|
# MRI < 2.7 treats numbered parameters as regular variables
|
1749
1773
|
# and so it's allowed to perform assignments like `_1 = 42`.
|
data/lib/parser/context.rb
CHANGED
@@ -9,60 +9,41 @@ module Parser
|
|
9
9
|
# + :sclass - in the singleton class body (class << obj; end)
|
10
10
|
# + :def - in the method body (def m; end)
|
11
11
|
# + :defs - in the singleton method body (def self.m; end)
|
12
|
+
# + :def_open_args - in the arglist of the method definition
|
13
|
+
# keep in mind that it's set **only** after reducing the first argument,
|
14
|
+
# if you need to handle the first argument check `lex_state == expr_fname`
|
12
15
|
# + :block - in the block body (tap {})
|
13
16
|
# + :lambda - in the lambda body (-> {})
|
14
17
|
#
|
15
18
|
class Context
|
16
|
-
|
19
|
+
FLAGS = %i[
|
20
|
+
in_defined
|
21
|
+
in_kwarg
|
22
|
+
in_argdef
|
23
|
+
in_def
|
24
|
+
in_class
|
25
|
+
in_block
|
26
|
+
in_lambda
|
27
|
+
]
|
17
28
|
|
18
29
|
def initialize
|
19
|
-
|
20
|
-
freeze
|
21
|
-
end
|
22
|
-
|
23
|
-
def push(state)
|
24
|
-
@stack << state
|
25
|
-
end
|
26
|
-
|
27
|
-
def pop
|
28
|
-
@stack.pop
|
30
|
+
reset
|
29
31
|
end
|
30
32
|
|
31
33
|
def reset
|
32
|
-
@
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@
|
37
|
-
|
38
|
-
|
39
|
-
def in_class?
|
40
|
-
@stack.last == :class
|
34
|
+
@in_defined = false
|
35
|
+
@in_kwarg = false
|
36
|
+
@in_argdef = false
|
37
|
+
@in_def = false
|
38
|
+
@in_class = false
|
39
|
+
@in_block = false
|
40
|
+
@in_lambda = false
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
@stack.include?(:def) || @stack.include?(:defs)
|
45
|
-
end
|
46
|
-
|
47
|
-
def class_definition_allowed?
|
48
|
-
def_index = stack.rindex { |item| [:def, :defs].include?(item) }
|
49
|
-
sclass_index = stack.rindex(:sclass)
|
50
|
-
|
51
|
-
def_index.nil? || (!sclass_index.nil? && sclass_index > def_index)
|
52
|
-
end
|
53
|
-
alias module_definition_allowed? class_definition_allowed?
|
54
|
-
alias dynamic_const_definition_allowed? class_definition_allowed?
|
55
|
-
|
56
|
-
def in_block?
|
57
|
-
@stack.last == :block
|
58
|
-
end
|
59
|
-
|
60
|
-
def in_lambda?
|
61
|
-
@stack.last == :lambda
|
62
|
-
end
|
43
|
+
attr_accessor(*FLAGS)
|
63
44
|
|
64
45
|
def in_dynamic_block?
|
65
|
-
in_block
|
46
|
+
in_block || in_lambda
|
66
47
|
end
|
67
48
|
end
|
68
49
|
end
|
data/lib/parser/current.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
module Parser
|
4
4
|
class << self
|
5
5
|
def warn_syntax_deviation(feature, version)
|
6
|
-
warn "warning: parser/current is loading #{feature}, which recognizes"
|
7
|
-
|
8
|
-
|
6
|
+
warn "warning: parser/current is loading #{feature}, which recognizes" \
|
7
|
+
"#{version}-compliant syntax, but you are running #{RUBY_VERSION}.\n" \
|
8
|
+
"Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri."
|
9
9
|
end
|
10
10
|
private :warn_syntax_deviation
|
11
11
|
end
|
@@ -93,7 +93,7 @@ module Parser
|
|
93
93
|
CurrentRuby = Ruby30
|
94
94
|
|
95
95
|
when /^3\.1\./
|
96
|
-
current_version = '3.1.
|
96
|
+
current_version = '3.1.1'
|
97
97
|
if RUBY_VERSION != current_version
|
98
98
|
warn_syntax_deviation 'parser/ruby31', current_version
|
99
99
|
end
|
@@ -101,10 +101,19 @@ module Parser
|
|
101
101
|
require 'parser/ruby31'
|
102
102
|
CurrentRuby = Ruby31
|
103
103
|
|
104
|
+
when /^3\.2\./
|
105
|
+
current_version = '3.2.0-dev'
|
106
|
+
if RUBY_VERSION != current_version
|
107
|
+
warn_syntax_deviation 'parser/ruby32', current_version
|
108
|
+
end
|
109
|
+
|
110
|
+
require 'parser/ruby32'
|
111
|
+
CurrentRuby = Ruby32
|
112
|
+
|
104
113
|
else # :nocov:
|
105
114
|
# Keep this in sync with released Ruby.
|
106
|
-
warn_syntax_deviation 'parser/
|
107
|
-
require 'parser/
|
108
|
-
CurrentRuby =
|
115
|
+
warn_syntax_deviation 'parser/ruby31', '3.1.x'
|
116
|
+
require 'parser/ruby31'
|
117
|
+
CurrentRuby = Ruby31
|
109
118
|
end
|
110
119
|
end
|
@@ -41,7 +41,7 @@ module Parser
|
|
41
41
|
if lines.length == 1
|
42
42
|
# If the line continuation sequence was found but there is no second
|
43
43
|
# line, it was not really a line continuation and must be ignored.
|
44
|
-
lines = [string]
|
44
|
+
lines = [string.force_encoding(original_encoding)]
|
45
45
|
else
|
46
46
|
lines.map! {|s| s.force_encoding(original_encoding) }
|
47
47
|
end
|