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
5 changes: 3 additions & 2 deletions src/tokenize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,10 @@ function lex_whitespace(l::Lexer, c)
if c == '\n'
k = K"NewlineWs"
end
pc = peekchar(l)
pc, ppc = dpeekchar(l)
# stop on non whitespace and limit to a single newline in a token
if !iswhitespace(pc) || (k == K"NewlineWs" && pc == '\n')
if !iswhitespace(pc) ||
(k == K"NewlineWs" && (pc == '\n' || (pc == '\r' && ppc == '\n')))
break
end
c = readchar(l)
Expand Down
10 changes: 10 additions & 0 deletions test/tokenize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ end
@test untokenize(tok(str), str)==">>"
end

@testset "tokenize newlines" begin
n = "\n"
rn = "\r\n"
nl = K"NewlineWs"
for i in 0:5
j = 5 - i
@test toks(n^i * rn^j) == vcat(fill(n => nl, i), fill(rn => nl, j))
@test toks(rn^i * n^j) == vcat(fill(rn => nl, i), fill(n => nl, j))
end
end

@testset "test added operators" begin
@test tok("1+=2", 2).kind == K"+="
Expand Down