Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an incompatibility with the parser translator #3338

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ def visit_interpolated_string_node(node)
start_offset = node.content_loc.start_offset

node.unescaped.lines.map do |line|
end_offset = start_offset + line.length
end_offset = start_offset + line.bytesize
offsets = srange_offsets(start_offset, end_offset)
start_offset = end_offset

Expand Down Expand Up @@ -1692,7 +1692,7 @@ def visit_string_node(node)
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
end_offset = start_offset + content_line.bytesize
offsets = srange_offsets(start_offset, end_offset)
start_offset = end_offset

Expand Down Expand Up @@ -1747,7 +1747,7 @@ def visit_symbol_node(node)
start_offset = node.value_loc.start_offset

node.value.lines.map do |line|
end_offset = start_offset + line.length
end_offset = start_offset + line.bytesize
offsets = srange_offsets(start_offset, end_offset)
start_offset = end_offset

Expand Down Expand Up @@ -1890,7 +1890,7 @@ def visit_x_string_node(node)
start_offset = node.content_loc.start_offset

node.unescaped.lines.map do |line|
end_offset = start_offset + line.length
end_offset = start_offset + line.bytesize
offsets = srange_offsets(start_offset, end_offset)
start_offset = end_offset

Expand Down
2 changes: 1 addition & 1 deletion lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def to_a
adjustment = 0
end

end_offset = start_offset + adjusted_line.length + adjustment
end_offset = start_offset + adjusted_line.bytesize + adjustment
tokens << [:tSTRING_CONTENT, [adjusted_line, Range.new(source_buffer, offset_cache[start_offset], offset_cache[end_offset])]]
start_offset = end_offset
end
Expand Down
3 changes: 3 additions & 0 deletions test/prism/fixtures/dstring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ foo\\\\
"
foo\\\\\
"

"
’"
3 changes: 3 additions & 0 deletions test/prism/fixtures/dsym_str.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
:"foo
bar"

:"
’"
3 changes: 3 additions & 0 deletions test/prism/fixtures/xstring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
``

%x{}

`
’`
1 change: 1 addition & 0 deletions test/prism/ruby/ruby_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RubyParserTest < TestCase
# https://github.com/seattlerb/ruby_parser/issues/344
failures = [
"alias.txt",
"dsym_str.txt",
"dos_endings.txt",
"heredocs_with_ignored_newlines.txt",
"method_calls.txt",
Expand Down
22 changes: 14 additions & 8 deletions test/prism/snapshots/dstring.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions test/prism/snapshots/dsym_str.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions test/prism/snapshots/xstring.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading