defmodule MyParser.Helpers do
import NimbleParsec
def license do
ascii_string([?a..?z], min: 1)
|> ignore(ascii_string([?\s], min: 1))
|> integer(min: 1)
|> ignore(string("\n"))
#|> tag("record")
end
def eventually_license do
eventually(license())
end
end
defmodule MyParser do
import NimbleParsec
import MyParser.Helpers
defparsec(:license, eventually_license())
end
defmodule MyParser.Run do
@data """
ohno
matchme 1
"""
def license do
MyParser.license(@data)
end
end
That does seem unexpected. It appears that the accumulator isn’t being cleared on the partial combinator match. I tested with this simple variation on your code:
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