Skip to content

Commit

Permalink
Implement CallOperatorWriteNode
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Jul 8, 2024
1 parent 0c8b916 commit c72f41f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/ast_to_prism/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,27 @@ def convert_node(node, block: nil)
location(node) # location
)
when :OP_ASGN2
not_supported(node)
nd_recv, nd_aid, nd_vid, nd_mid, nd_value = node.children
receiver = convert_node(nd_recv)
read_name = nd_vid
# NOTE: Why write_name is needed?
write_name = "#{nd_vid}=".to_sym
binary_operator = nd_mid
value = convert_node(nd_value)

Prism::CallOperatorWriteNode.new(
source, # source
0, # flags
receiver, # receiver
null_location, # call_operator_loc
null_location, # message_loc
read_name, # read_name
write_name, # write_name
binary_operator, # binary_operator
null_location, # binary_operator_loc
value, # value
location(node) # location
)
when :OP_ASGN_AND
not_supported(node)
when :OP_ASGN_OR
Expand Down
10 changes: 10 additions & 0 deletions spec/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ def test_code(code)
end
end

describe "attr assignment with operator (OP_ASGN2)" do
it "tests" do
pending "CallOperatorWriteNode locations are not supported"

test_code(<<~CODE)
struct.field += foo
CODE
end
end

describe "super" do
it "tests" do
pending "keyword_loc, lparen_loc and rparen_loc are not supported"
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ def ===(other)
}
end

class CallOperatorWriteNode
prepend Module.new {
def ===(other)
super(other) &&
self.location == other.location &&
self.call_operator_loc == other.call_operator_loc &&
self.message_loc == other.message_loc &&
self.binary_operator_loc == other.binary_operator_loc
end
}
end

class BeginNode
prepend Module.new {
def ===(other)
Expand Down

0 comments on commit c72f41f

Please sign in to comment.