зеркало из https://github.com/github/ruby.git
[ruby/prism] "Fix" transpose issue in parser compiler
https://github.com/ruby/prism/commit/593d637178
This commit is contained in:
Родитель
147ca9585e
Коммит
8f908a354e
|
@ -1535,19 +1535,29 @@ module Prism
|
||||||
elsif node.opening == "?"
|
elsif node.opening == "?"
|
||||||
builder.character([node.unescaped, srange(node.location)])
|
builder.character([node.unescaped, srange(node.location)])
|
||||||
else
|
else
|
||||||
parts = if node.content.lines.count <= 1 || node.unescaped.lines.count <= 1
|
content_lines = node.content.lines
|
||||||
[builder.string_internal([node.unescaped, srange(node.content_loc)])]
|
unescaped_lines = node.unescaped.lines
|
||||||
else
|
|
||||||
start_offset = node.content_loc.start_offset
|
|
||||||
|
|
||||||
[node.content.lines, node.unescaped.lines].transpose.map do |content_line, unescaped_line|
|
parts =
|
||||||
end_offset = start_offset + content_line.length
|
if content_lines.length <= 1 || unescaped_lines.length <= 1
|
||||||
offsets = srange_offsets(start_offset, end_offset)
|
[builder.string_internal([node.unescaped, srange(node.content_loc)])]
|
||||||
start_offset = end_offset
|
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
|
||||||
|
|
||||||
builder.string_internal([unescaped_line, offsets])
|
[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])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
builder.string_compose(
|
builder.string_compose(
|
||||||
token(node.opening_loc),
|
token(node.opening_loc),
|
||||||
|
|
Загрузка…
Ссылка в новой задаче