Skip to content

Commit 741f37a

Browse files
authored
Merge pull request #326 from KristofferC/kc/peekchar
add peekchar for IOBuffer
2 parents a090b63 + cbc07f7 commit 741f37a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lexer.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ function Base.show(io::IO, ps::ParseState)
6464
println(io, "next : ", kindof(ps.nt), " ($(ps.nt))", " ($(wstype(ps.nws)))")
6565
end
6666
peekchar(ps::ParseState) = peekchar(ps.l)
67+
if !applicable(Base.peek, Tuple{IOBuffer, Char})
68+
function _peek(s::IO, ::Type{T}) where T
69+
mark(s)
70+
try read(s, T)::T
71+
finally
72+
reset(s)
73+
end
74+
end
75+
peekchar(io) = _peek(io, Char)
76+
else
77+
peekchar(io) = peek(io, Char)
78+
end
79+
80+
81+
82+
6783
wstype(t::AbstractToken) = kindof(t) == EmptyWS ? "empty" :
6884
kindof(t) == NewLineWS ? "ws w/ newline" :
6985
kindof(t) == SemiColonWS ? "ws w/ semicolon" : "ws"

0 commit comments

Comments
 (0)