Skip to content

Commit aea55cb

Browse files
committed
do not fail if lexing empty input
1 parent 639921f commit aea55cb

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PikaParser"
22
uuid = "3bbf5609-3e7b-44cd-8549-7c69f321e792"
33
authors = ["The developers of PikaParser.jl"]
4-
version = "0.5.0"
4+
version = "0.5.1"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"

src/parse.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ parsing terminals where another terminal was already parsed successfully.
208208
"""
209209
function lex(g::Grammar{G,T}, input::I)::Vector{Vector{Tuple{G,Int}}} where {G,T,I}
210210
q = PikaQueue(lastindex(input))
211-
push!(q, firstindex(input))
212-
res = [Vector{Tuple{G,Int}}() for _ = firstindex(input):lastindex(input)] # tricky: do not fill()!
211+
212+
# tricky: both use of eachindex() and of fill() are actually wrong here
213+
res = [Vector{Tuple{G,Int}}() for _ = firstindex(input):lastindex(input)]
214+
firstindex(input) <= lastindex(input) && push!(q, firstindex(input))
215+
213216
while !isempty(q)
214217
pos = pop!(q)
215218
for tidx in g.terminals

test/fastmatch.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141

4242
# lexing shouldn't make too much tokens
4343
@test sum(length.(P.lex(g, input))) == 5
44+
@test isempty(P.lex(g, ""))
4445

4546
p = P.parse_lex(g, input)
4647

0 commit comments

Comments
 (0)