summaryrefslogtreecommitdiff
path: root/lib/prism/translation/parser
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-04-18 14:27:38 -0400
committergit <svn-admin@ruby-lang.org>2024-04-18 18:34:42 +0000
commit8f908a354ea80c01029af26d60adf14ef8ca33b8 (patch)
tree0347ef0cb85ca4d917886fd961b4d5af23dedeb9 /lib/prism/translation/parser
parent147ca9585ede559fd68e162cbbbaba84f009c9a1 (diff)
[ruby/prism] "Fix" transpose issue in parser compiler
https://github.com/ruby/prism/commit/593d637178
Diffstat (limited to 'lib/prism/translation/parser')
-rw-r--r--lib/prism/translation/parser/compiler.rb30
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index 9437589623..1025595925 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -1535,19 +1535,29 @@ module Prism
elsif node.opening == "?"
builder.character([node.unescaped, srange(node.location)])
else
- parts = if node.content.lines.count <= 1 || node.unescaped.lines.count <= 1
- [builder.string_internal([node.unescaped, srange(node.content_loc)])]
- else
- start_offset = node.content_loc.start_offset
+ content_lines = node.content.lines
+ unescaped_lines = node.unescaped.lines
- [node.content.lines, node.unescaped.lines].transpose.map do |content_line, unescaped_line|
- end_offset = start_offset + content_line.length
- offsets = srange_offsets(start_offset, end_offset)
- start_offset = end_offset
+ parts =
+ if content_lines.length <= 1 || unescaped_lines.length <= 1
+ [builder.string_internal([node.unescaped, srange(node.content_loc)])]
+ elsif content_lines.length != unescaped_lines.length
+ # This occurs when we have line continuations in the string. We
+ # need to come back and fix this, but for now this stops the
+ # code from breaking when we encounter it because of trying to
+ # transpose arrays of different lengths.
+ [builder.string_internal([node.unescaped, srange(node.content_loc)])]
+ else
+ start_offset = node.content_loc.start_offset
+
+ [content_lines, unescaped_lines].transpose.map do |content_line, unescaped_line|
+ end_offset = start_offset + content_line.length
+ offsets = srange_offsets(start_offset, end_offset)
+ start_offset = end_offset
- builder.string_internal([unescaped_line, offsets])
+ builder.string_internal([unescaped_line, offsets])
+ end
end
- end
builder.string_compose(
token(node.opening_loc),