Skip to content

Commit

Permalink
Remove OK code when sentinel is matched (#142)
Browse files Browse the repository at this point in the history
* Remove OK code when sentinel is matched

This broke the InlineStrings tests. Regardless of greedy or non-greedy,
we want to remove the OK code, since that should be mutually exclusive
with the SENTINEL code.

* add test
  • Loading branch information
quinnj authored Oct 25, 2022
1 parent 4b9ee9b commit 3136584
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ function sentinel(chcksentinel, sentinel)
# @show match, sentinelpos, pos, pl
if match && sentinelpos > (pl.pos + pl.len - 1)
# if we matched a sentinel value that was as long or longer than our type value
code &= ~OK
if isgreedy(T)
pl = withlen(pl, sentinelpos - pl.pos)
else
code &= ~(OK | INVALID | EOF | OVERFLOW)
code &= ~(INVALID | EOF | OVERFLOW)
pos = sentinelpos
fastseek!(source, pos - 1)
end
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ res = Parsers.xparse(Int64, "1\n"; sentinel=["", " ", " "])
@test res.tlen == 2
@test res.code == (OK | EOF | NEWLINE)

# #140, #142
res = Parsers.xparse(String, "NA"; sentinel=["NA"])
@test res.code == (SENTINEL | EOF)

# stripwhitespace
res = Parsers.xparse(String, "{hey there}"; openquotechar='{', closequotechar='}', stripwhitespace=true)
@test res.val.pos == 2 && res.val.len == 9
Expand Down

0 comments on commit 3136584

Please sign in to comment.