Skip to content

Commit f8b016f

Browse files
committed
Fix on_words_sep for ripper translator with newlines
Ripper emits a token each per line.
1 parent 0e1c05c commit f8b016f

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

lib/prism/lex_compat.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,16 @@ 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. This splits the
662+
# string at newlines and emits one token for each match.
663+
parts = value.scan(/(?=\s)[^\S\r\n]*(?:\r\n|\n)?/)
664+
parts[0...-1].each do |whitespace|
665+
tokens << Token.new([[lineno, column], event, whitespace, lex_state])
666+
lineno += 1
667+
column = 0
668+
end
669+
Token.new([[lineno, column], event, parts.last, lex_state])
660670
when :on_regexp_end
661671
# On regex end, Ripper scans and then sets end state, so the ripper
662672
# 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)