Skip to content

fix: skip zero-width error tokens in last_non_whitespace_byte #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
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
5 changes: 3 additions & 2 deletions src/core/parse_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -970,10 +970,11 @@ function last_non_whitespace_byte(stream::ParseStream)
for i = length(stream.output):-1:1
node = stream.output[i]
if is_terminal(node)
if !(kind(node) in KSet"Comment Whitespace NewlineWs ErrorEofMultiComment")
if kind(node) in KSet"Comment Whitespace NewlineWs ErrorEofMultiComment" || kind(node) == K"error" && node.byte_span == 0
byte_pos -= node.byte_span
else
return byte_pos - 1
end
byte_pos -= node.byte_span
end
end
return first_byte(stream) - 1
Expand Down
1 change: 1 addition & 0 deletions test/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ end
"Issue53126()." => :other
"using " => :other
"global xxx::Number = Base." => :other
"let x = 1 # comment" => :other
]
@testset "$(repr(str))" begin
# Test :statement parsing
Expand Down
Loading