prism 0.27.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/config.yml +39 -27
- data/docs/configuration.md +1 -0
- data/ext/prism/api_node.c +814 -807
- data/ext/prism/extension.c +5 -3
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +38 -16
- data/include/prism/diagnostic.h +12 -5
- data/include/prism/options.h +2 -2
- data/include/prism/parser.h +10 -0
- data/include/prism/static_literals.h +8 -6
- data/include/prism/version.h +2 -2
- data/lib/prism/dot_visitor.rb +22 -6
- data/lib/prism/dsl.rb +8 -8
- data/lib/prism/ffi.rb +3 -3
- data/lib/prism/inspect_visitor.rb +2156 -0
- data/lib/prism/lex_compat.rb +1 -1
- data/lib/prism/mutation_compiler.rb +2 -2
- data/lib/prism/node.rb +589 -1715
- data/lib/prism/node_ext.rb +34 -5
- data/lib/prism/parse_result.rb +78 -0
- data/lib/prism/pattern.rb +12 -6
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/reflection.rb +13 -13
- data/lib/prism/serialize.rb +21 -14
- data/lib/prism/translation/parser/compiler.rb +2 -2
- data/lib/prism/translation/parser.rb +6 -6
- data/lib/prism/translation/ripper.rb +13 -9
- data/lib/prism/translation/ruby_parser.rb +4 -4
- data/lib/prism.rb +2 -1
- data/prism.gemspec +36 -38
- data/rbi/prism/compiler.rbi +3 -5
- data/rbi/prism/inspect_visitor.rbi +12 -0
- data/rbi/prism/node.rbi +354 -319
- data/rbi/prism/parse_result.rbi +23 -0
- data/rbi/prism/translation/ripper.rbi +1 -11
- data/sig/prism/dsl.rbs +3 -3
- data/sig/prism/inspect_visitor.rbs +22 -0
- data/sig/prism/node.rbs +64 -47
- data/sig/prism/parse_result.rbs +12 -0
- data/src/diagnostic.c +38 -24
- data/src/node.c +41 -16
- data/src/options.c +2 -2
- data/src/prettyprint.c +61 -18
- data/src/prism.c +607 -185
- data/src/serialize.c +5 -2
- data/src/static_literals.c +120 -34
- data/src/token_type.c +4 -4
- metadata +7 -9
- data/lib/prism/node_inspector.rb +0 -68
- data/lib/prism/polyfill/string.rb +0 -12
- data/rbi/prism/desugar_compiler.rbi +0 -5
- data/rbi/prism/mutation_compiler.rbi +0 -5
- data/rbi/prism/translation/parser/compiler.rbi +0 -13
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +0 -5
- data/rbi/prism/translation/ruby_parser.rbi +0 -11
data/lib/prism/node_ext.rb
CHANGED
@@ -143,11 +143,12 @@ module Prism
|
|
143
143
|
current = self #: node?
|
144
144
|
|
145
145
|
while current.is_a?(ConstantPathNode)
|
146
|
-
|
147
|
-
if
|
146
|
+
name = current.name
|
147
|
+
if name.nil?
|
148
148
|
raise MissingNodesInConstantPathError, "Constant path contains missing nodes. Cannot compute full name"
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
|
+
parts.unshift(name)
|
151
152
|
current = current.parent
|
152
153
|
end
|
153
154
|
|
@@ -162,6 +163,20 @@ module Prism
|
|
162
163
|
def full_name
|
163
164
|
full_name_parts.join("::")
|
164
165
|
end
|
166
|
+
|
167
|
+
# Previously, we had a child node on this class that contained either a
|
168
|
+
# constant read or a missing node. To not cause a breaking change, we
|
169
|
+
# continue to supply that API.
|
170
|
+
def child
|
171
|
+
warn(<<~MSG, category: :deprecated)
|
172
|
+
DEPRECATED: ConstantPathNode#child is deprecated and will be removed \
|
173
|
+
in the next major version. Use \
|
174
|
+
ConstantPathNode#name/ConstantPathNode#name_loc instead. Called from \
|
175
|
+
#{caller(1, 1)&.first}.
|
176
|
+
MSG
|
177
|
+
|
178
|
+
name ? ConstantReadNode.new(source, name, name_loc) : MissingNode.new(source, location)
|
179
|
+
end
|
165
180
|
end
|
166
181
|
|
167
182
|
class ConstantPathTargetNode < Node
|
@@ -179,17 +194,31 @@ module Prism
|
|
179
194
|
raise ConstantPathNode::DynamicPartsInConstantPathError, "Constant target path contains dynamic parts. Cannot compute full name"
|
180
195
|
end
|
181
196
|
|
182
|
-
if
|
197
|
+
if name.nil?
|
183
198
|
raise ConstantPathNode::MissingNodesInConstantPathError, "Constant target path contains missing nodes. Cannot compute full name"
|
184
199
|
end
|
185
200
|
|
186
|
-
parts.push(
|
201
|
+
parts.push(name)
|
187
202
|
end
|
188
203
|
|
189
204
|
# Returns the full name of this constant path. For example: "Foo::Bar"
|
190
205
|
def full_name
|
191
206
|
full_name_parts.join("::")
|
192
207
|
end
|
208
|
+
|
209
|
+
# Previously, we had a child node on this class that contained either a
|
210
|
+
# constant read or a missing node. To not cause a breaking change, we
|
211
|
+
# continue to supply that API.
|
212
|
+
def child
|
213
|
+
warn(<<~MSG, category: :deprecated)
|
214
|
+
DEPRECATED: ConstantPathTargetNode#child is deprecated and will be \
|
215
|
+
removed in the next major version. Use \
|
216
|
+
ConstantPathTargetNode#name/ConstantPathTargetNode#name_loc instead. \
|
217
|
+
Called from #{caller(1, 1)&.first}.
|
218
|
+
MSG
|
219
|
+
|
220
|
+
name ? ConstantReadNode.new(source, name, name_loc) : MissingNode.new(source, location)
|
221
|
+
end
|
193
222
|
end
|
194
223
|
|
195
224
|
class ConstantTargetNode < Node
|
data/lib/prism/parse_result.rb
CHANGED
@@ -5,6 +5,14 @@ module Prism
|
|
5
5
|
# conjunction with locations to allow them to resolve line numbers and source
|
6
6
|
# ranges.
|
7
7
|
class Source
|
8
|
+
# Create a new source object with the given source code. This method should
|
9
|
+
# be used instead of `new` and it will return either a `Source` or a
|
10
|
+
# specialized and more performant `ASCIISource` if no multibyte characters
|
11
|
+
# are present in the source code.
|
12
|
+
def self.for(source, start_line = 1, offsets = [])
|
13
|
+
source.ascii_only? ? ASCIISource.new(source, start_line, offsets): new(source, start_line, offsets)
|
14
|
+
end
|
15
|
+
|
8
16
|
# The source code that this source object represents.
|
9
17
|
attr_reader :source
|
10
18
|
|
@@ -27,6 +35,11 @@ module Prism
|
|
27
35
|
source.encoding
|
28
36
|
end
|
29
37
|
|
38
|
+
# Returns the lines of the source code as an array of strings.
|
39
|
+
def lines
|
40
|
+
source.lines
|
41
|
+
end
|
42
|
+
|
30
43
|
# Perform a byteslice on the source code using the given byte offset and
|
31
44
|
# byte length.
|
32
45
|
def slice(byte_offset, length)
|
@@ -45,6 +58,12 @@ module Prism
|
|
45
58
|
offsets[find_line(byte_offset)]
|
46
59
|
end
|
47
60
|
|
61
|
+
# Returns the byte offset of the end of the line corresponding to the given
|
62
|
+
# byte offset.
|
63
|
+
def line_end(byte_offset)
|
64
|
+
offsets[find_line(byte_offset) + 1] || source.bytesize
|
65
|
+
end
|
66
|
+
|
48
67
|
# Return the column number for the given byte offset.
|
49
68
|
def column(byte_offset)
|
50
69
|
byte_offset - line_start(byte_offset)
|
@@ -100,6 +119,39 @@ module Prism
|
|
100
119
|
end
|
101
120
|
end
|
102
121
|
|
122
|
+
# Specialized version of Prism::Source for source code that includes ASCII
|
123
|
+
# characters only. This class is used to apply performance optimizations that
|
124
|
+
# cannot be applied to sources that include multibyte characters. Sources that
|
125
|
+
# include multibyte characters are represented by the Prism::Source class.
|
126
|
+
class ASCIISource < Source
|
127
|
+
# Return the character offset for the given byte offset.
|
128
|
+
def character_offset(byte_offset)
|
129
|
+
byte_offset
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return the column number in characters for the given byte offset.
|
133
|
+
def character_column(byte_offset)
|
134
|
+
byte_offset - line_start(byte_offset)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns the offset from the start of the file for the given byte offset
|
138
|
+
# counting in code units for the given encoding.
|
139
|
+
#
|
140
|
+
# This method is tested with UTF-8, UTF-16, and UTF-32. If there is the
|
141
|
+
# concept of code units that differs from the number of characters in other
|
142
|
+
# encodings, it is not captured here.
|
143
|
+
def code_units_offset(byte_offset, encoding)
|
144
|
+
byte_offset
|
145
|
+
end
|
146
|
+
|
147
|
+
# Specialized version of `code_units_column` that does not depend on
|
148
|
+
# `code_units_offset`, which is a more expensive operation. This is
|
149
|
+
# essentialy the same as `Prism::Source#column`.
|
150
|
+
def code_units_column(byte_offset, encoding)
|
151
|
+
byte_offset - line_start(byte_offset)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
103
155
|
# This represents a location in the source.
|
104
156
|
class Location
|
105
157
|
# A Source object that is used to determine more information from the given
|
@@ -171,11 +223,25 @@ module Prism
|
|
171
223
|
"#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
|
172
224
|
end
|
173
225
|
|
226
|
+
# Returns all of the lines of the source code associated with this location.
|
227
|
+
def source_lines
|
228
|
+
source.lines
|
229
|
+
end
|
230
|
+
|
174
231
|
# The source code that this location represents.
|
175
232
|
def slice
|
176
233
|
source.slice(start_offset, length)
|
177
234
|
end
|
178
235
|
|
236
|
+
# The source code that this location represents starting from the beginning
|
237
|
+
# of the line that this location starts on to the end of the line that this
|
238
|
+
# location ends on.
|
239
|
+
def slice_lines
|
240
|
+
line_start = source.line_start(start_offset)
|
241
|
+
line_end = source.line_end(end_offset)
|
242
|
+
source.slice(line_start, line_end - line_start)
|
243
|
+
end
|
244
|
+
|
179
245
|
# The character offset from the beginning of the source where this location
|
180
246
|
# starts.
|
181
247
|
def start_character_offset
|
@@ -281,6 +347,18 @@ module Prism
|
|
281
347
|
|
282
348
|
Location.new(source, start_offset, other.end_offset - start_offset)
|
283
349
|
end
|
350
|
+
|
351
|
+
# Join this location with the first occurrence of the string in the source
|
352
|
+
# that occurs after this location on the same line, and return the new
|
353
|
+
# location. This will raise an error if the string does not exist.
|
354
|
+
def adjoin(string)
|
355
|
+
line_suffix = source.slice(end_offset, source.line_end(end_offset) - end_offset)
|
356
|
+
|
357
|
+
line_suffix_index = line_suffix.byteindex(string)
|
358
|
+
raise "Could not find #{string}" if line_suffix_index.nil?
|
359
|
+
|
360
|
+
Location.new(source, start_offset, length + line_suffix_index + string.bytesize)
|
361
|
+
end
|
284
362
|
end
|
285
363
|
|
286
364
|
# This represents a comment that was encountered during parsing. It is the
|
data/lib/prism/pattern.rb
CHANGED
@@ -149,7 +149,10 @@ module Prism
|
|
149
149
|
parent = node.parent
|
150
150
|
|
151
151
|
if parent.is_a?(ConstantReadNode) && parent.slice == "Prism"
|
152
|
-
|
152
|
+
name = node.name
|
153
|
+
raise CompilationError, node.inspect if name.nil?
|
154
|
+
|
155
|
+
compile_constant_name(node, name)
|
153
156
|
else
|
154
157
|
compile_error(node)
|
155
158
|
end
|
@@ -158,14 +161,17 @@ module Prism
|
|
158
161
|
# in ConstantReadNode
|
159
162
|
# in String
|
160
163
|
def compile_constant_read_node(node)
|
161
|
-
|
164
|
+
compile_constant_name(node, node.name)
|
165
|
+
end
|
162
166
|
|
163
|
-
|
164
|
-
|
167
|
+
# Compile a name associated with a constant.
|
168
|
+
def compile_constant_name(node, name)
|
169
|
+
if Prism.const_defined?(name, false)
|
170
|
+
clazz = Prism.const_get(name)
|
165
171
|
|
166
172
|
->(other) { clazz === other }
|
167
|
-
elsif Object.const_defined?(
|
168
|
-
clazz = Object.const_get(
|
173
|
+
elsif Object.const_defined?(name, false)
|
174
|
+
clazz = Object.const_get(name)
|
169
175
|
|
170
176
|
->(other) { clazz === other }
|
171
177
|
else
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Polyfill for String#byteindex, which didn't exist until Ruby 3.2.
|
4
|
+
if !("".respond_to?(:byteindex))
|
5
|
+
String.include(
|
6
|
+
Module.new {
|
7
|
+
def byteindex(needle, offset = 0)
|
8
|
+
charindex = index(needle, offset)
|
9
|
+
slice(0...charindex).bytesize if charindex
|
10
|
+
end
|
11
|
+
}
|
12
|
+
)
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Polyfill for String#unpack1 with the offset parameter. Not all Ruby engines
|
4
|
+
# have Method#parameters implemented, so we check the arity instead if
|
5
|
+
# necessary.
|
6
|
+
if (unpack1 = String.instance_method(:unpack1)).respond_to?(:parameters) ? unpack1.parameters.none? { |_, name| name == :offset } : (unpack1.arity == 1)
|
7
|
+
String.prepend(
|
8
|
+
Module.new {
|
9
|
+
def unpack1(format, offset: 0) # :nodoc:
|
10
|
+
offset == 0 ? super(format) : self[offset..].unpack1(format) # steep:ignore
|
11
|
+
end
|
12
|
+
}
|
13
|
+
)
|
14
|
+
end
|
data/lib/prism/reflection.rb
CHANGED
@@ -112,7 +112,7 @@ module Prism
|
|
112
112
|
when :and_node
|
113
113
|
[NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
|
114
114
|
when :arguments_node
|
115
|
-
[FlagsField.new(:flags, [:contains_keyword_splat?]), NodeListField.new(:arguments)]
|
115
|
+
[FlagsField.new(:flags, [:contains_keywords?, :contains_keyword_splat?]), NodeListField.new(:arguments)]
|
116
116
|
when :array_node
|
117
117
|
[FlagsField.new(:flags, [:contains_splat?]), NodeListField.new(:elements), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
|
118
118
|
when :array_pattern_node
|
@@ -176,13 +176,13 @@ module Prism
|
|
176
176
|
when :constant_path_and_write_node
|
177
177
|
[NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
|
178
178
|
when :constant_path_node
|
179
|
-
[OptionalNodeField.new(:parent),
|
179
|
+
[OptionalNodeField.new(:parent), OptionalConstantField.new(:name), LocationField.new(:delimiter_loc), LocationField.new(:name_loc)]
|
180
180
|
when :constant_path_operator_write_node
|
181
181
|
[NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
|
182
182
|
when :constant_path_or_write_node
|
183
183
|
[NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
|
184
184
|
when :constant_path_target_node
|
185
|
-
[OptionalNodeField.new(:parent),
|
185
|
+
[OptionalNodeField.new(:parent), OptionalConstantField.new(:name), LocationField.new(:delimiter_loc), LocationField.new(:name_loc)]
|
186
186
|
when :constant_path_write_node
|
187
187
|
[NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
|
188
188
|
when :constant_read_node
|
@@ -266,7 +266,7 @@ module Prism
|
|
266
266
|
when :instance_variable_write_node
|
267
267
|
[ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
|
268
268
|
when :integer_node
|
269
|
-
[FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]),
|
269
|
+
[FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), IntegerField.new(:value)]
|
270
270
|
when :interpolated_match_last_line_node
|
271
271
|
[FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
|
272
272
|
when :interpolated_regular_expression_node
|
@@ -286,17 +286,17 @@ module Prism
|
|
286
286
|
when :lambda_node
|
287
287
|
[ConstantListField.new(:locals), LocationField.new(:operator_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body)]
|
288
288
|
when :local_variable_and_write_node
|
289
|
-
[LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name),
|
289
|
+
[LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), IntegerField.new(:depth)]
|
290
290
|
when :local_variable_operator_write_node
|
291
|
-
[LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:operator),
|
291
|
+
[LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:operator), IntegerField.new(:depth)]
|
292
292
|
when :local_variable_or_write_node
|
293
|
-
[LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name),
|
293
|
+
[LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), IntegerField.new(:depth)]
|
294
294
|
when :local_variable_read_node
|
295
|
-
[ConstantField.new(:name),
|
295
|
+
[ConstantField.new(:name), IntegerField.new(:depth)]
|
296
296
|
when :local_variable_target_node
|
297
|
-
[ConstantField.new(:name),
|
297
|
+
[ConstantField.new(:name), IntegerField.new(:depth)]
|
298
298
|
when :local_variable_write_node
|
299
|
-
[ConstantField.new(:name),
|
299
|
+
[ConstantField.new(:name), IntegerField.new(:depth), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
|
300
300
|
when :match_last_line_node
|
301
301
|
[FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
|
302
302
|
when :match_predicate_node
|
@@ -320,9 +320,9 @@ module Prism
|
|
320
320
|
when :no_keywords_parameter_node
|
321
321
|
[LocationField.new(:operator_loc), LocationField.new(:keyword_loc)]
|
322
322
|
when :numbered_parameters_node
|
323
|
-
[
|
323
|
+
[IntegerField.new(:maximum)]
|
324
324
|
when :numbered_reference_read_node
|
325
|
-
[
|
325
|
+
[IntegerField.new(:number)]
|
326
326
|
when :optional_keyword_parameter_node
|
327
327
|
[FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value)]
|
328
328
|
when :optional_parameter_node
|
@@ -364,7 +364,7 @@ module Prism
|
|
364
364
|
when :retry_node
|
365
365
|
[]
|
366
366
|
when :return_node
|
367
|
-
[LocationField.new(:keyword_loc), OptionalNodeField.new(:arguments)]
|
367
|
+
[FlagsField.new(:flags, [:redundant?]), LocationField.new(:keyword_loc), OptionalNodeField.new(:arguments)]
|
368
368
|
when :self_node
|
369
369
|
[]
|
370
370
|
when :shareable_constant_node
|
data/lib/prism/serialize.rb
CHANGED
@@ -7,7 +7,7 @@ if you are looking to modify the template
|
|
7
7
|
=end
|
8
8
|
|
9
9
|
require "stringio"
|
10
|
-
require_relative "polyfill/
|
10
|
+
require_relative "polyfill/unpack1"
|
11
11
|
|
12
12
|
module Prism
|
13
13
|
# A module responsible for deserializing parse results.
|
@@ -18,7 +18,7 @@ module Prism
|
|
18
18
|
|
19
19
|
# The minor version of prism that we are expecting to find in the serialized
|
20
20
|
# strings.
|
21
|
-
MINOR_VERSION =
|
21
|
+
MINOR_VERSION = 28
|
22
22
|
|
23
23
|
# The patch version of prism that we are expecting to find in the serialized
|
24
24
|
# strings.
|
@@ -27,7 +27,7 @@ module Prism
|
|
27
27
|
# Deserialize the AST represented by the given string into a parse result.
|
28
28
|
def self.load(input, serialized)
|
29
29
|
input = input.dup
|
30
|
-
source = Source.
|
30
|
+
source = Source.for(input)
|
31
31
|
loader = Loader.new(source, serialized)
|
32
32
|
result = loader.load_result
|
33
33
|
|
@@ -249,12 +249,13 @@ module Prism
|
|
249
249
|
:hash_rocket,
|
250
250
|
:hash_term,
|
251
251
|
:hash_value,
|
252
|
+
:heredoc_identifier,
|
252
253
|
:heredoc_term,
|
253
254
|
:incomplete_question_mark,
|
254
255
|
:incomplete_variable_class,
|
255
|
-
:
|
256
|
+
:incomplete_variable_class_3_3,
|
256
257
|
:incomplete_variable_instance,
|
257
|
-
:
|
258
|
+
:incomplete_variable_instance_3_3,
|
258
259
|
:instance_variable_bare,
|
259
260
|
:invalid_block_exit,
|
260
261
|
:invalid_character,
|
@@ -269,14 +270,16 @@ module Prism
|
|
269
270
|
:invalid_number_decimal,
|
270
271
|
:invalid_number_hexadecimal,
|
271
272
|
:invalid_number_octal,
|
272
|
-
:
|
273
|
+
:invalid_number_underscore_inner,
|
274
|
+
:invalid_number_underscore_trailing,
|
273
275
|
:invalid_percent,
|
274
276
|
:invalid_printable_character,
|
275
277
|
:invalid_retry_after_else,
|
276
278
|
:invalid_retry_after_ensure,
|
277
279
|
:invalid_retry_without_rescue,
|
280
|
+
:invalid_symbol,
|
278
281
|
:invalid_variable_global,
|
279
|
-
:
|
282
|
+
:invalid_variable_global_3_3,
|
280
283
|
:invalid_yield,
|
281
284
|
:it_not_allowed_numbered,
|
282
285
|
:it_not_allowed_ordinary,
|
@@ -320,6 +323,7 @@ module Prism
|
|
320
323
|
:parameter_star,
|
321
324
|
:parameter_unexpected_fwd,
|
322
325
|
:parameter_wild_loose_comma,
|
326
|
+
:parameter_unexpected_no_kw,
|
323
327
|
:pattern_capture_duplicate,
|
324
328
|
:pattern_expression_after_bracket,
|
325
329
|
:pattern_expression_after_comma,
|
@@ -373,6 +377,9 @@ module Prism
|
|
373
377
|
:unary_receiver,
|
374
378
|
:undef_argument,
|
375
379
|
:unexpected_block_argument,
|
380
|
+
:unexpected_index_block,
|
381
|
+
:unexpected_index_keywords,
|
382
|
+
:unexpected_safe_navigation,
|
376
383
|
:unexpected_token_close_context,
|
377
384
|
:unexpected_token_ignore,
|
378
385
|
:until_term,
|
@@ -391,7 +398,7 @@ module Prism
|
|
391
398
|
:comparison_after_comparison,
|
392
399
|
:dot_dot_dot_eol,
|
393
400
|
:equal_in_conditional,
|
394
|
-
:
|
401
|
+
:equal_in_conditional_3_3,
|
395
402
|
:end_in_method,
|
396
403
|
:duplicated_hash_key,
|
397
404
|
:duplicated_when_clause,
|
@@ -721,7 +728,7 @@ module Prism
|
|
721
728
|
source, load_node, load_location, load_node, location)
|
722
729
|
when 37 then
|
723
730
|
ConstantPathNode.new(
|
724
|
-
source, load_optional_node,
|
731
|
+
source, load_optional_node, load_optional_constant, load_location, load_location, location)
|
725
732
|
when 38 then
|
726
733
|
ConstantPathOperatorWriteNode.new(
|
727
734
|
source, load_node, load_location, load_node, load_required_constant, location)
|
@@ -730,7 +737,7 @@ module Prism
|
|
730
737
|
source, load_node, load_location, load_node, location)
|
731
738
|
when 40 then
|
732
739
|
ConstantPathTargetNode.new(
|
733
|
-
source, load_optional_node,
|
740
|
+
source, load_optional_node, load_optional_constant, load_location, load_location, location)
|
734
741
|
when 41 then
|
735
742
|
ConstantPathWriteNode.new(
|
736
743
|
source, load_node, load_location, load_node, location)
|
@@ -1004,7 +1011,7 @@ module Prism
|
|
1004
1011
|
source, location)
|
1005
1012
|
when 131 then
|
1006
1013
|
ReturnNode.new(
|
1007
|
-
source, load_location, load_optional_node, location)
|
1014
|
+
source, load_varuint, load_location, load_optional_node, location)
|
1008
1015
|
when 132 then
|
1009
1016
|
SelfNode.new(
|
1010
1017
|
source, location)
|
@@ -1256,7 +1263,7 @@ module Prism
|
|
1256
1263
|
-> {
|
1257
1264
|
location = load_location
|
1258
1265
|
ConstantPathNode.new(
|
1259
|
-
source, load_optional_node,
|
1266
|
+
source, load_optional_node, load_optional_constant, load_location, load_location, location)
|
1260
1267
|
},
|
1261
1268
|
-> {
|
1262
1269
|
location = load_location
|
@@ -1271,7 +1278,7 @@ module Prism
|
|
1271
1278
|
-> {
|
1272
1279
|
location = load_location
|
1273
1280
|
ConstantPathTargetNode.new(
|
1274
|
-
source, load_optional_node,
|
1281
|
+
source, load_optional_node, load_optional_constant, load_location, load_location, location)
|
1275
1282
|
},
|
1276
1283
|
-> {
|
1277
1284
|
location = load_location
|
@@ -1727,7 +1734,7 @@ module Prism
|
|
1727
1734
|
-> {
|
1728
1735
|
location = load_location
|
1729
1736
|
ReturnNode.new(
|
1730
|
-
source, load_location, load_optional_node, location)
|
1737
|
+
source, load_varuint, load_location, load_optional_node, location)
|
1731
1738
|
},
|
1732
1739
|
-> {
|
1733
1740
|
location = load_location
|
@@ -483,13 +483,13 @@ module Prism
|
|
483
483
|
if node.parent.nil?
|
484
484
|
builder.const_global(
|
485
485
|
token(node.delimiter_loc),
|
486
|
-
[node.
|
486
|
+
[node.name, srange(node.name_loc)]
|
487
487
|
)
|
488
488
|
else
|
489
489
|
builder.const_fetch(
|
490
490
|
visit(node.parent),
|
491
491
|
token(node.delimiter_loc),
|
492
|
-
[node.
|
492
|
+
[node.name, srange(node.name_loc)]
|
493
493
|
)
|
494
494
|
end
|
495
495
|
end
|
@@ -46,7 +46,7 @@ module Prism
|
|
46
46
|
source = source_buffer.source
|
47
47
|
|
48
48
|
offset_cache = build_offset_cache(source)
|
49
|
-
result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version)), offset_cache)
|
49
|
+
result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), scopes: [[]]), offset_cache)
|
50
50
|
|
51
51
|
build_ast(result.value, offset_cache)
|
52
52
|
ensure
|
@@ -59,7 +59,7 @@ module Prism
|
|
59
59
|
source = source_buffer.source
|
60
60
|
|
61
61
|
offset_cache = build_offset_cache(source)
|
62
|
-
result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version)), offset_cache)
|
62
|
+
result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), scopes: [[]]), offset_cache)
|
63
63
|
|
64
64
|
[
|
65
65
|
build_ast(result.value, offset_cache),
|
@@ -78,7 +78,7 @@ module Prism
|
|
78
78
|
offset_cache = build_offset_cache(source)
|
79
79
|
result =
|
80
80
|
begin
|
81
|
-
unwrap(Prism.parse_lex(source, filepath: source_buffer.name, version: convert_for_prism(version)), offset_cache)
|
81
|
+
unwrap(Prism.parse_lex(source, filepath: source_buffer.name, version: convert_for_prism(version), scopes: [[]]), offset_cache)
|
82
82
|
rescue ::Parser::SyntaxError
|
83
83
|
raise if !recover
|
84
84
|
end
|
@@ -149,17 +149,17 @@ module Prism
|
|
149
149
|
Diagnostic.new(:error, :endless_setter, {}, diagnostic_location, [])
|
150
150
|
when :embdoc_term
|
151
151
|
Diagnostic.new(:error, :embedded_document, {}, diagnostic_location, [])
|
152
|
-
when :incomplete_variable_class, :
|
152
|
+
when :incomplete_variable_class, :incomplete_variable_class_3_3
|
153
153
|
location = location.copy(length: location.length + 1)
|
154
154
|
diagnostic_location = build_range(location, offset_cache)
|
155
155
|
|
156
156
|
Diagnostic.new(:error, :cvar_name, { name: location.slice }, diagnostic_location, [])
|
157
|
-
when :incomplete_variable_instance, :
|
157
|
+
when :incomplete_variable_instance, :incomplete_variable_instance_3_3
|
158
158
|
location = location.copy(length: location.length + 1)
|
159
159
|
diagnostic_location = build_range(location, offset_cache)
|
160
160
|
|
161
161
|
Diagnostic.new(:error, :ivar_name, { name: location.slice }, diagnostic_location, [])
|
162
|
-
when :invalid_variable_global, :
|
162
|
+
when :invalid_variable_global, :invalid_variable_global_3_3
|
163
163
|
Diagnostic.new(:error, :gvar_name, { name: location.slice }, diagnostic_location, [])
|
164
164
|
when :module_in_method
|
165
165
|
Diagnostic.new(:error, :module_in_def, {}, diagnostic_location, [])
|
@@ -1456,16 +1456,16 @@ module Prism
|
|
1456
1456
|
# ^^^^^^^^
|
1457
1457
|
def visit_constant_path_node(node)
|
1458
1458
|
if node.parent.nil?
|
1459
|
-
bounds(node.
|
1460
|
-
child = on_const(node.
|
1459
|
+
bounds(node.name_loc)
|
1460
|
+
child = on_const(node.name.to_s)
|
1461
1461
|
|
1462
1462
|
bounds(node.location)
|
1463
1463
|
on_top_const_ref(child)
|
1464
1464
|
else
|
1465
1465
|
parent = visit(node.parent)
|
1466
1466
|
|
1467
|
-
bounds(node.
|
1468
|
-
child = on_const(node.
|
1467
|
+
bounds(node.name_loc)
|
1468
|
+
child = on_const(node.name.to_s)
|
1469
1469
|
|
1470
1470
|
bounds(node.location)
|
1471
1471
|
on_const_path_ref(parent, child)
|
@@ -1488,16 +1488,16 @@ module Prism
|
|
1488
1488
|
# Visit a constant path that is part of a write node.
|
1489
1489
|
private def visit_constant_path_write_node_target(node)
|
1490
1490
|
if node.parent.nil?
|
1491
|
-
bounds(node.
|
1492
|
-
child = on_const(node.
|
1491
|
+
bounds(node.name_loc)
|
1492
|
+
child = on_const(node.name.to_s)
|
1493
1493
|
|
1494
1494
|
bounds(node.location)
|
1495
1495
|
on_top_const_field(child)
|
1496
1496
|
else
|
1497
1497
|
parent = visit(node.parent)
|
1498
1498
|
|
1499
|
-
bounds(node.
|
1500
|
-
child = on_const(node.
|
1499
|
+
bounds(node.name_loc)
|
1500
|
+
child = on_const(node.name.to_s)
|
1501
1501
|
|
1502
1502
|
bounds(node.location)
|
1503
1503
|
on_const_path_field(parent, child)
|
@@ -3267,7 +3267,11 @@ module Prism
|
|
3267
3267
|
|
3268
3268
|
# Lazily initialize the parse result.
|
3269
3269
|
def result
|
3270
|
-
@result ||=
|
3270
|
+
@result ||=
|
3271
|
+
begin
|
3272
|
+
scopes = RUBY_VERSION >= "3.3.0" ? [] : [[]]
|
3273
|
+
Prism.parse(source, scopes: scopes)
|
3274
|
+
end
|
3271
3275
|
end
|
3272
3276
|
|
3273
3277
|
##########################################################################
|
@@ -442,9 +442,9 @@ module Prism
|
|
442
442
|
# ^^^^^^^^
|
443
443
|
def visit_constant_path_node(node)
|
444
444
|
if node.parent.nil?
|
445
|
-
s(node, :colon3, node.
|
445
|
+
s(node, :colon3, node.name)
|
446
446
|
else
|
447
|
-
s(node, :colon2, visit(node.parent), node.
|
447
|
+
s(node, :colon2, visit(node.parent), node.name)
|
448
448
|
end
|
449
449
|
end
|
450
450
|
|
@@ -1536,13 +1536,13 @@ module Prism
|
|
1536
1536
|
# Parse the given source and translate it into the seattlerb/ruby_parser
|
1537
1537
|
# gem's Sexp format.
|
1538
1538
|
def parse(source, filepath = "(string)")
|
1539
|
-
translate(Prism.parse(source, filepath: filepath), filepath)
|
1539
|
+
translate(Prism.parse(source, filepath: filepath, scopes: [[]]), filepath)
|
1540
1540
|
end
|
1541
1541
|
|
1542
1542
|
# Parse the given file and translate it into the seattlerb/ruby_parser
|
1543
1543
|
# gem's Sexp format.
|
1544
1544
|
def parse_file(filepath)
|
1545
|
-
translate(Prism.parse_file(filepath), filepath)
|
1545
|
+
translate(Prism.parse_file(filepath, scopes: [[]]), filepath)
|
1546
1546
|
end
|
1547
1547
|
|
1548
1548
|
class << self
|
data/lib/prism.rb
CHANGED
@@ -18,10 +18,10 @@ module Prism
|
|
18
18
|
autoload :Dispatcher, "prism/dispatcher"
|
19
19
|
autoload :DotVisitor, "prism/dot_visitor"
|
20
20
|
autoload :DSL, "prism/dsl"
|
21
|
+
autoload :InspectVisitor, "prism/inspect_visitor"
|
21
22
|
autoload :LexCompat, "prism/lex_compat"
|
22
23
|
autoload :LexRipper, "prism/lex_compat"
|
23
24
|
autoload :MutationCompiler, "prism/mutation_compiler"
|
24
|
-
autoload :NodeInspector, "prism/node_inspector"
|
25
25
|
autoload :Pack, "prism/pack"
|
26
26
|
autoload :Pattern, "prism/pattern"
|
27
27
|
autoload :Reflection, "prism/reflection"
|
@@ -67,6 +67,7 @@ module Prism
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
require_relative "prism/polyfill/byteindex"
|
70
71
|
require_relative "prism/node"
|
71
72
|
require_relative "prism/node_ext"
|
72
73
|
require_relative "prism/parse_result"
|