Eventually gives unexpected result
molsio opened this issue · comments
Eventually in combination with a simple parser gives unexpected output. If tag is appended, It works as expected.
iex(120)> MyParser.correct
{:ok, [{"record", ["matchme", 1]}], "", %{}, {3, 15}, 15}
iex(121)> MyParser.incorrect
{:ok, ["ohno", "matchme", 1], "", %{}, {3, 15}, 15}
`defmodule MyParser do
import NimbleParsec
parse_incorrect =
ascii_string([?a..?z], min: 1)
|> ignore(ascii_char([?\s]))
|> integer(min: 1)
|> ignore(ascii_char([?\n]))
parse_correct =
ascii_string([?a..?z], min: 1)
|> ignore(ascii_char([?\s]))
|> integer(min: 1)
|> ignore(ascii_char([?\n]))
|> tag("record")
defparsec :parse_correct, eventually(parse_correct)
defparsec :parse_incorrect, eventually(parse_incorrect)
@DaTa """
ohno
matchme 1
"""
def correct do
parse_correct(@DaTa)
end
def incorrect do
parse_incorrect(@DaTa)
end
end
`
You are correct the incorrect behaviour is incorrect. :) I would work on a fix tomorrow soon.