prism 0.28.0 → 0.29.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 +20 -1
- data/config.yml +29 -17
- data/ext/prism/api_node.c +40 -40
- data/ext/prism/extconf.rb +27 -23
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +32 -32
- data/include/prism/diagnostic.h +11 -1
- data/include/prism/version.h +2 -2
- data/lib/prism/desugar_compiler.rb +4 -4
- data/lib/prism/dot_visitor.rb +32 -32
- data/lib/prism/dsl.rb +16 -16
- data/lib/prism/ffi.rb +1 -1
- data/lib/prism/inspect_visitor.rb +16 -16
- data/lib/prism/node.rb +148 -148
- data/lib/prism/node_ext.rb +156 -14
- data/lib/prism/parse_result/comments.rb +1 -1
- data/lib/prism/parse_result/newlines.rb +1 -1
- data/lib/prism/reflection.rb +8 -8
- data/lib/prism/serialize.rb +12 -2
- data/lib/prism/translation/parser/compiler.rb +154 -24
- data/lib/prism/translation/parser.rb +1 -1
- data/lib/prism/translation/ripper.rb +16 -16
- data/lib/prism/translation/ruby_parser.rb +9 -9
- data/prism.gemspec +2 -1
- data/rbi/prism/node.rbi +51 -51
- data/rbi/prism/node_ext.rbi +5 -0
- data/rbi/prism/parse_result.rbi +1 -1
- data/sig/prism/dsl.rbs +9 -9
- data/sig/prism/lex_compat.rbs +10 -0
- data/sig/prism/node.rbs +44 -44
- data/sig/prism/node_ext.rbs +4 -0
- data/src/diagnostic.c +30 -11
- data/src/node.c +48 -48
- data/src/prettyprint.c +48 -48
- data/src/prism.c +256 -133
- data/src/serialize.c +16 -16
- data/src/token_type.c +2 -2
- metadata +3 -2
data/lib/prism/node_ext.rb
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
# Here we are reopening the prism module to provide methods on nodes that aren't
|
4
4
|
# templated and are meant as convenience methods.
|
5
5
|
module Prism
|
6
|
+
class Node
|
7
|
+
def deprecated(*replacements) # :nodoc:
|
8
|
+
suggest = replacements.map { |replacement| "#{self.class}##{replacement}" }
|
9
|
+
warn(<<~MSG, category: :deprecated)
|
10
|
+
[deprecation]: #{self.class}##{caller_locations(1, 1)[0].label} is deprecated \
|
11
|
+
and will be removed in the next major version. Use #{suggest.join("/")} instead.
|
12
|
+
#{(caller(1, 3) || []).join("\n")}
|
13
|
+
MSG
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
6
17
|
module RegularExpressionOptions # :nodoc:
|
7
18
|
# Returns a numeric value that represents the flags that were used to create
|
8
19
|
# the regular expression.
|
@@ -168,13 +179,7 @@ module Prism
|
|
168
179
|
# constant read or a missing node. To not cause a breaking change, we
|
169
180
|
# continue to supply that API.
|
170
181
|
def child
|
171
|
-
|
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
|
-
|
182
|
+
deprecated("name", "name_loc")
|
178
183
|
name ? ConstantReadNode.new(source, name, name_loc) : MissingNode.new(source, location)
|
179
184
|
end
|
180
185
|
end
|
@@ -210,13 +215,7 @@ module Prism
|
|
210
215
|
# constant read or a missing node. To not cause a breaking change, we
|
211
216
|
# continue to supply that API.
|
212
217
|
def child
|
213
|
-
|
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
|
-
|
218
|
+
deprecated("name", "name_loc")
|
220
219
|
name ? ConstantReadNode.new(source, name, name_loc) : MissingNode.new(source, location)
|
221
220
|
end
|
222
221
|
end
|
@@ -286,4 +285,147 @@ module Prism
|
|
286
285
|
names
|
287
286
|
end
|
288
287
|
end
|
288
|
+
|
289
|
+
class CallNode < Node
|
290
|
+
# When a call node has the attribute_write flag set, it means that the call
|
291
|
+
# is using the attribute write syntax. This is either a method call to []=
|
292
|
+
# or a method call to a method that ends with =. Either way, the = sign is
|
293
|
+
# present in the source.
|
294
|
+
#
|
295
|
+
# Prism returns the message_loc _without_ the = sign attached, because there
|
296
|
+
# can be any amount of space between the message and the = sign. However,
|
297
|
+
# sometimes you want the location of the full message including the inner
|
298
|
+
# space and the = sign. This method provides that.
|
299
|
+
def full_message_loc
|
300
|
+
attribute_write? ? message_loc&.adjoin("=") : message_loc
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
class CallOperatorWriteNode < Node
|
305
|
+
# Returns the binary operator used to modify the receiver. This method is
|
306
|
+
# deprecated in favor of #binary_operator.
|
307
|
+
def operator
|
308
|
+
deprecated("binary_operator")
|
309
|
+
binary_operator
|
310
|
+
end
|
311
|
+
|
312
|
+
# Returns the location of the binary operator used to modify the receiver.
|
313
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
314
|
+
def operator_loc
|
315
|
+
deprecated("binary_operator_loc")
|
316
|
+
binary_operator_loc
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
class ClassVariableOperatorWriteNode < Node
|
321
|
+
# Returns the binary operator used to modify the receiver. This method is
|
322
|
+
# deprecated in favor of #binary_operator.
|
323
|
+
def operator
|
324
|
+
deprecated("binary_operator")
|
325
|
+
binary_operator
|
326
|
+
end
|
327
|
+
|
328
|
+
# Returns the location of the binary operator used to modify the receiver.
|
329
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
330
|
+
def operator_loc
|
331
|
+
deprecated("binary_operator_loc")
|
332
|
+
binary_operator_loc
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
class ConstantOperatorWriteNode < Node
|
337
|
+
# Returns the binary operator used to modify the receiver. This method is
|
338
|
+
# deprecated in favor of #binary_operator.
|
339
|
+
def operator
|
340
|
+
deprecated("binary_operator")
|
341
|
+
binary_operator
|
342
|
+
end
|
343
|
+
|
344
|
+
# Returns the location of the binary operator used to modify the receiver.
|
345
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
346
|
+
def operator_loc
|
347
|
+
deprecated("binary_operator_loc")
|
348
|
+
binary_operator_loc
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
class ConstantPathOperatorWriteNode < Node
|
353
|
+
# Returns the binary operator used to modify the receiver. This method is
|
354
|
+
# deprecated in favor of #binary_operator.
|
355
|
+
def operator
|
356
|
+
deprecated("binary_operator")
|
357
|
+
binary_operator
|
358
|
+
end
|
359
|
+
|
360
|
+
# Returns the location of the binary operator used to modify the receiver.
|
361
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
362
|
+
def operator_loc
|
363
|
+
deprecated("binary_operator_loc")
|
364
|
+
binary_operator_loc
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
class GlobalVariableOperatorWriteNode < Node
|
369
|
+
# Returns the binary operator used to modify the receiver. This method is
|
370
|
+
# deprecated in favor of #binary_operator.
|
371
|
+
def operator
|
372
|
+
deprecated("binary_operator")
|
373
|
+
binary_operator
|
374
|
+
end
|
375
|
+
|
376
|
+
# Returns the location of the binary operator used to modify the receiver.
|
377
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
378
|
+
def operator_loc
|
379
|
+
deprecated("binary_operator_loc")
|
380
|
+
binary_operator_loc
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
class IndexOperatorWriteNode < Node
|
385
|
+
# Returns the binary operator used to modify the receiver. This method is
|
386
|
+
# deprecated in favor of #binary_operator.
|
387
|
+
def operator
|
388
|
+
deprecated("binary_operator")
|
389
|
+
binary_operator
|
390
|
+
end
|
391
|
+
|
392
|
+
# Returns the location of the binary operator used to modify the receiver.
|
393
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
394
|
+
def operator_loc
|
395
|
+
deprecated("binary_operator_loc")
|
396
|
+
binary_operator_loc
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
class InstanceVariableOperatorWriteNode < Node
|
401
|
+
# Returns the binary operator used to modify the receiver. This method is
|
402
|
+
# deprecated in favor of #binary_operator.
|
403
|
+
def operator
|
404
|
+
deprecated("binary_operator")
|
405
|
+
binary_operator
|
406
|
+
end
|
407
|
+
|
408
|
+
# Returns the location of the binary operator used to modify the receiver.
|
409
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
410
|
+
def operator_loc
|
411
|
+
deprecated("binary_operator_loc")
|
412
|
+
binary_operator_loc
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
class LocalVariableOperatorWriteNode < Node
|
417
|
+
# Returns the binary operator used to modify the receiver. This method is
|
418
|
+
# deprecated in favor of #binary_operator.
|
419
|
+
def operator
|
420
|
+
deprecated("binary_operator")
|
421
|
+
binary_operator
|
422
|
+
end
|
423
|
+
|
424
|
+
# Returns the location of the binary operator used to modify the receiver.
|
425
|
+
# This method is deprecated in favor of #binary_operator_loc.
|
426
|
+
def operator_loc
|
427
|
+
deprecated("binary_operator_loc")
|
428
|
+
binary_operator_loc
|
429
|
+
end
|
430
|
+
end
|
289
431
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Prism
|
4
|
-
class ParseResult
|
4
|
+
class ParseResult < Result
|
5
5
|
# When we've parsed the source, we have both the syntax tree and the list of
|
6
6
|
# comments that we found in the source. This class is responsible for
|
7
7
|
# walking the tree and finding the nearest location to attach each comment.
|
data/lib/prism/reflection.rb
CHANGED
@@ -142,7 +142,7 @@ module Prism
|
|
142
142
|
when :call_node
|
143
143
|
[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)]
|
144
144
|
when :call_operator_write_node
|
145
|
-
[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(:
|
145
|
+
[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(:binary_operator), LocationField.new(:binary_operator_loc), NodeField.new(:value)]
|
146
146
|
when :call_or_write_node
|
147
147
|
[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)]
|
148
148
|
when :call_target_node
|
@@ -158,7 +158,7 @@ module Prism
|
|
158
158
|
when :class_variable_and_write_node
|
159
159
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
160
160
|
when :class_variable_operator_write_node
|
161
|
-
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:
|
161
|
+
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
|
162
162
|
when :class_variable_or_write_node
|
163
163
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
164
164
|
when :class_variable_read_node
|
@@ -170,7 +170,7 @@ module Prism
|
|
170
170
|
when :constant_and_write_node
|
171
171
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
172
172
|
when :constant_operator_write_node
|
173
|
-
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:
|
173
|
+
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
|
174
174
|
when :constant_or_write_node
|
175
175
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
176
176
|
when :constant_path_and_write_node
|
@@ -178,7 +178,7 @@ module Prism
|
|
178
178
|
when :constant_path_node
|
179
179
|
[OptionalNodeField.new(:parent), OptionalConstantField.new(:name), LocationField.new(:delimiter_loc), LocationField.new(:name_loc)]
|
180
180
|
when :constant_path_operator_write_node
|
181
|
-
[NodeField.new(:target), LocationField.new(:
|
181
|
+
[NodeField.new(:target), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_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
|
@@ -222,7 +222,7 @@ module Prism
|
|
222
222
|
when :global_variable_and_write_node
|
223
223
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
224
224
|
when :global_variable_operator_write_node
|
225
|
-
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:
|
225
|
+
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
|
226
226
|
when :global_variable_or_write_node
|
227
227
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
228
228
|
when :global_variable_read_node
|
@@ -248,7 +248,7 @@ module Prism
|
|
248
248
|
when :index_and_write_node
|
249
249
|
[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)]
|
250
250
|
when :index_operator_write_node
|
251
|
-
[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(:
|
251
|
+
[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(:binary_operator), LocationField.new(:binary_operator_loc), NodeField.new(:value)]
|
252
252
|
when :index_or_write_node
|
253
253
|
[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)]
|
254
254
|
when :index_target_node
|
@@ -256,7 +256,7 @@ module Prism
|
|
256
256
|
when :instance_variable_and_write_node
|
257
257
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
258
258
|
when :instance_variable_operator_write_node
|
259
|
-
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:
|
259
|
+
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
|
260
260
|
when :instance_variable_or_write_node
|
261
261
|
[ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
|
262
262
|
when :instance_variable_read_node
|
@@ -288,7 +288,7 @@ module Prism
|
|
288
288
|
when :local_variable_and_write_node
|
289
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(:
|
291
|
+
[LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:binary_operator), IntegerField.new(:depth)]
|
292
292
|
when :local_variable_or_write_node
|
293
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
|
data/lib/prism/serialize.rb
CHANGED
@@ -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 = 29
|
22
22
|
|
23
23
|
# The patch version of prism that we are expecting to find in the serialized
|
24
24
|
# strings.
|
@@ -133,13 +133,16 @@ module Prism
|
|
133
133
|
:argument_bare_hash,
|
134
134
|
:argument_block_forwarding,
|
135
135
|
:argument_block_multi,
|
136
|
+
:argument_conflict_ampersand,
|
137
|
+
:argument_conflict_star,
|
138
|
+
:argument_conflict_star_star,
|
136
139
|
:argument_formal_class,
|
137
140
|
:argument_formal_constant,
|
138
141
|
:argument_formal_global,
|
139
142
|
:argument_formal_ivar,
|
140
143
|
:argument_forwarding_unbound,
|
141
144
|
:argument_in,
|
142
|
-
:
|
145
|
+
:argument_no_forwarding_ampersand,
|
143
146
|
:argument_no_forwarding_ellipses,
|
144
147
|
:argument_no_forwarding_star,
|
145
148
|
:argument_no_forwarding_star_star,
|
@@ -221,6 +224,7 @@ module Prism
|
|
221
224
|
:expect_expression_after_splat_hash,
|
222
225
|
:expect_expression_after_star,
|
223
226
|
:expect_ident_req_parameter,
|
227
|
+
:expect_in_delimiter,
|
224
228
|
:expect_lparen_req_parameter,
|
225
229
|
:expect_message,
|
226
230
|
:expect_rbracket,
|
@@ -260,6 +264,7 @@ module Prism
|
|
260
264
|
:invalid_block_exit,
|
261
265
|
:invalid_character,
|
262
266
|
:invalid_encoding_magic_comment,
|
267
|
+
:invalid_escape_character,
|
263
268
|
:invalid_float_exponent,
|
264
269
|
:invalid_local_variable_read,
|
265
270
|
:invalid_local_variable_write,
|
@@ -268,6 +273,7 @@ module Prism
|
|
268
273
|
:invalid_multibyte_escape,
|
269
274
|
:invalid_number_binary,
|
270
275
|
:invalid_number_decimal,
|
276
|
+
:invalid_number_fraction,
|
271
277
|
:invalid_number_hexadecimal,
|
272
278
|
:invalid_number_octal,
|
273
279
|
:invalid_number_underscore_inner,
|
@@ -313,6 +319,7 @@ module Prism
|
|
313
319
|
:parameter_assoc_splat_multi,
|
314
320
|
:parameter_block_multi,
|
315
321
|
:parameter_circular,
|
322
|
+
:parameter_forwarding_after_rest,
|
316
323
|
:parameter_method_name,
|
317
324
|
:parameter_name_duplicated,
|
318
325
|
:parameter_no_default,
|
@@ -335,8 +342,10 @@ module Prism
|
|
335
342
|
:pattern_expression_after_pipe,
|
336
343
|
:pattern_expression_after_range,
|
337
344
|
:pattern_expression_after_rest,
|
345
|
+
:pattern_hash_implicit,
|
338
346
|
:pattern_hash_key,
|
339
347
|
:pattern_hash_key_duplicate,
|
348
|
+
:pattern_hash_key_interpolated,
|
340
349
|
:pattern_hash_key_label,
|
341
350
|
:pattern_hash_key_locals,
|
342
351
|
:pattern_ident_after_hrocket,
|
@@ -411,6 +420,7 @@ module Prism
|
|
411
420
|
:keyword_eol,
|
412
421
|
:literal_in_condition_default,
|
413
422
|
:literal_in_condition_verbose,
|
423
|
+
:shareable_constant_value_line,
|
414
424
|
:shebang_carriage_return,
|
415
425
|
:unexpected_carriage_return,
|
416
426
|
:unreachable_statement,
|
@@ -328,18 +328,48 @@ module Prism
|
|
328
328
|
[],
|
329
329
|
nil
|
330
330
|
),
|
331
|
-
[node.
|
331
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
332
332
|
visit(node.value)
|
333
333
|
)
|
334
334
|
end
|
335
335
|
|
336
336
|
# foo.bar &&= baz
|
337
337
|
# ^^^^^^^^^^^^^^^
|
338
|
-
|
338
|
+
def visit_call_and_write_node(node)
|
339
|
+
call_operator_loc = node.call_operator_loc
|
340
|
+
|
341
|
+
builder.op_assign(
|
342
|
+
builder.call_method(
|
343
|
+
visit(node.receiver),
|
344
|
+
call_operator_loc.nil? ? nil : [{ "." => :dot, "&." => :anddot, "::" => "::" }.fetch(call_operator_loc.slice), srange(call_operator_loc)],
|
345
|
+
node.message_loc ? [node.read_name, srange(node.message_loc)] : nil,
|
346
|
+
nil,
|
347
|
+
[],
|
348
|
+
nil
|
349
|
+
),
|
350
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
351
|
+
visit(node.value)
|
352
|
+
)
|
353
|
+
end
|
339
354
|
|
340
355
|
# foo.bar ||= baz
|
341
356
|
# ^^^^^^^^^^^^^^^
|
342
|
-
|
357
|
+
def visit_call_or_write_node(node)
|
358
|
+
call_operator_loc = node.call_operator_loc
|
359
|
+
|
360
|
+
builder.op_assign(
|
361
|
+
builder.call_method(
|
362
|
+
visit(node.receiver),
|
363
|
+
call_operator_loc.nil? ? nil : [{ "." => :dot, "&." => :anddot, "::" => "::" }.fetch(call_operator_loc.slice), srange(call_operator_loc)],
|
364
|
+
node.message_loc ? [node.read_name, srange(node.message_loc)] : nil,
|
365
|
+
nil,
|
366
|
+
[],
|
367
|
+
nil
|
368
|
+
),
|
369
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
370
|
+
visit(node.value)
|
371
|
+
)
|
372
|
+
end
|
343
373
|
|
344
374
|
# foo.bar, = 1
|
345
375
|
# ^^^^^^^
|
@@ -419,18 +449,30 @@ module Prism
|
|
419
449
|
def visit_class_variable_operator_write_node(node)
|
420
450
|
builder.op_assign(
|
421
451
|
builder.assignable(builder.cvar(token(node.name_loc))),
|
422
|
-
[node.
|
452
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
423
453
|
visit(node.value)
|
424
454
|
)
|
425
455
|
end
|
426
456
|
|
427
457
|
# @@foo &&= bar
|
428
458
|
# ^^^^^^^^^^^^^
|
429
|
-
|
459
|
+
def visit_class_variable_and_write_node(node)
|
460
|
+
builder.op_assign(
|
461
|
+
builder.assignable(builder.cvar(token(node.name_loc))),
|
462
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
463
|
+
visit(node.value)
|
464
|
+
)
|
465
|
+
end
|
430
466
|
|
431
467
|
# @@foo ||= bar
|
432
468
|
# ^^^^^^^^^^^^^
|
433
|
-
|
469
|
+
def visit_class_variable_or_write_node(node)
|
470
|
+
builder.op_assign(
|
471
|
+
builder.assignable(builder.cvar(token(node.name_loc))),
|
472
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
473
|
+
visit(node.value)
|
474
|
+
)
|
475
|
+
end
|
434
476
|
|
435
477
|
# @@foo, = bar
|
436
478
|
# ^^^^^
|
@@ -458,18 +500,30 @@ module Prism
|
|
458
500
|
def visit_constant_operator_write_node(node)
|
459
501
|
builder.op_assign(
|
460
502
|
builder.assignable(builder.const([node.name, srange(node.name_loc)])),
|
461
|
-
[node.
|
503
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
462
504
|
visit(node.value)
|
463
505
|
)
|
464
506
|
end
|
465
507
|
|
466
508
|
# Foo &&= bar
|
467
509
|
# ^^^^^^^^^^^^
|
468
|
-
|
510
|
+
def visit_constant_and_write_node(node)
|
511
|
+
builder.op_assign(
|
512
|
+
builder.assignable(builder.const([node.name, srange(node.name_loc)])),
|
513
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
514
|
+
visit(node.value)
|
515
|
+
)
|
516
|
+
end
|
469
517
|
|
470
518
|
# Foo ||= bar
|
471
519
|
# ^^^^^^^^^^^^
|
472
|
-
|
520
|
+
def visit_constant_or_write_node(node)
|
521
|
+
builder.op_assign(
|
522
|
+
builder.assignable(builder.const([node.name, srange(node.name_loc)])),
|
523
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
524
|
+
visit(node.value)
|
525
|
+
)
|
526
|
+
end
|
473
527
|
|
474
528
|
# Foo, = bar
|
475
529
|
# ^^^
|
@@ -512,18 +566,30 @@ module Prism
|
|
512
566
|
def visit_constant_path_operator_write_node(node)
|
513
567
|
builder.op_assign(
|
514
568
|
builder.assignable(visit(node.target)),
|
515
|
-
[node.
|
569
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
516
570
|
visit(node.value)
|
517
571
|
)
|
518
572
|
end
|
519
573
|
|
520
574
|
# Foo::Bar &&= baz
|
521
575
|
# ^^^^^^^^^^^^^^^^
|
522
|
-
|
576
|
+
def visit_constant_path_and_write_node(node)
|
577
|
+
builder.op_assign(
|
578
|
+
builder.assignable(visit(node.target)),
|
579
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
580
|
+
visit(node.value)
|
581
|
+
)
|
582
|
+
end
|
523
583
|
|
524
584
|
# Foo::Bar ||= baz
|
525
585
|
# ^^^^^^^^^^^^^^^^
|
526
|
-
|
586
|
+
def visit_constant_path_or_write_node(node)
|
587
|
+
builder.op_assign(
|
588
|
+
builder.assignable(visit(node.target)),
|
589
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
590
|
+
visit(node.value)
|
591
|
+
)
|
592
|
+
end
|
527
593
|
|
528
594
|
# Foo::Bar, = baz
|
529
595
|
# ^^^^^^^^
|
@@ -711,18 +777,30 @@ module Prism
|
|
711
777
|
def visit_global_variable_operator_write_node(node)
|
712
778
|
builder.op_assign(
|
713
779
|
builder.assignable(builder.gvar(token(node.name_loc))),
|
714
|
-
[node.
|
780
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
715
781
|
visit(node.value)
|
716
782
|
)
|
717
783
|
end
|
718
784
|
|
719
785
|
# $foo &&= bar
|
720
786
|
# ^^^^^^^^^^^^
|
721
|
-
|
787
|
+
def visit_global_variable_and_write_node(node)
|
788
|
+
builder.op_assign(
|
789
|
+
builder.assignable(builder.gvar(token(node.name_loc))),
|
790
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
791
|
+
visit(node.value)
|
792
|
+
)
|
793
|
+
end
|
722
794
|
|
723
795
|
# $foo ||= bar
|
724
796
|
# ^^^^^^^^^^^^
|
725
|
-
|
797
|
+
def visit_global_variable_or_write_node(node)
|
798
|
+
builder.op_assign(
|
799
|
+
builder.assignable(builder.gvar(token(node.name_loc))),
|
800
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
801
|
+
visit(node.value)
|
802
|
+
)
|
803
|
+
end
|
726
804
|
|
727
805
|
# $foo, = bar
|
728
806
|
# ^^^^
|
@@ -857,18 +935,46 @@ module Prism
|
|
857
935
|
visit_all(arguments),
|
858
936
|
token(node.closing_loc)
|
859
937
|
),
|
860
|
-
[node.
|
938
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
861
939
|
visit(node.value)
|
862
940
|
)
|
863
941
|
end
|
864
942
|
|
865
943
|
# foo[bar] &&= baz
|
866
944
|
# ^^^^^^^^^^^^^^^^
|
867
|
-
|
945
|
+
def visit_index_and_write_node(node)
|
946
|
+
arguments = node.arguments&.arguments || []
|
947
|
+
arguments << node.block if node.block
|
948
|
+
|
949
|
+
builder.op_assign(
|
950
|
+
builder.index(
|
951
|
+
visit(node.receiver),
|
952
|
+
token(node.opening_loc),
|
953
|
+
visit_all(arguments),
|
954
|
+
token(node.closing_loc)
|
955
|
+
),
|
956
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
957
|
+
visit(node.value)
|
958
|
+
)
|
959
|
+
end
|
868
960
|
|
869
961
|
# foo[bar] ||= baz
|
870
962
|
# ^^^^^^^^^^^^^^^^
|
871
|
-
|
963
|
+
def visit_index_or_write_node(node)
|
964
|
+
arguments = node.arguments&.arguments || []
|
965
|
+
arguments << node.block if node.block
|
966
|
+
|
967
|
+
builder.op_assign(
|
968
|
+
builder.index(
|
969
|
+
visit(node.receiver),
|
970
|
+
token(node.opening_loc),
|
971
|
+
visit_all(arguments),
|
972
|
+
token(node.closing_loc)
|
973
|
+
),
|
974
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
975
|
+
visit(node.value)
|
976
|
+
)
|
977
|
+
end
|
872
978
|
|
873
979
|
# foo[bar], = 1
|
874
980
|
# ^^^^^^^^
|
@@ -902,18 +1008,30 @@ module Prism
|
|
902
1008
|
def visit_instance_variable_operator_write_node(node)
|
903
1009
|
builder.op_assign(
|
904
1010
|
builder.assignable(builder.ivar(token(node.name_loc))),
|
905
|
-
[node.
|
1011
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
906
1012
|
visit(node.value)
|
907
1013
|
)
|
908
1014
|
end
|
909
1015
|
|
910
1016
|
# @foo &&= bar
|
911
1017
|
# ^^^^^^^^^^^^
|
912
|
-
|
1018
|
+
def visit_instance_variable_and_write_node(node)
|
1019
|
+
builder.op_assign(
|
1020
|
+
builder.assignable(builder.ivar(token(node.name_loc))),
|
1021
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
1022
|
+
visit(node.value)
|
1023
|
+
)
|
1024
|
+
end
|
913
1025
|
|
914
1026
|
# @foo ||= bar
|
915
1027
|
# ^^^^^^^^^^^^
|
916
|
-
|
1028
|
+
def visit_instance_variable_or_write_node(node)
|
1029
|
+
builder.op_assign(
|
1030
|
+
builder.assignable(builder.ivar(token(node.name_loc))),
|
1031
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
1032
|
+
visit(node.value)
|
1033
|
+
)
|
1034
|
+
end
|
917
1035
|
|
918
1036
|
# @foo, = bar
|
919
1037
|
# ^^^^
|
@@ -1108,18 +1226,30 @@ module Prism
|
|
1108
1226
|
def visit_local_variable_operator_write_node(node)
|
1109
1227
|
builder.op_assign(
|
1110
1228
|
builder.assignable(builder.ident(token(node.name_loc))),
|
1111
|
-
[node.
|
1229
|
+
[node.binary_operator_loc.slice.chomp("="), srange(node.binary_operator_loc)],
|
1112
1230
|
visit(node.value)
|
1113
1231
|
)
|
1114
1232
|
end
|
1115
1233
|
|
1116
1234
|
# foo &&= bar
|
1117
1235
|
# ^^^^^^^^^^^
|
1118
|
-
|
1236
|
+
def visit_local_variable_and_write_node(node)
|
1237
|
+
builder.op_assign(
|
1238
|
+
builder.assignable(builder.ident(token(node.name_loc))),
|
1239
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
1240
|
+
visit(node.value)
|
1241
|
+
)
|
1242
|
+
end
|
1119
1243
|
|
1120
1244
|
# foo ||= bar
|
1121
1245
|
# ^^^^^^^^^^^
|
1122
|
-
|
1246
|
+
def visit_local_variable_or_write_node(node)
|
1247
|
+
builder.op_assign(
|
1248
|
+
builder.assignable(builder.ident(token(node.name_loc))),
|
1249
|
+
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
|
1250
|
+
visit(node.value)
|
1251
|
+
)
|
1252
|
+
end
|
1123
1253
|
|
1124
1254
|
# foo, = bar
|
1125
1255
|
# ^^^
|