Skip to content

Commit 1d95081

Browse files
authored
Fix tokenization of emitting comments followed by \r\n (#455)
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).
1 parent ae7d6ac commit 1d95081

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/tokenize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ function lex_comment(l::Lexer)
747747
if peekchar(l) != '='
748748
valid = true
749749
while true
750-
pc = peekchar(l)
751-
if pc == '\n' || pc == EOF_CHAR
750+
pc, ppc = dpeekchar(l)
751+
if pc == '\n' || (pc == '\r' && ppc == '\n') || pc == EOF_CHAR
752752
return emit(l, valid ? K"Comment" : K"ErrorInvalidUTF8")
753753
end
754754
valid &= isvalid(pc)

test/tokenize.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ end
221221
@test toks("#= #= =#") == ["#= #= =#"=>K"ErrorEofMultiComment"]
222222
@test toks("#=#==#=#") == ["#=#==#=#"=>K"Comment"]
223223
@test toks("#=#==#=") == ["#=#==#="=>K"ErrorEofMultiComment"]
224+
# comment terminated by \r\n
225+
@test toks("#\r\n") == ["#" => K"Comment", "\r\n" => K"NewlineWs"]
224226
end
225227

226228

0 commit comments

Comments
 (0)