diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-11-09 23:50:26 -0500 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2023-11-21 11:35:46 -0500 |
commit | ddacc0852895adfe3ffec83cdb79ba21f6db169f (patch) | |
tree | dec8c93fcdc89cc58d06090e80270c2ed999c588 /test/prism/location_test.rb | |
parent | 903b0931a116691386e71fa30fb1698bbd785853 (diff) | |
download | ruby-ddacc0852895adfe3ffec83cdb79ba21f6db169f.tar.gz |
[ruby/prism] Remove string concat in favor of a flat list
Right now when you have a lot of string concats it ends up being
difficult to work with because of the depth of the tree. You end
up descending very far for every string literal that is part of the
concat.
There are already times when we use an interpolated string node to
group together two string segments that are part of the same string
(like when they are interupted by the contents of a heredoc). This
commit takes the same approach and replaces string concats with
interpolated string nodes.
Now that they're a flat list, they should be much easier to work
with. There's still some missing information here that would be
useful to consumers: whether or not there is _actually_ any
interpolation contained in the list. We could remedy this with
another node type that is named something like string list, or we
could add a flag to interpolated string node indicating that there
is interpolation. Either way I want to solve that in a follow-up
commit, since this commit is valuable on its own.
https://github.com/ruby/prism/commit/1e7ae3ad1b
Diffstat (limited to 'test/prism/location_test.rb')
-rw-r--r-- | test/prism/location_test.rb | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/test/prism/location_test.rb b/test/prism/location_test.rb index 02a577a73c..302e6bd139 100644 --- a/test/prism/location_test.rb +++ b/test/prism/location_test.rb @@ -495,6 +495,7 @@ module Prism def test_InterpolatedStringNode assert_location(InterpolatedStringNode, "\"foo \#@bar baz\"") assert_location(InterpolatedStringNode, "<<~A\nhello \#{1} world\nA", 0...4) + assert_location(InterpolatedStringNode, '"foo" "bar"') end def test_InterpolatedSymbolNode @@ -789,10 +790,6 @@ module Prism assert_location(StatementsNode, "\"\#{foo}\"", 3...6) { |node| node.parts.first.statements } end - def test_StringConcatNode - assert_location(StringConcatNode, '"foo" "bar"') - end - def test_StringNode assert_location(StringNode, '"foo"') assert_location(StringNode, '%q[foo]') |