summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-05 09:43:43 -0500
committergit <svn-admin@ruby-lang.org>2024-03-06 16:42:45 +0000
commitb0ee9c8f28249b3de644383901bb637b8eb7275b (patch)
tree22079a1bd7bb639c41e170dac7bc94e123b6f1b1
parent7bcca7177d6c42891004899d63e13ef47d78a337 (diff)
[ruby/prism] Implement index nodes for ripper translation
https://github.com/ruby/prism/commit/3fd962f2d3
-rw-r--r--lib/prism/translation/ripper.rb42
-rw-r--r--test/prism/ripper_test.rb6
2 files changed, 39 insertions, 9 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index 89f793cb70..d92ff83ed3 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -1208,25 +1208,59 @@ module Prism
# foo[bar] += baz
# ^^^^^^^^^^^^^^^
def visit_index_operator_write_node(node)
- raise NoMethodError, __method__
+ receiver = visit(node.receiver)
+ arguments = visit(node.arguments)
+
+ bounds(node.location)
+ target = on_aref_field(receiver, arguments)
+
+ bounds(node.operator_loc)
+ operator = on_op("#{node.operator}=")
+
+ value = visit(node.value)
+ on_opassign(target, operator, value)
end
# foo[bar] &&= baz
# ^^^^^^^^^^^^^^^^
def visit_index_and_write_node(node)
- raise NoMethodError, __method__
+ receiver = visit(node.receiver)
+ arguments = visit(node.arguments)
+
+ bounds(node.location)
+ target = on_aref_field(receiver, arguments)
+
+ bounds(node.operator_loc)
+ operator = on_op("&&=")
+
+ value = visit(node.value)
+ on_opassign(target, operator, value)
end
# foo[bar] ||= baz
# ^^^^^^^^^^^^^^^^
def visit_index_or_write_node(node)
- raise NoMethodError, __method__
+ receiver = visit(node.receiver)
+ arguments = visit(node.arguments)
+
+ bounds(node.location)
+ target = on_aref_field(receiver, arguments)
+
+ bounds(node.operator_loc)
+ operator = on_op("||=")
+
+ value = visit(node.value)
+ on_opassign(target, operator, value)
end
# foo[bar], = 1
# ^^^^^^^^
def visit_index_target_node(node)
- raise NoMethodError, __method__
+ receiver = visit(node.receiver)
+ arguments = visit(node.arguments)
+
+ bounds(node.location)
+ on_aref_field(receiver, arguments)
end
# @foo
diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb
index 5b91ea905d..38ffbad761 100644
--- a/test/prism/ripper_test.rb
+++ b/test/prism/ripper_test.rb
@@ -6,7 +6,7 @@ File.delete("passing.txt") if File.exist?("passing.txt")
File.delete("failing.txt") if File.exist?("failing.txt")
module Prism
- class RipperTest < RipperTestCase
+ class RipperTest < TestCase
base = File.join(__dir__, "fixtures")
relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]
@@ -149,7 +149,6 @@ module Prism
seattlerb/heredoc_with_only_carriage_returns_windows.txt
seattlerb/if_elsif.txt
seattlerb/index_0.txt
- seattlerb/index_0_opasgn.txt
seattlerb/interpolated_symbol_array_line_breaks.txt
seattlerb/interpolated_word_array_line_breaks.txt
seattlerb/lambda_do_vs_brace.txt
@@ -185,7 +184,6 @@ module Prism
seattlerb/non_interpolated_word_array_line_breaks.txt
seattlerb/op_asgn_command_call.txt
seattlerb/op_asgn_dot_ident_command_call.txt
- seattlerb/op_asgn_index_command_call.txt
seattlerb/op_asgn_primary_colon_identifier1.txt
seattlerb/op_asgn_primary_colon_identifier_command_call.txt
seattlerb/op_asgn_val_dot_ident_command_call.txt
@@ -389,8 +387,6 @@ module Prism
whitequark/numparam_outside_block.txt
whitequark/op_asgn.txt
whitequark/op_asgn_cmd.txt
- whitequark/op_asgn_index.txt
- whitequark/op_asgn_index_cmd.txt
whitequark/or_asgn.txt
whitequark/parser_bug_272.txt
whitequark/parser_bug_507.txt