Skip to content

Commit be16d1d

Browse files
committed
Match EOF after newline behavior
in Ripper EOL after whitespace is returned as a on_nl node with the whitespace as the content
1 parent 84b37e0 commit be16d1d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/yarp/lex_compat.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,14 @@ def result
630630
end
631631

632632
Token.new([[lineno, column], event, value, lex_state])
633+
634+
when :on_eof
635+
prev_token = result_value[index-1][0]
636+
if prev_token.type == :COMMENT && prev_token.location.end_offset < token.location.start_offset
637+
tokens << Token.new([[lineno, 0], :on_nl, source.byteslice(result_value[index-1].first.location.end_offset...token.location.start_offset), lex_state])
638+
end
639+
640+
Token.new([[lineno, column], event, value, lex_state])
633641
else
634642
Token.new([[lineno, column], event, value, lex_state])
635643
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def hi
2+
3+
end # hi there
4+

test/snapshots/indented_file_end.txt

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)