Skip to content

Commit

Permalink
Implement InterpolatedXStringNode
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Jul 9, 2024
1 parent 66ccf3c commit 10f9868
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/ast_to_prism/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def convert_for_args(node)
end

def convert_dynamic_literal(node)
check_node_type(node, :DSTR, :DREGX)
check_node_type(node, :DSTR, :DXSTR, :DREGX)

string, nd_head, nd_next = node.children
flags = 0
Expand Down Expand Up @@ -1825,7 +1825,15 @@ def convert_node(node, block: nil)
location(node) # location
)
when :DXSTR
not_supported(node)
parts = convert_dynamic_literal(node)

Prism::InterpolatedXStringNode.new(
source, # source
null_location, # opening_loc
parts, # parts
null_location, # closing_loc
location(node) # location
)
when :DREGX
flags = 0
parts = convert_dynamic_literal(node)
Expand Down
19 changes: 19 additions & 0 deletions spec/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ def test_code(code)
end
end

describe "xstring literal with interpolation" do
it "tests" do
pending "InterpolatedXStringNode locations are not supported"

test_code(<<~'CODE')
`foo#{ bar }baz`
CODE
end

it "tests" do
pending "InterpolatedXStringNode locations are not supported"

test_code(<<~'CODE')
# frozen_string_literal: true
`foo#{ bar }baz`
CODE
end
end

describe "regex" do
it "tests" do
pending "RegularExpressionNode locations are not supported"
Expand Down
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ def ===(other)
}
end

class InterpolatedXStringNode
prepend Module.new {
def ===(other)
super(other) &&
self.location == other.location &&
self.opening_loc == other.opening_loc &&
self.closing_loc == other.closing_loc
end
}
end

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

0 comments on commit 10f9868

Please sign in to comment.