summaryrefslogtreecommitdiff
path: root/lib/prism/translation/parser/compiler.rb
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2024-03-03 21:25:10 +0900
committergit <svn-admin@ruby-lang.org>2024-03-07 14:05:20 +0000
commit0e4bfd08e548e90faf5d91bddccf418dc9a62a42 (patch)
tree12ac92dffdedf181274593cf0f53798a1e8bb4de /lib/prism/translation/parser/compiler.rb
parent78725f14b287bff19d48dea076be169c74e18b77 (diff)
[ruby/prism] Fix an AST and token incompatibility for `Prism::Translation::Parser`
Fixes https://github.com/ruby/prism/pull/2506. This PR fixes an AST and token incompatibility between Parser gem and `Prism::Translation::Parser` for symbols quoted with line breaks. https://github.com/ruby/prism/commit/06ab4df8cd
Diffstat (limited to 'lib/prism/translation/parser/compiler.rb')
-rw-r--r--lib/prism/translation/parser/compiler.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index 8170e1953b..d64e382c78 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -1528,9 +1528,23 @@ module Prism
builder.symbol([node.unescaped, srange(node.location)])
end
else
+ parts = if node.value.lines.one?
+ [builder.string_internal([node.unescaped, srange(node.value_loc)])]
+ else
+ start_offset = node.value_loc.start_offset
+
+ node.value.lines.map do |line|
+ end_offset = start_offset + line.length
+ offsets = srange_offsets(start_offset, end_offset)
+ start_offset = end_offset
+
+ builder.string_internal([line, offsets])
+ end
+ end
+
builder.symbol_compose(
token(node.opening_loc),
- [builder.string_internal([node.unescaped, srange(node.value_loc)])],
+ parts,
token(node.closing_loc)
)
end