@@ -120,6 +120,9 @@ def visit_array_node(node)
120
120
# nodes -- unary and binary operators, "command" calls with
121
121
# no parentheses, and call/fcall/vcall.
122
122
def visit_call_node ( node )
123
+ return visit_aref_node ( node ) if node . name == :[]
124
+ return visit_aref_field_node ( node ) if node . name == :[]=
125
+
123
126
if node . variable_call?
124
127
raise NotImplementedError unless node . receiver . nil?
125
128
@@ -153,6 +156,13 @@ def visit_call_node(node)
153
156
end
154
157
end
155
158
159
+ # Visit a LocalVariableWriteNode.
160
+ def visit_local_variable_write_node ( node )
161
+ bounds ( node . name_loc )
162
+ ident_val = on_ident ( node . name . to_s )
163
+ on_assign ( on_var_field ( ident_val ) , visit ( node . value ) )
164
+ end
165
+
156
166
# Visit a LocalVariableAndWriteNode.
157
167
def visit_local_variable_and_write_node ( node )
158
168
visit_binary_op_assign ( node )
@@ -299,6 +309,59 @@ def visit_rational_node(node)
299
309
visit_number ( node ) { |text | on_rational ( text ) }
300
310
end
301
311
312
+ # Visit a StringNode node.
313
+ def visit_string_node ( node )
314
+ bounds ( node . content_loc )
315
+ tstring_val = on_tstring_content ( node . unescaped . to_s )
316
+ on_string_literal ( on_string_add ( on_string_content , tstring_val ) )
317
+ end
318
+
319
+ # Visit an XStringNode node.
320
+ def visit_x_string_node ( node )
321
+ bounds ( node . content_loc )
322
+ tstring_val = on_tstring_content ( node . unescaped . to_s )
323
+ on_xstring_literal ( on_xstring_add ( on_xstring_new , tstring_val ) )
324
+ end
325
+
326
+ # Visit an InterpolatedStringNode node.
327
+ def visit_interpolated_string_node ( node )
328
+ parts = node . parts . map do |part |
329
+ case part
330
+ when StringNode
331
+ bounds ( part . content_loc )
332
+ on_tstring_content ( part . content )
333
+ when EmbeddedStatementsNode
334
+ on_string_embexpr ( visit ( part ) )
335
+ else
336
+ raise NotImplementedError , "Unexpected node type in InterpolatedStringNode"
337
+ end
338
+ end
339
+
340
+ string_list = parts . inject ( on_string_content ) do |items , item |
341
+ on_string_add ( items , item )
342
+ end
343
+
344
+ on_string_literal ( string_list )
345
+ end
346
+
347
+ # Visit an EmbeddedStatementsNode node.
348
+ def visit_embedded_statements_node ( node )
349
+ visit ( node . statements )
350
+ end
351
+
352
+ # Visit a SymbolNode node.
353
+ def visit_symbol_node ( node )
354
+ if node . opening && [ '"' , "'" , "(" ] . include? ( node . opening [ -1 ] )
355
+ bounds ( node . value_loc )
356
+ tstring_val = on_tstring_content ( node . value . to_s )
357
+ return on_dyna_symbol ( on_string_add ( on_string_content , tstring_val ) )
358
+ end
359
+
360
+ bounds ( node . value_loc )
361
+ ident_val = on_ident ( node . value . to_s )
362
+ on_symbol_literal ( on_symbol ( ident_val ) )
363
+ end
364
+
302
365
# Visit a StatementsNode node.
303
366
def visit_statements_node ( node )
304
367
bounds ( node . location )
@@ -406,6 +469,23 @@ def visit_binary_op_assign(node, operator: node.operator)
406
469
on_opassign ( on_var_field ( ident_val ) , op_val , visit ( node . value ) )
407
470
end
408
471
472
+ # In Prism this is a CallNode with :[] as the operator.
473
+ # In Ripper it's an :aref.
474
+ def visit_aref_node ( node )
475
+ first_arg_val = visit ( node . arguments . arguments [ 0 ] )
476
+ args_val = on_args_add_block ( on_args_add ( on_args_new , first_arg_val ) , false )
477
+ on_aref ( visit ( node . receiver ) , args_val )
478
+ end
479
+
480
+ # In Prism this is a CallNode with :[]= as the operator.
481
+ # In Ripper it's an :aref_field.
482
+ def visit_aref_field_node ( node )
483
+ first_arg_val = visit ( node . arguments . arguments [ 0 ] )
484
+ args_val = on_args_add_block ( on_args_add ( on_args_new , first_arg_val ) , false )
485
+ assign_val = visit ( node . arguments . arguments [ 1 ] )
486
+ on_assign ( on_aref_field ( visit ( node . receiver ) , args_val ) , assign_val )
487
+ end
488
+
409
489
# Visit a node that represents a number. We need to explicitly handle the
410
490
# unary - operator.
411
491
def visit_number ( node )
0 commit comments