prism 0.25.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,421 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ This file is generated by the templates/template.rb script and should not be
5
+ modified manually. See templates/lib/prism/reflection.rb.erb
6
+ if you are looking to modify the template
7
+ =end
8
+
9
+ module Prism
10
+ # The Reflection module provides the ability to reflect on the structure of
11
+ # the syntax tree itself, as opposed to looking at a single syntax tree. This
12
+ # is useful in metaprogramming contexts.
13
+ module Reflection
14
+ # A field represents a single piece of data on a node. It is the base class
15
+ # for all other field types.
16
+ class Field
17
+ # The name of the field.
18
+ attr_reader :name
19
+
20
+ # Initializes the field with the given name.
21
+ def initialize(name)
22
+ @name = name
23
+ end
24
+ end
25
+
26
+ # A node field represents a single child node in the syntax tree. It
27
+ # resolves to a Prism::Node in Ruby.
28
+ class NodeField < Field
29
+ end
30
+
31
+ # An optional node field represents a single child node in the syntax tree
32
+ # that may or may not be present. It resolves to either a Prism::Node or nil
33
+ # in Ruby.
34
+ class OptionalNodeField < Field
35
+ end
36
+
37
+ # A node list field represents a list of child nodes in the syntax tree. It
38
+ # resolves to an array of Prism::Node instances in Ruby.
39
+ class NodeListField < Field
40
+ end
41
+
42
+ # A constant field represents a constant value on a node. Effectively, it
43
+ # represents an identifier found within the source. It resolves to a symbol
44
+ # in Ruby.
45
+ class ConstantField < Field
46
+ end
47
+
48
+ # An optional constant field represents a constant value on a node that may
49
+ # or may not be present. It resolves to either a symbol or nil in Ruby.
50
+ class OptionalConstantField < Field
51
+ end
52
+
53
+ # A constant list field represents a list of constant values on a node. It
54
+ # resolves to an array of symbols in Ruby.
55
+ class ConstantListField < Field
56
+ end
57
+
58
+ # A string field represents a string value on a node. It almost always
59
+ # represents the unescaped value of a string-like literal. It resolves to a
60
+ # string in Ruby.
61
+ class StringField < Field
62
+ end
63
+
64
+ # A location field represents the location of some part of the node in the
65
+ # source code. For example, the location of a keyword or an operator. It
66
+ # resolves to a Prism::Location in Ruby.
67
+ class LocationField < Field
68
+ end
69
+
70
+ # An optional location field represents the location of some part of the
71
+ # node in the source code that may or may not be present. It resolves to
72
+ # either a Prism::Location or nil in Ruby.
73
+ class OptionalLocationField < Field
74
+ end
75
+
76
+ # A uint8 field represents an unsigned 8-bit integer value on a node. It
77
+ # resolves to an Integer in Ruby.
78
+ class UInt8Field < Field
79
+ end
80
+
81
+ # A uint32 field represents an unsigned 32-bit integer value on a node. It
82
+ # resolves to an Integer in Ruby.
83
+ class UInt32Field < Field
84
+ end
85
+
86
+ # A flags field represents a bitset of flags on a node. It resolves to an
87
+ # integer in Ruby. Note that the flags cannot be accessed directly on the
88
+ # node because the integer is kept private. Instead, the various flags in
89
+ # the bitset should be accessed through their query methods.
90
+ class FlagsField < Field
91
+ # The names of the flags in the bitset.
92
+ attr_reader :flags
93
+
94
+ # Initializes the flags field with the given name and flags.
95
+ def initialize(name, flags)
96
+ super(name)
97
+ @flags = flags
98
+ end
99
+ end
100
+
101
+ # An integer field represents an arbitrarily-sized integer value. It is used
102
+ # exclusively to represent the value of an integer literal. It resolves to
103
+ # an Integer in Ruby.
104
+ class IntegerField < Field
105
+ end
106
+
107
+ # A double field represents a double-precision floating point value. It is
108
+ # used exclusively to represent the value of a floating point literal. It
109
+ # resolves to a Float in Ruby.
110
+ class DoubleField < Field
111
+ end
112
+
113
+ # Returns the fields for the given node.
114
+ def self.fields_for(node)
115
+ case node.type
116
+ when :alias_global_variable_node
117
+ [NodeField.new(:new_name), NodeField.new(:old_name), LocationField.new(:keyword_loc)]
118
+ when :alias_method_node
119
+ [NodeField.new(:new_name), NodeField.new(:old_name), LocationField.new(:keyword_loc)]
120
+ when :alternation_pattern_node
121
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
122
+ when :and_node
123
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
124
+ when :arguments_node
125
+ [FlagsField.new(:flags, [:contains_keyword_splat?]), NodeListField.new(:arguments)]
126
+ when :array_node
127
+ [FlagsField.new(:flags, [:contains_splat?]), NodeListField.new(:elements), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
128
+ when :array_pattern_node
129
+ [OptionalNodeField.new(:constant), NodeListField.new(:requireds), OptionalNodeField.new(:rest), NodeListField.new(:posts), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
130
+ when :assoc_node
131
+ [NodeField.new(:key), NodeField.new(:value), OptionalLocationField.new(:operator_loc)]
132
+ when :assoc_splat_node
133
+ [OptionalNodeField.new(:value), LocationField.new(:operator_loc)]
134
+ when :back_reference_read_node
135
+ [ConstantField.new(:name)]
136
+ when :begin_node
137
+ [OptionalLocationField.new(:begin_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:rescue_clause), OptionalNodeField.new(:else_clause), OptionalNodeField.new(:ensure_clause), OptionalLocationField.new(:end_keyword_loc)]
138
+ when :block_argument_node
139
+ [OptionalNodeField.new(:expression), LocationField.new(:operator_loc)]
140
+ when :block_local_variable_node
141
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name)]
142
+ when :block_node
143
+ [ConstantListField.new(:locals), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
144
+ when :block_parameter_node
145
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
146
+ when :block_parameters_node
147
+ [OptionalNodeField.new(:parameters), NodeListField.new(:locals), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
148
+ when :break_node
149
+ [OptionalNodeField.new(:arguments), LocationField.new(:keyword_loc)]
150
+ when :call_and_write_node
151
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), OptionalLocationField.new(:message_loc), ConstantField.new(:read_name), ConstantField.new(:write_name), LocationField.new(:operator_loc), NodeField.new(:value)]
152
+ when :call_node
153
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), ConstantField.new(:name), OptionalLocationField.new(:message_loc), OptionalLocationField.new(:opening_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:closing_loc), OptionalNodeField.new(:block)]
154
+ when :call_operator_write_node
155
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), OptionalLocationField.new(:message_loc), ConstantField.new(:read_name), ConstantField.new(:write_name), ConstantField.new(:operator), LocationField.new(:operator_loc), NodeField.new(:value)]
156
+ when :call_or_write_node
157
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), OptionalLocationField.new(:message_loc), ConstantField.new(:read_name), ConstantField.new(:write_name), LocationField.new(:operator_loc), NodeField.new(:value)]
158
+ when :call_target_node
159
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), NodeField.new(:receiver), LocationField.new(:call_operator_loc), ConstantField.new(:name), LocationField.new(:message_loc)]
160
+ when :capture_pattern_node
161
+ [NodeField.new(:value), NodeField.new(:target), LocationField.new(:operator_loc)]
162
+ when :case_match_node
163
+ [OptionalNodeField.new(:predicate), NodeListField.new(:conditions), OptionalNodeField.new(:consequent), LocationField.new(:case_keyword_loc), LocationField.new(:end_keyword_loc)]
164
+ when :case_node
165
+ [OptionalNodeField.new(:predicate), NodeListField.new(:conditions), OptionalNodeField.new(:consequent), LocationField.new(:case_keyword_loc), LocationField.new(:end_keyword_loc)]
166
+ when :class_node
167
+ [ConstantListField.new(:locals), LocationField.new(:class_keyword_loc), NodeField.new(:constant_path), OptionalLocationField.new(:inheritance_operator_loc), OptionalNodeField.new(:superclass), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc), ConstantField.new(:name)]
168
+ when :class_variable_and_write_node
169
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
170
+ when :class_variable_operator_write_node
171
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
172
+ when :class_variable_or_write_node
173
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
174
+ when :class_variable_read_node
175
+ [ConstantField.new(:name)]
176
+ when :class_variable_target_node
177
+ [ConstantField.new(:name)]
178
+ when :class_variable_write_node
179
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
180
+ when :constant_and_write_node
181
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
182
+ when :constant_operator_write_node
183
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
184
+ when :constant_or_write_node
185
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
186
+ when :constant_path_and_write_node
187
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
188
+ when :constant_path_node
189
+ [OptionalNodeField.new(:parent), NodeField.new(:child), LocationField.new(:delimiter_loc)]
190
+ when :constant_path_operator_write_node
191
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
192
+ when :constant_path_or_write_node
193
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
194
+ when :constant_path_target_node
195
+ [OptionalNodeField.new(:parent), NodeField.new(:child), LocationField.new(:delimiter_loc)]
196
+ when :constant_path_write_node
197
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
198
+ when :constant_read_node
199
+ [ConstantField.new(:name)]
200
+ when :constant_target_node
201
+ [ConstantField.new(:name)]
202
+ when :constant_write_node
203
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
204
+ when :def_node
205
+ [ConstantField.new(:name), LocationField.new(:name_loc), OptionalNodeField.new(:receiver), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body), ConstantListField.new(:locals), LocationField.new(:def_keyword_loc), OptionalLocationField.new(:operator_loc), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc), OptionalLocationField.new(:equal_loc), OptionalLocationField.new(:end_keyword_loc)]
206
+ when :defined_node
207
+ [OptionalLocationField.new(:lparen_loc), NodeField.new(:value), OptionalLocationField.new(:rparen_loc), LocationField.new(:keyword_loc)]
208
+ when :else_node
209
+ [LocationField.new(:else_keyword_loc), OptionalNodeField.new(:statements), OptionalLocationField.new(:end_keyword_loc)]
210
+ when :embedded_statements_node
211
+ [LocationField.new(:opening_loc), OptionalNodeField.new(:statements), LocationField.new(:closing_loc)]
212
+ when :embedded_variable_node
213
+ [LocationField.new(:operator_loc), NodeField.new(:variable)]
214
+ when :ensure_node
215
+ [LocationField.new(:ensure_keyword_loc), OptionalNodeField.new(:statements), LocationField.new(:end_keyword_loc)]
216
+ when :false_node
217
+ []
218
+ when :find_pattern_node
219
+ [OptionalNodeField.new(:constant), NodeField.new(:left), NodeListField.new(:requireds), NodeField.new(:right), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
220
+ when :flip_flop_node
221
+ [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
222
+ when :float_node
223
+ [DoubleField.new(:value)]
224
+ when :for_node
225
+ [NodeField.new(:index), NodeField.new(:collection), OptionalNodeField.new(:statements), LocationField.new(:for_keyword_loc), LocationField.new(:in_keyword_loc), OptionalLocationField.new(:do_keyword_loc), LocationField.new(:end_keyword_loc)]
226
+ when :forwarding_arguments_node
227
+ []
228
+ when :forwarding_parameter_node
229
+ []
230
+ when :forwarding_super_node
231
+ [OptionalNodeField.new(:block)]
232
+ when :global_variable_and_write_node
233
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
234
+ when :global_variable_operator_write_node
235
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
236
+ when :global_variable_or_write_node
237
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
238
+ when :global_variable_read_node
239
+ [ConstantField.new(:name)]
240
+ when :global_variable_target_node
241
+ [ConstantField.new(:name)]
242
+ when :global_variable_write_node
243
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
244
+ when :hash_node
245
+ [LocationField.new(:opening_loc), NodeListField.new(:elements), LocationField.new(:closing_loc)]
246
+ when :hash_pattern_node
247
+ [OptionalNodeField.new(:constant), NodeListField.new(:elements), OptionalNodeField.new(:rest), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
248
+ when :if_node
249
+ [OptionalLocationField.new(:if_keyword_loc), NodeField.new(:predicate), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:consequent), OptionalLocationField.new(:end_keyword_loc)]
250
+ when :imaginary_node
251
+ [NodeField.new(:numeric)]
252
+ when :implicit_node
253
+ [NodeField.new(:value)]
254
+ when :implicit_rest_node
255
+ []
256
+ when :in_node
257
+ [NodeField.new(:pattern), OptionalNodeField.new(:statements), LocationField.new(:in_loc), OptionalLocationField.new(:then_loc)]
258
+ when :index_and_write_node
259
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block), LocationField.new(:operator_loc), NodeField.new(:value)]
260
+ when :index_operator_write_node
261
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block), ConstantField.new(:operator), LocationField.new(:operator_loc), NodeField.new(:value)]
262
+ when :index_or_write_node
263
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block), LocationField.new(:operator_loc), NodeField.new(:value)]
264
+ when :index_target_node
265
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), NodeField.new(:receiver), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block)]
266
+ when :instance_variable_and_write_node
267
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
268
+ when :instance_variable_operator_write_node
269
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
270
+ when :instance_variable_or_write_node
271
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
272
+ when :instance_variable_read_node
273
+ [ConstantField.new(:name)]
274
+ when :instance_variable_target_node
275
+ [ConstantField.new(:name)]
276
+ when :instance_variable_write_node
277
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
278
+ when :integer_node
279
+ [FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), IntegerField.new(:value)]
280
+ when :interpolated_match_last_line_node
281
+ [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)]
282
+ when :interpolated_regular_expression_node
283
+ [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)]
284
+ when :interpolated_string_node
285
+ [FlagsField.new(:flags, [:frozen?, :mutable?]), OptionalLocationField.new(:opening_loc), NodeListField.new(:parts), OptionalLocationField.new(:closing_loc)]
286
+ when :interpolated_symbol_node
287
+ [OptionalLocationField.new(:opening_loc), NodeListField.new(:parts), OptionalLocationField.new(:closing_loc)]
288
+ when :interpolated_x_string_node
289
+ [LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
290
+ when :it_parameters_node
291
+ []
292
+ when :keyword_hash_node
293
+ [FlagsField.new(:flags, [:symbol_keys?]), NodeListField.new(:elements)]
294
+ when :keyword_rest_parameter_node
295
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
296
+ when :lambda_node
297
+ [ConstantListField.new(:locals), LocationField.new(:operator_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body)]
298
+ when :local_variable_and_write_node
299
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), UInt32Field.new(:depth)]
300
+ when :local_variable_operator_write_node
301
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:operator), UInt32Field.new(:depth)]
302
+ when :local_variable_or_write_node
303
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), UInt32Field.new(:depth)]
304
+ when :local_variable_read_node
305
+ [ConstantField.new(:name), UInt32Field.new(:depth)]
306
+ when :local_variable_target_node
307
+ [ConstantField.new(:name), UInt32Field.new(:depth)]
308
+ when :local_variable_write_node
309
+ [ConstantField.new(:name), UInt32Field.new(:depth), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
310
+ when :match_last_line_node
311
+ [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)]
312
+ when :match_predicate_node
313
+ [NodeField.new(:value), NodeField.new(:pattern), LocationField.new(:operator_loc)]
314
+ when :match_required_node
315
+ [NodeField.new(:value), NodeField.new(:pattern), LocationField.new(:operator_loc)]
316
+ when :match_write_node
317
+ [NodeField.new(:call), NodeListField.new(:targets)]
318
+ when :missing_node
319
+ []
320
+ when :module_node
321
+ [ConstantListField.new(:locals), LocationField.new(:module_keyword_loc), NodeField.new(:constant_path), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc), ConstantField.new(:name)]
322
+ when :multi_target_node
323
+ [NodeListField.new(:lefts), OptionalNodeField.new(:rest), NodeListField.new(:rights), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc)]
324
+ when :multi_write_node
325
+ [NodeListField.new(:lefts), OptionalNodeField.new(:rest), NodeListField.new(:rights), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
326
+ when :next_node
327
+ [OptionalNodeField.new(:arguments), LocationField.new(:keyword_loc)]
328
+ when :nil_node
329
+ []
330
+ when :no_keywords_parameter_node
331
+ [LocationField.new(:operator_loc), LocationField.new(:keyword_loc)]
332
+ when :numbered_parameters_node
333
+ [UInt8Field.new(:maximum)]
334
+ when :numbered_reference_read_node
335
+ [UInt32Field.new(:number)]
336
+ when :optional_keyword_parameter_node
337
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value)]
338
+ when :optional_parameter_node
339
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
340
+ when :or_node
341
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
342
+ when :parameters_node
343
+ [NodeListField.new(:requireds), NodeListField.new(:optionals), OptionalNodeField.new(:rest), NodeListField.new(:posts), NodeListField.new(:keywords), OptionalNodeField.new(:keyword_rest), OptionalNodeField.new(:block)]
344
+ when :parentheses_node
345
+ [OptionalNodeField.new(:body), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
346
+ when :pinned_expression_node
347
+ [NodeField.new(:expression), LocationField.new(:operator_loc), LocationField.new(:lparen_loc), LocationField.new(:rparen_loc)]
348
+ when :pinned_variable_node
349
+ [NodeField.new(:variable), LocationField.new(:operator_loc)]
350
+ when :post_execution_node
351
+ [OptionalNodeField.new(:statements), LocationField.new(:keyword_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
352
+ when :pre_execution_node
353
+ [OptionalNodeField.new(:statements), LocationField.new(:keyword_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
354
+ when :program_node
355
+ [ConstantListField.new(:locals), NodeField.new(:statements)]
356
+ when :range_node
357
+ [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
358
+ when :rational_node
359
+ [NodeField.new(:numeric)]
360
+ when :redo_node
361
+ []
362
+ when :regular_expression_node
363
+ [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)]
364
+ when :required_keyword_parameter_node
365
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc)]
366
+ when :required_parameter_node
367
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name)]
368
+ when :rescue_modifier_node
369
+ [NodeField.new(:expression), LocationField.new(:keyword_loc), NodeField.new(:rescue_expression)]
370
+ when :rescue_node
371
+ [LocationField.new(:keyword_loc), NodeListField.new(:exceptions), OptionalLocationField.new(:operator_loc), OptionalNodeField.new(:reference), OptionalNodeField.new(:statements), OptionalNodeField.new(:consequent)]
372
+ when :rest_parameter_node
373
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
374
+ when :retry_node
375
+ []
376
+ when :return_node
377
+ [LocationField.new(:keyword_loc), OptionalNodeField.new(:arguments)]
378
+ when :self_node
379
+ []
380
+ when :shareable_constant_node
381
+ [FlagsField.new(:flags, [:literal?, :experimental_everything?, :experimental_copy?]), NodeField.new(:write)]
382
+ when :singleton_class_node
383
+ [ConstantListField.new(:locals), LocationField.new(:class_keyword_loc), LocationField.new(:operator_loc), NodeField.new(:expression), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc)]
384
+ when :source_encoding_node
385
+ []
386
+ when :source_file_node
387
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :frozen?, :mutable?]), StringField.new(:filepath)]
388
+ when :source_line_node
389
+ []
390
+ when :splat_node
391
+ [LocationField.new(:operator_loc), OptionalNodeField.new(:expression)]
392
+ when :statements_node
393
+ [NodeListField.new(:body)]
394
+ when :string_node
395
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :frozen?, :mutable?]), OptionalLocationField.new(:opening_loc), LocationField.new(:content_loc), OptionalLocationField.new(:closing_loc), StringField.new(:unescaped)]
396
+ when :super_node
397
+ [LocationField.new(:keyword_loc), OptionalLocationField.new(:lparen_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:rparen_loc), OptionalNodeField.new(:block)]
398
+ when :symbol_node
399
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:value_loc), OptionalLocationField.new(:closing_loc), StringField.new(:unescaped)]
400
+ when :true_node
401
+ []
402
+ when :undef_node
403
+ [NodeListField.new(:names), LocationField.new(:keyword_loc)]
404
+ when :unless_node
405
+ [LocationField.new(:keyword_loc), NodeField.new(:predicate), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:consequent), OptionalLocationField.new(:end_keyword_loc)]
406
+ when :until_node
407
+ [FlagsField.new(:flags, [:begin_modifier?]), LocationField.new(:keyword_loc), OptionalLocationField.new(:closing_loc), NodeField.new(:predicate), OptionalNodeField.new(:statements)]
408
+ when :when_node
409
+ [LocationField.new(:keyword_loc), NodeListField.new(:conditions), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements)]
410
+ when :while_node
411
+ [FlagsField.new(:flags, [:begin_modifier?]), LocationField.new(:keyword_loc), OptionalLocationField.new(:closing_loc), NodeField.new(:predicate), OptionalNodeField.new(:statements)]
412
+ when :x_string_node
413
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
414
+ when :yield_node
415
+ [LocationField.new(:keyword_loc), OptionalLocationField.new(:lparen_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:rparen_loc)]
416
+ else
417
+ raise "Unknown node type: #{node.type.inspect}"
418
+ end
419
+ end
420
+ end
421
+ end
@@ -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 = 25
21
+ MINOR_VERSION = 26
22
22
 
23
23
  # The patch version of prism that we are expecting to find in the serialized
24
24
  # strings.
@@ -186,7 +186,6 @@ module Prism
186
186
  :def_endless,
187
187
  :def_endless_setter,
188
188
  :def_name,
189
- :def_name_after_receiver,
190
189
  :def_params_term,
191
190
  :def_params_term_paren,
192
191
  :def_receiver,
@@ -223,6 +222,7 @@ module Prism
223
222
  :expect_expression_after_star,
224
223
  :expect_ident_req_parameter,
225
224
  :expect_lparen_req_parameter,
225
+ :expect_message,
226
226
  :expect_rbracket,
227
227
  :expect_rparen,
228
228
  :expect_rparen_after_multi,
@@ -230,6 +230,14 @@ module Prism
230
230
  :expect_string_content,
231
231
  :expect_when_delimiter,
232
232
  :expression_bare_hash,
233
+ :expression_not_writable,
234
+ :expression_not_writable_encoding,
235
+ :expression_not_writable_false,
236
+ :expression_not_writable_file,
237
+ :expression_not_writable_line,
238
+ :expression_not_writable_nil,
239
+ :expression_not_writable_self,
240
+ :expression_not_writable_true,
233
241
  :float_parse,
234
242
  :for_collection,
235
243
  :for_in,
@@ -361,6 +369,7 @@ module Prism
361
369
  :ternary_expression_true,
362
370
  :unary_receiver,
363
371
  :undef_argument,
372
+ :unexpected_block_argument,
364
373
  :unexpected_token_close_context,
365
374
  :unexpected_token_ignore,
366
375
  :until_term,
@@ -394,7 +403,9 @@ module Prism
394
403
  :literal_in_condition_verbose,
395
404
  :shebang_carriage_return,
396
405
  :unexpected_carriage_return,
406
+ :unreachable_statement,
397
407
  :unused_local_variable,
408
+ :void_statement,
398
409
  ].freeze
399
410
 
400
411
  private_constant :DIAGNOSTIC_TYPES
@@ -947,8 +947,35 @@ module Prism
947
947
  def visit_interpolated_string_node(node)
948
948
  if node.heredoc?
949
949
  children, closing = visit_heredoc(node)
950
+ opening = token(node.opening_loc)
951
+
952
+ start_offset = node.opening_loc.end_offset + 1
953
+ end_offset = node.parts.first.location.start_offset
954
+
955
+ # In the below case, the offsets should be the same:
956
+ #
957
+ # <<~HEREDOC
958
+ # a #{b}
959
+ # HEREDOC
960
+ #
961
+ # But in this case, the end_offset would be greater than the start_offset:
962
+ #
963
+ # <<~HEREDOC
964
+ # #{b}
965
+ # HEREDOC
966
+ #
967
+ # So we need to make sure the result node's heredoc range is correct, without updating the children
968
+ result = if start_offset < end_offset
969
+ # We need to add a padding string to ensure that the heredoc has correct range for its body
970
+ padding_string_node = builder.string_internal(["", srange_offsets(start_offset, end_offset)])
971
+ node_with_correct_location = builder.string_compose(opening, [padding_string_node, *children], closing)
972
+ # But the padding string should not be included in the final AST, so we need to update the result's children
973
+ node_with_correct_location.updated(:dstr, children)
974
+ else
975
+ builder.string_compose(opening, children, closing)
976
+ end
950
977
 
951
- return builder.string_compose(token(node.opening_loc), children, closing)
978
+ return result
952
979
  end
953
980
 
954
981
  parts = if node.parts.one? { |part| part.type == :string_node }
@@ -1508,19 +1535,29 @@ module Prism
1508
1535
  elsif node.opening == "?"
1509
1536
  builder.character([node.unescaped, srange(node.location)])
1510
1537
  else
1511
- parts = if node.content.lines.count <= 1 || node.unescaped.lines.count <= 1
1512
- [builder.string_internal([node.unescaped, srange(node.content_loc)])]
1513
- else
1514
- start_offset = node.content_loc.start_offset
1538
+ content_lines = node.content.lines
1539
+ unescaped_lines = node.unescaped.lines
1515
1540
 
1516
- [node.content.lines, node.unescaped.lines].transpose.map do |content_line, unescaped_line|
1517
- end_offset = start_offset + content_line.length
1518
- offsets = srange_offsets(start_offset, end_offset)
1519
- start_offset = end_offset
1541
+ parts =
1542
+ if content_lines.length <= 1 || unescaped_lines.length <= 1
1543
+ [builder.string_internal([node.unescaped, srange(node.content_loc)])]
1544
+ elsif content_lines.length != unescaped_lines.length
1545
+ # This occurs when we have line continuations in the string. We
1546
+ # need to come back and fix this, but for now this stops the
1547
+ # code from breaking when we encounter it because of trying to
1548
+ # transpose arrays of different lengths.
1549
+ [builder.string_internal([node.unescaped, srange(node.content_loc)])]
1550
+ else
1551
+ start_offset = node.content_loc.start_offset
1520
1552
 
1521
- builder.string_internal([unescaped_line, offsets])
1553
+ [content_lines, unescaped_lines].transpose.map do |content_line, unescaped_line|
1554
+ end_offset = start_offset + content_line.length
1555
+ offsets = srange_offsets(start_offset, end_offset)
1556
+ start_offset = end_offset
1557
+
1558
+ builder.string_internal([unescaped_line, offsets])
1559
+ end
1522
1560
  end
1523
- end
1524
1561
 
1525
1562
  builder.string_compose(
1526
1563
  token(node.opening_loc),
data/lib/prism.rb CHANGED
@@ -24,6 +24,7 @@ module Prism
24
24
  autoload :NodeInspector, "prism/node_inspector"
25
25
  autoload :Pack, "prism/pack"
26
26
  autoload :Pattern, "prism/pattern"
27
+ autoload :Reflection, "prism/reflection"
27
28
  autoload :Serialize, "prism/serialize"
28
29
  autoload :Translation, "prism/translation"
29
30
  autoload :Visitor, "prism/visitor"
@@ -64,22 +65,6 @@ module Prism
64
65
  def self.load(source, serialized)
65
66
  Serialize.load(source, serialized)
66
67
  end
67
-
68
- # :call-seq:
69
- # Prism::parse_failure?(source, **options) -> bool
70
- #
71
- # Returns true if the source parses with errors.
72
- def self.parse_failure?(source, **options)
73
- !parse_success?(source, **options)
74
- end
75
-
76
- # :call-seq:
77
- # Prism::parse_file_failure?(filepath, **options) -> bool
78
- #
79
- # Returns true if the file at filepath parses with errors.
80
- def self.parse_file_failure?(filepath, **options)
81
- !parse_file_success?(filepath, **options)
82
- end
83
68
  end
84
69
 
85
70
  require_relative "prism/node"
data/prism.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prism"
5
- spec.version = "0.25.0"
5
+ spec.version = "0.26.0"
6
6
  spec.authors = ["Shopify"]
7
7
  spec.email = ["ruby@shopify.com"]
8
8
 
@@ -63,7 +63,6 @@ Gem::Specification.new do |spec|
63
63
  "include/prism/util/pm_list.h",
64
64
  "include/prism/util/pm_memchr.h",
65
65
  "include/prism/util/pm_newline_list.h",
66
- "include/prism/util/pm_state_stack.h",
67
66
  "include/prism/util/pm_strncasecmp.h",
68
67
  "include/prism/util/pm_string.h",
69
68
  "include/prism/util/pm_string_list.h",
@@ -88,6 +87,7 @@ Gem::Specification.new do |spec|
88
87
  "lib/prism/parse_result/newlines.rb",
89
88
  "lib/prism/pattern.rb",
90
89
  "lib/prism/polyfill/string.rb",
90
+ "lib/prism/reflection.rb",
91
91
  "lib/prism/serialize.rb",
92
92
  "lib/prism/translation.rb",
93
93
  "lib/prism/translation/parser.rb",
@@ -117,7 +117,6 @@ Gem::Specification.new do |spec|
117
117
  "src/util/pm_list.c",
118
118
  "src/util/pm_memchr.c",
119
119
  "src/util/pm_newline_list.c",
120
- "src/util/pm_state_stack.c",
121
120
  "src/util/pm_string.c",
122
121
  "src/util/pm_string_list.c",
123
122
  "src/util/pm_strncasecmp.c",
@@ -136,6 +135,7 @@ Gem::Specification.new do |spec|
136
135
  "sig/prism/pack.rbs",
137
136
  "sig/prism/parse_result.rbs",
138
137
  "sig/prism/pattern.rbs",
138
+ "sig/prism/reflection.rbs",
139
139
  "sig/prism/serialize.rbs",
140
140
  "sig/prism/visitor.rbs",
141
141
  "rbi/prism.rbi",
@@ -145,7 +145,11 @@ Gem::Specification.new do |spec|
145
145
  "rbi/prism/node_ext.rbi",
146
146
  "rbi/prism/node.rbi",
147
147
  "rbi/prism/parse_result.rbi",
148
+ "rbi/prism/reflection.rbi",
149
+ "rbi/prism/translation/parser.rbi",
148
150
  "rbi/prism/translation/parser/compiler.rbi",
151
+ "rbi/prism/translation/parser33.rbi",
152
+ "rbi/prism/translation/parser34.rbi",
149
153
  "rbi/prism/translation/ripper.rbi",
150
154
  "rbi/prism/translation/ripper/ripper_compiler.rbi",
151
155
  "rbi/prism/translation/ruby_parser.rbi",