parser 3.2.2.3 → 3.3.9.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/LICENSE.txt +2 -1
- data/lib/gauntlet_parser.rb +1 -1
- data/lib/parser/all.rb +15 -14
- data/lib/parser/ast/processor.rb +3 -1
- data/lib/parser/base.rb +3 -0
- data/lib/parser/builders/default.rb +59 -19
- data/lib/parser/context.rb +2 -0
- data/lib/parser/current.rb +37 -19
- data/lib/parser/lexer/literal.rb +16 -1
- data/lib/parser/lexer-F0.rb +360 -299
- data/lib/parser/lexer-F1.rb +634 -564
- data/lib/parser/lexer-strings.rb +89 -80
- data/lib/parser/macruby.rb +3 -3
- data/lib/parser/messages.rb +46 -41
- data/lib/parser/meta.rb +11 -3
- data/lib/parser/ruby18.rb +3 -3
- data/lib/parser/ruby19.rb +3 -3
- data/lib/parser/ruby20.rb +3 -3
- data/lib/parser/ruby21.rb +3 -3
- data/lib/parser/ruby22.rb +3 -3
- data/lib/parser/ruby23.rb +3 -3
- data/lib/parser/ruby24.rb +3 -3
- data/lib/parser/ruby25.rb +3 -3
- data/lib/parser/ruby26.rb +3 -3
- data/lib/parser/ruby27.rb +5 -4
- data/lib/parser/ruby30.rb +5 -4
- data/lib/parser/ruby31.rb +5 -4
- data/lib/parser/ruby32.rb +5 -4
- data/lib/parser/ruby33.rb +6764 -6878
- data/lib/parser/ruby34.rb +12597 -0
- data/lib/parser/rubymotion.rb +3 -3
- data/lib/parser/runner/ruby_parse.rb +3 -3
- data/lib/parser/runner/ruby_rewrite.rb +1 -1
- data/lib/parser/runner.rb +37 -31
- data/lib/parser/source/buffer.rb +6 -1
- data/lib/parser/source/comment/associator.rb +7 -7
- data/lib/parser/source/tree_rewriter/action.rb +5 -4
- data/lib/parser/static_environment.rb +56 -9
- data/lib/parser/unknown_encoding_in_magic_comment_error.rb +15 -0
- data/lib/parser/version.rb +1 -1
- data/lib/parser.rb +54 -53
- metadata +8 -10
- data/lib/parser/ruby28.rb +0 -8047
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a529863f2d1095ddbd3d559a095fe9a3e7f68c45c7765e34038bcc1d21bd1fe
|
4
|
+
data.tar.gz: 20cdfa126994051d144f0736db2ce3c4730df3af46cf32f14caa6ddefb8beb74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 421283a136846ad02588075fcb953e7b6e6659a57fb98ac5614cf25608707bfe93b6254ba00eac1eefa0c1b70a4881a2d998ba680b4fcd2c882a286bbdd56960
|
7
|
+
data.tar.gz: c65956ed457bd622862ed3654cec0f5beff551f475a45b3d5f0d519accbbcae1999f6958e924b178d3dd3d117b565c0f59db5ff3f854224fa9077e09153f22cc
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright (c) 2013-
|
1
|
+
Copyright (c) 2013-2024 parser project contributors
|
2
|
+
Copyright (c) 2013-2016 Catherine <whitequark@whitequark.org>
|
2
3
|
|
3
4
|
Parts of the source are derived from ruby_parser:
|
4
5
|
Copyright (c) Ryan Davis, seattle.rb
|
data/lib/gauntlet_parser.rb
CHANGED
data/lib/parser/all.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
require_relative 'ruby18'
|
4
|
+
require_relative 'ruby19'
|
5
|
+
require_relative 'ruby20'
|
6
|
+
require_relative 'ruby21'
|
7
|
+
require_relative 'ruby22'
|
8
|
+
require_relative 'ruby23'
|
9
|
+
require_relative 'ruby24'
|
10
|
+
require_relative 'ruby25'
|
11
|
+
require_relative 'ruby26'
|
12
|
+
require_relative 'ruby27'
|
13
|
+
require_relative 'ruby30'
|
14
|
+
require_relative 'ruby31'
|
15
|
+
require_relative 'ruby32'
|
16
|
+
require_relative 'ruby33'
|
17
|
+
require_relative 'ruby34'
|
data/lib/parser/ast/processor.rb
CHANGED
data/lib/parser/base.rb
CHANGED
@@ -426,7 +426,7 @@ module Parser
|
|
426
426
|
def regexp_compose(begin_t, parts, end_t, options)
|
427
427
|
begin
|
428
428
|
static_regexp(parts, options)
|
429
|
-
rescue RegexpError => e
|
429
|
+
rescue RegexpError, Encoding::UndefinedConversionError => e
|
430
430
|
diagnostic :error, :invalid_regexp, { :message => e.message },
|
431
431
|
loc(begin_t).join(loc(end_t))
|
432
432
|
end
|
@@ -524,10 +524,10 @@ module Parser
|
|
524
524
|
|
525
525
|
label = value(key_t)
|
526
526
|
value =
|
527
|
-
if label =~ /\A[[:
|
528
|
-
n(:ident, [ label.to_sym ], Source::Map::Variable.new(value_l))
|
529
|
-
else
|
527
|
+
if label =~ /\A[[:upper:]]/
|
530
528
|
n(:const, [ nil, label.to_sym ], Source::Map::Constant.new(nil, value_l, value_l))
|
529
|
+
else
|
530
|
+
n(:ident, [ label.to_sym ], Source::Map::Variable.new(value_l))
|
531
531
|
end
|
532
532
|
pair_keyword(key_t, accessible(value))
|
533
533
|
end
|
@@ -594,7 +594,13 @@ module Parser
|
|
594
594
|
end
|
595
595
|
|
596
596
|
def gvar(token)
|
597
|
-
|
597
|
+
gvar_name = value(token)
|
598
|
+
|
599
|
+
if gvar_name.start_with?('$0') && gvar_name.length > 2
|
600
|
+
diagnostic :error, :gvar_name, { :name => gvar_name }, loc(token)
|
601
|
+
end
|
602
|
+
|
603
|
+
n(:gvar, [ gvar_name.to_sym ],
|
598
604
|
variable_map(token))
|
599
605
|
end
|
600
606
|
|
@@ -654,6 +660,13 @@ module Parser
|
|
654
660
|
end
|
655
661
|
|
656
662
|
unless @parser.static_env.declared?(name)
|
663
|
+
if @parser.version == 33 &&
|
664
|
+
name == :it &&
|
665
|
+
@parser.context.in_block &&
|
666
|
+
!@parser.max_numparam_stack.has_ordinary_params?
|
667
|
+
diagnostic :warning, :ambiguous_it_call, nil, node.loc.expression
|
668
|
+
end
|
669
|
+
|
657
670
|
return n(:send, [ nil, name ],
|
658
671
|
var_send_map(node))
|
659
672
|
end
|
@@ -1107,15 +1120,19 @@ module Parser
|
|
1107
1120
|
end
|
1108
1121
|
|
1109
1122
|
def block(method_call, begin_t, args, body, end_t)
|
1110
|
-
_receiver, _selector, *call_args = *method_call
|
1111
|
-
|
1112
1123
|
if method_call.type == :yield
|
1113
1124
|
diagnostic :error, :block_given_to_yield, nil, method_call.loc.keyword, [loc(begin_t)]
|
1114
1125
|
end
|
1115
1126
|
|
1116
|
-
|
1127
|
+
if method_call.type == :super
|
1128
|
+
*_args, last_arg = *method_call
|
1129
|
+
else
|
1130
|
+
_receiver, _selector, *_args, last_arg = *method_call
|
1131
|
+
end
|
1117
1132
|
if last_arg && (last_arg.type == :block_pass || last_arg.type == :forwarded_args)
|
1118
|
-
|
1133
|
+
if (@parser.version == 33 && method_call.type != :super) || @parser.version != 33
|
1134
|
+
diagnostic :error, :block_and_blockarg, nil, last_arg.loc.expression, [loc(begin_t)]
|
1135
|
+
end
|
1119
1136
|
end
|
1120
1137
|
|
1121
1138
|
if args.type == :numargs
|
@@ -1179,6 +1196,10 @@ module Parser
|
|
1179
1196
|
end
|
1180
1197
|
|
1181
1198
|
def index_asgn(receiver, lbrack_t, indexes, rbrack_t)
|
1199
|
+
if self.class.emit_kwargs
|
1200
|
+
rewrite_hash_args_to_kwargs(indexes)
|
1201
|
+
end
|
1202
|
+
|
1182
1203
|
if self.class.emit_index
|
1183
1204
|
n(:indexasgn, [ receiver, *indexes ],
|
1184
1205
|
index_map(receiver, lbrack_t, rbrack_t))
|
@@ -1690,24 +1711,34 @@ module Parser
|
|
1690
1711
|
cond
|
1691
1712
|
end
|
1692
1713
|
|
1693
|
-
when :and, :or
|
1714
|
+
when :and, :or
|
1694
1715
|
lhs, rhs = *cond
|
1695
1716
|
|
1696
|
-
|
1697
|
-
when :irange then :iflipflop
|
1698
|
-
when :erange then :eflipflop
|
1699
|
-
end
|
1700
|
-
|
1701
|
-
if [:and, :or].include?(cond.type) &&
|
1702
|
-
@parser.version == 18
|
1717
|
+
if @parser.version == 18
|
1703
1718
|
cond
|
1704
1719
|
else
|
1705
|
-
cond.updated(type, [
|
1720
|
+
cond.updated(cond.type, [
|
1706
1721
|
check_condition(lhs),
|
1707
1722
|
check_condition(rhs)
|
1708
1723
|
])
|
1709
1724
|
end
|
1710
1725
|
|
1726
|
+
when :irange, :erange
|
1727
|
+
lhs, rhs = *cond
|
1728
|
+
|
1729
|
+
type = case cond.type
|
1730
|
+
when :irange then :iflipflop
|
1731
|
+
when :erange then :eflipflop
|
1732
|
+
end
|
1733
|
+
|
1734
|
+
lhs_condition = check_condition(lhs) unless lhs.nil?
|
1735
|
+
rhs_condition = check_condition(rhs) unless rhs.nil?
|
1736
|
+
|
1737
|
+
return cond.updated(type, [
|
1738
|
+
lhs_condition,
|
1739
|
+
rhs_condition
|
1740
|
+
])
|
1741
|
+
|
1711
1742
|
when :regexp
|
1712
1743
|
n(:match_current_line, [ cond ], expr_map(cond.loc.expression))
|
1713
1744
|
|
@@ -2240,11 +2271,20 @@ module Parser
|
|
2240
2271
|
source
|
2241
2272
|
end
|
2242
2273
|
|
2243
|
-
|
2274
|
+
begin
|
2275
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
2276
|
+
Regexp.new(source, (Regexp::EXTENDED if options.children.include?(:x)))
|
2277
|
+
ensure
|
2278
|
+
$VERBOSE = old_verbose
|
2279
|
+
end
|
2244
2280
|
end
|
2245
2281
|
|
2246
2282
|
def static_regexp_node(node)
|
2247
2283
|
if node.type == :regexp
|
2284
|
+
if @parser.version >= 33 && node.children[0..-2].any? { |child| child.type != :str }
|
2285
|
+
return nil
|
2286
|
+
end
|
2287
|
+
|
2248
2288
|
parts, options = node.children[0..-2], node.children[-1]
|
2249
2289
|
static_regexp(parts, options)
|
2250
2290
|
end
|
data/lib/parser/context.rb
CHANGED
@@ -24,6 +24,7 @@ module Parser
|
|
24
24
|
in_class
|
25
25
|
in_block
|
26
26
|
in_lambda
|
27
|
+
cant_return
|
27
28
|
]
|
28
29
|
|
29
30
|
def initialize
|
@@ -38,6 +39,7 @@ module Parser
|
|
38
39
|
@in_class = false
|
39
40
|
@in_block = false
|
40
41
|
@in_lambda = false
|
42
|
+
@cant_return = false
|
41
43
|
end
|
42
44
|
|
43
45
|
attr_accessor(*FLAGS)
|
data/lib/parser/current.rb
CHANGED
@@ -17,7 +17,7 @@ module Parser
|
|
17
17
|
warn_syntax_deviation 'parser/ruby20', current_version
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
require_relative 'ruby20'
|
21
21
|
CurrentRuby = Ruby20
|
22
22
|
|
23
23
|
when /^2\.1\./
|
@@ -26,7 +26,7 @@ module Parser
|
|
26
26
|
warn_syntax_deviation 'parser/ruby21', current_version
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
require_relative 'ruby21'
|
30
30
|
CurrentRuby = Ruby21
|
31
31
|
|
32
32
|
when /^2\.2\./
|
@@ -35,7 +35,7 @@ module Parser
|
|
35
35
|
warn_syntax_deviation 'parser/ruby22', current_version
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
require_relative 'ruby22'
|
39
39
|
CurrentRuby = Ruby22
|
40
40
|
|
41
41
|
when /^2\.3\./
|
@@ -44,7 +44,7 @@ module Parser
|
|
44
44
|
warn_syntax_deviation 'parser/ruby23', current_version
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
require_relative 'ruby23'
|
48
48
|
CurrentRuby = Ruby23
|
49
49
|
|
50
50
|
when /^2\.4\./
|
@@ -53,7 +53,7 @@ module Parser
|
|
53
53
|
warn_syntax_deviation 'parser/ruby24', current_version
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
require_relative 'ruby24'
|
57
57
|
CurrentRuby = Ruby24
|
58
58
|
|
59
59
|
when /^2\.5\./
|
@@ -62,7 +62,7 @@ module Parser
|
|
62
62
|
warn_syntax_deviation 'parser/ruby25', current_version
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
require_relative 'ruby25'
|
66
66
|
CurrentRuby = Ruby25
|
67
67
|
|
68
68
|
when /^2\.6\./
|
@@ -71,7 +71,7 @@ module Parser
|
|
71
71
|
warn_syntax_deviation 'parser/ruby26', current_version
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
require_relative 'ruby26'
|
75
75
|
CurrentRuby = Ruby26
|
76
76
|
|
77
77
|
when /^2\.7\./
|
@@ -80,49 +80,67 @@ module Parser
|
|
80
80
|
warn_syntax_deviation 'parser/ruby27', current_version
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
require_relative 'ruby27'
|
84
84
|
CurrentRuby = Ruby27
|
85
85
|
|
86
86
|
when /^3\.0\./
|
87
|
-
current_version = '3.0.
|
87
|
+
current_version = '3.0.7'
|
88
88
|
if RUBY_VERSION != current_version
|
89
89
|
warn_syntax_deviation 'parser/ruby30', current_version
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
require_relative 'ruby30'
|
93
93
|
CurrentRuby = Ruby30
|
94
94
|
|
95
95
|
when /^3\.1\./
|
96
|
-
current_version = '3.1.
|
96
|
+
current_version = '3.1.7'
|
97
97
|
if RUBY_VERSION != current_version
|
98
98
|
warn_syntax_deviation 'parser/ruby31', current_version
|
99
99
|
end
|
100
100
|
|
101
|
-
|
101
|
+
require_relative 'ruby31'
|
102
102
|
CurrentRuby = Ruby31
|
103
103
|
|
104
104
|
when /^3\.2\./
|
105
|
-
current_version = '3.2.
|
105
|
+
current_version = '3.2.9'
|
106
106
|
if RUBY_VERSION != current_version
|
107
107
|
warn_syntax_deviation 'parser/ruby32', current_version
|
108
108
|
end
|
109
109
|
|
110
|
-
|
110
|
+
require_relative 'ruby32'
|
111
111
|
CurrentRuby = Ruby32
|
112
112
|
|
113
113
|
when /^3\.3\./
|
114
|
-
current_version = '3.3.
|
114
|
+
current_version = '3.3.9'
|
115
115
|
if RUBY_VERSION != current_version
|
116
116
|
warn_syntax_deviation 'parser/ruby33', current_version
|
117
117
|
end
|
118
118
|
|
119
|
-
|
119
|
+
require_relative 'ruby33'
|
120
120
|
CurrentRuby = Ruby33
|
121
121
|
|
122
|
+
when /^3\.4\./
|
123
|
+
current_version = '3.4.0-dev'
|
124
|
+
if RUBY_VERSION != current_version
|
125
|
+
warn_syntax_deviation 'parser/ruby34', current_version
|
126
|
+
end
|
127
|
+
|
128
|
+
require_relative 'ruby34'
|
129
|
+
CurrentRuby = Ruby34
|
130
|
+
|
122
131
|
else # :nocov:
|
123
132
|
# Keep this in sync with released Ruby.
|
124
|
-
warn_syntax_deviation 'parser/
|
125
|
-
|
126
|
-
CurrentRuby =
|
133
|
+
warn_syntax_deviation 'parser/ruby33', '3.3.x'
|
134
|
+
require_relative 'ruby33'
|
135
|
+
CurrentRuby = Ruby33
|
127
136
|
end
|
137
|
+
# @!parse
|
138
|
+
# ##
|
139
|
+
# # @api public
|
140
|
+
# #
|
141
|
+
# # Parser for the running version of Ruby. NOTE: Supports only Ruby <= 3.3. To parse Ruby 3.4+, please use the prism gem. You can also use them in conjunction to support multiple versions using a backwards-compatible AST.
|
142
|
+
# #
|
143
|
+
# # @see https://ruby.github.io/prism/rb/docs/ruby_api_md.html prism gem documentation
|
144
|
+
# # @see https://github.com/whitequark/parser/blob/master/doc/PRISM_TRANSLATION.md Guide to using prism and parser together.
|
145
|
+
# class ::Parser::CurrentRuby < ::Parser::Base; end
|
128
146
|
end
|
data/lib/parser/lexer/literal.rb
CHANGED
@@ -5,6 +5,8 @@ module Parser
|
|
5
5
|
|
6
6
|
class Lexer::Literal
|
7
7
|
DELIMITERS = { '(' => ')', '[' => ']', '{' => '}', '<' => '>' }
|
8
|
+
SPACE = ' '.ord
|
9
|
+
TAB = "\t".ord
|
8
10
|
|
9
11
|
TYPES = {
|
10
12
|
# type start token interpolate?
|
@@ -234,7 +236,20 @@ module Parser
|
|
234
236
|
protected
|
235
237
|
|
236
238
|
def delimiter?(delimiter)
|
237
|
-
if
|
239
|
+
if heredoc?
|
240
|
+
# This heredoc is valid:
|
241
|
+
# <<~E
|
242
|
+
# E
|
243
|
+
# and this:
|
244
|
+
# <<~E
|
245
|
+
# E
|
246
|
+
# but this one is not:
|
247
|
+
# <<~' E'
|
248
|
+
# E
|
249
|
+
# because there are not enough leading spaces in the closing delimiter.
|
250
|
+
delimiter.end_with?(@end_delim) &&
|
251
|
+
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE || c == TAB }
|
252
|
+
elsif @indent
|
238
253
|
@end_delim == delimiter.lstrip
|
239
254
|
else
|
240
255
|
@end_delim == delimiter
|