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
10 changes: 5 additions & 5 deletions lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ def to_a
location = range(token.location.start_offset, lexed[index][0].location.end_offset)
index += 1
else
value.chomp!
location = range(token.location.start_offset, token.location.end_offset - 1)
is_at_eol = value.chomp!.nil?
location = range(token.location.start_offset, token.location.end_offset + (is_at_eol ? 0 : -1))

prev_token = lexed[index - 2][0]
prev_token = lexed[index - 2][0] if index - 2 >= 0
next_token = lexed[index][0]

is_inline_comment = prev_token.location.start_line == token.location.start_line
if is_inline_comment && !COMMENT_CONTINUATION_TYPES.include?(next_token&.type)
is_inline_comment = prev_token&.location&.start_line == token.location.start_line
if is_inline_comment && !is_at_eol && !COMMENT_CONTINUATION_TYPES.include?(next_token&.type)
tokens << [:tCOMMENT, [value, location]]

nl_location = range(token.location.end_offset - 1, token.location.end_offset)
Expand Down
1 change: 1 addition & 0 deletions test/prism/fixtures/comment_single.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo # Bar
17 changes: 17 additions & 0 deletions test/prism/snapshots/comment_single.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading