Skip to content

Commit 5a86713

Browse files
committed
Fix initialization of character byte offsets in lexer
1 parent 07b97cc commit 5a86713

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/tokenize.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ function Lexer(io::IO)
9898
c2 = read(io, Char)
9999
p2 = position(io)
100100
if eof(io)
101-
c3, p3 = EOF_CHAR, p1
102-
c4, p4 = EOF_CHAR, p1
101+
c3, p3 = EOF_CHAR, p2
102+
c4, p4 = EOF_CHAR, p2
103103
else
104104
c3 = read(io, Char)
105105
p3 = position(io)
106106
if eof(io)
107-
c4, p4 = EOF_CHAR, p1
107+
c4, p4 = EOF_CHAR, p3
108108
else
109109
c4 = read(io, Char)
110110
p4 = position(io)

test/tokenize.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,12 @@ end
897897
]
898898
end
899899

900+
@testset "lexer initialization" begin
901+
# Ranges of EndMarker
902+
@test (t = last(collect(tokenize("+"))); (t.startbyte, t.endbyte)) == (1,0)
903+
@test (t = last(collect(tokenize("+*"))); (t.startbyte, t.endbyte)) == (2,1)
904+
end
905+
900906
@testset "dotop miscellanea" begin
901907
@test strtok("a .-> b") == ["a", " ", ".-", ">", " ", "b", ""]
902908
@test strtok(".>: b") == [".>:", " ", "b", ""]

0 commit comments

Comments
 (0)