Skip to content

Commit

Permalink
Fix tokenization of emitting comments followed by \r\n (#455)
Browse files Browse the repository at this point in the history
Before this patch the `\r` character would be part of the comment and
not the following NewlineWs (which would simply be a `\n`-style
NewlineWs instead of a `\r\n` as one would expect).

(cherry picked from commit 1d95081, PR #455)
  • Loading branch information
fredrikekre committed Jul 20, 2024
1 parent b1c758c commit db9a9c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tokenize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ function lex_comment(l::Lexer)
if peekchar(l) != '='
valid = true
while true
pc = peekchar(l)
if pc == '\n' || pc == EOF_CHAR
pc, ppc = dpeekchar(l)
if pc == '\n' || (pc == '\r' && ppc == '\n') || pc == EOF_CHAR
return emit(l, valid ? K"Comment" : K"ErrorInvalidUTF8")
end
valid &= isvalid(pc)
Expand Down
2 changes: 2 additions & 0 deletions test/tokenize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ end
@test toks("#= #= =#") == ["#= #= =#"=>K"ErrorEofMultiComment"]
@test toks("#=#==#=#") == ["#=#==#=#"=>K"Comment"]
@test toks("#=#==#=") == ["#=#==#="=>K"ErrorEofMultiComment"]
# comment terminated by \r\n
@test toks("#\r\n") == ["#" => K"Comment", "\r\n" => K"NewlineWs"]
end


Expand Down

0 comments on commit db9a9c4

Please sign in to comment.