Skip to content
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
28 changes: 21 additions & 7 deletions lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ def visit_array_node(node)
previous = element
end

visit_words_sep(opening_loc, node.elements.last, node.closing_loc)

bounds(node.closing_loc)
on_tstring_end(node.closing)
when /^%i/
Expand All @@ -723,6 +725,8 @@ def visit_array_node(node)
previous = element
end

visit_words_sep(opening_loc, node.elements.last, node.closing_loc)

bounds(node.closing_loc)
on_tstring_end(node.closing)
when /^%W/
Expand Down Expand Up @@ -760,6 +764,8 @@ def visit_array_node(node)
previous = element
end

visit_words_sep(opening_loc, node.elements.last, node.closing_loc)

bounds(node.closing_loc)
on_tstring_end(node.closing)
when /^%I/
Expand Down Expand Up @@ -797,6 +803,8 @@ def visit_array_node(node)
previous = element
end

visit_words_sep(opening_loc, node.elements.last, node.closing_loc)

bounds(node.closing_loc)
on_tstring_end(node.closing)
else
Expand All @@ -813,15 +821,21 @@ def visit_array_node(node)
on_array(elements)
end

# Dispatch a words_sep event that contains the space between the elements
# Dispatch words_sep events that contains the whitespace between the elements
# of list literals.
private def visit_words_sep(opening_loc, previous, current)
end_offset = (previous.nil? ? opening_loc : previous.location).end_offset
start_offset = current.location.start_offset

if end_offset != start_offset
bounds(current.location.copy(start_offset: end_offset))
on_words_sep(source.byteslice(end_offset...start_offset))
start_offset = (previous.nil? ? opening_loc : previous.location).end_offset
end_offset = current.start_offset
length = end_offset - start_offset

if length > 0
whitespace = source.byteslice(start_offset, length)
current_offset = start_offset
whitespace.each_line do |part|
bounds(opening_loc.copy(start_offset: current_offset, length: part.bytesize))
on_words_sep(part)
current_offset += part.bytesize
end
end
end

Expand Down
5 changes: 3 additions & 2 deletions test/prism/ruby/ripper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class RipperTest < TestCase
"seattlerb/messy_op_asgn_lineno.txt",
"seattlerb/op_asgn_primary_colon_const_command_call.txt",
"seattlerb/parse_pattern_076.txt",
"seattlerb/pct_w_heredoc_interp_nested.txt",
"tilde_heredocs.txt",
"unparser/corpus/literal/assignment.txt",
"unparser/corpus/literal/pattern.txt",
Expand Down Expand Up @@ -138,11 +139,11 @@ def test_lex_ignored_missing_heredoc_end
end
end

UNSUPPORTED_EVENTS = %i[comma ignored_nl label_end nl semicolon sp words_sep ignored_sp]
UNSUPPORTED_EVENTS = %i[comma ignored_nl label_end nl semicolon sp ignored_sp]
# Events that are currently not emitted
SUPPORTED_EVENTS = Translation::Ripper::EVENTS - UNSUPPORTED_EVENTS
# Events that assert against their line/column
CHECK_LOCATION_EVENTS = %i[kw op lbrace rbrace lbracket rbracket lparen rparen]
CHECK_LOCATION_EVENTS = %i[kw op lbrace rbrace lbracket rbracket lparen rparen words_sep]

module Events
attr_reader :events
Expand Down