diff --git a/lib/yarp/lex_compat.rb b/lib/yarp/lex_compat.rb index 7e1d9f3657..6442650931 100644 --- a/lib/yarp/lex_compat.rb +++ b/lib/yarp/lex_compat.rb @@ -630,6 +630,14 @@ module YARP end Token.new([[lineno, column], event, value, lex_state]) + + when :on_eof + prev_token = result_value[index-1][0] + if prev_token.type == :COMMENT && prev_token.location.end_offset < token.location.start_offset + tokens << Token.new([[lineno, 0], :on_nl, source.byteslice(result_value[index-1].first.location.end_offset...token.location.start_offset), lex_state]) + end + + Token.new([[lineno, column], event, value, lex_state]) else Token.new([[lineno, column], event, value, lex_state]) end diff --git a/test/snapshots/indented_file_end.txt b/test/snapshots/indented_file_end.txt new file mode 100644 index 0000000000..513a7ab0f5 --- /dev/null +++ b/test/snapshots/indented_file_end.txt @@ -0,0 +1,18 @@ +ProgramNode(4...23)( + [], + StatementsNode(4...23)( + [DefNode(4...23)( + (8...10), + nil, + nil, + nil, + [], + (4...7), + nil, + nil, + nil, + nil, + (20...23) + )] + ) +)