Skip to content

Commit 5f25420

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Fix on_words_sep for ripper translator with newlines
Ripper emits a token each per line. ruby/prism@4b5c9f5437
1 parent e410d93 commit 5f25420

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

lib/prism/lex_compat.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,15 @@ def result
657657
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
658658
when :on_embexpr_end
659659
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
660+
when :on_words_sep
661+
# Ripper emits one token each per line.
662+
lines = value.lines
663+
lines[0...-1].each do |whitespace|
664+
tokens << Token.new([[lineno, column], event, whitespace, lex_state])
665+
lineno += 1
666+
column = 0
667+
end
668+
Token.new([[lineno, column], event, lines.last, lex_state])
660669
when :on_regexp_end
661670
# On regex end, Ripper scans and then sets end state, so the ripper
662671
# lexed output is begin, when it should be end. prism sets lex state

lib/prism/lex_ripper.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ def result
2626
results << token
2727
previous = token
2828
end
29-
when :on_words_sep
30-
if previous[1] == :on_words_sep
31-
previous[2] << token[2]
32-
else
33-
results << token
34-
previous = token
35-
end
3629
else
3730
results << token
3831
previous = token

test/prism/ruby/ripper_test.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,10 @@ class RipperTest < TestCase
6262
]
6363

6464
omitted_lex = [
65-
"comments.txt",
66-
"heredoc_percent_q_newline_delimiter.txt",
6765
"heredoc_with_escaped_newline_at_start.txt",
6866
"heredocs_with_fake_newlines.txt",
6967
"indented_file_end.txt",
70-
"seattlerb/TestRubyParserShared.txt",
71-
"seattlerb/class_comments.txt",
72-
"seattlerb/module_comments.txt",
73-
"seattlerb/parse_line_block_inline_comment_leading_newlines.txt",
74-
"seattlerb/parse_line_block_inline_multiline_comment.txt",
7568
"spanning_heredoc_newlines.txt",
76-
"strings.txt",
7769
"whitequark/dedenting_heredoc.txt",
7870
"whitequark/procarg0.txt",
7971
]

0 commit comments

Comments
 (0)