Skip to content

Commit 71320ea

Browse files
authored
fix: skip zero-width error tokens in last_non_whitespace_byte (#566)
to ensure that `let x = 1 # comment` is treated as an incomplete expression
1 parent 746d74c commit 71320ea

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/core/parse_stream.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,11 @@ function last_non_whitespace_byte(stream::ParseStream)
970970
for i = length(stream.output):-1:1
971971
node = stream.output[i]
972972
if is_terminal(node)
973-
if !(kind(node) in KSet"Comment Whitespace NewlineWs ErrorEofMultiComment")
973+
if kind(node) in KSet"Comment Whitespace NewlineWs ErrorEofMultiComment" || kind(node) == K"error" && node.byte_span == 0
974+
byte_pos -= node.byte_span
975+
else
974976
return byte_pos - 1
975977
end
976-
byte_pos -= node.byte_span
977978
end
978979
end
979980
return first_byte(stream) - 1

test/hooks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ end
497497
"Issue53126()." => :other
498498
"using " => :other
499499
"global xxx::Number = Base." => :other
500+
"let x = 1 # comment" => :other
500501
]
501502
@testset "$(repr(str))" begin
502503
# Test :statement parsing

0 commit comments

Comments
 (0)