Hi everyone,
I’m playing with Nimble Parsec and when I use parsec/2
the error report incorrect location.
I’m using XML parser from example directory. This is my code
defmodule SimpleXML do
import NimbleParsec
@doc """
Parses a simple XML.
It is meant to show NimbleParsec recursive features.
It doesn't support attributes. The content of a tag is
either another tag or a text node.
"""
defparsec(:parse, parsec(:node) |> eos())
tag = ascii_string([?a..?z, ?A..?Z], min: 1)
text = ascii_string([not: ?<], min: 1)
opening_tag = ignore(string("<")) |> concat(tag) |> ignore(string(">"))
closing_tag = ignore(string("</")) |> concat(tag) |> ignore(string(">"))
defcombinator(
:node,
opening_tag
|> repeat(lookahead_not(string("</")) |> choice([parsec(:node), text]))
|> concat(closing_tag)
|> wrap()
)
end
input = """
<foo>
<bar>
hi
</bar>
<fa>
<son>son</son>
<dau>
<gson>grand son</gson
</dau>
</fa>
</foo>
"""
IO.inspect(SimpleXML.parse(String.trim(input)))
Here I miss >
on gson
closing tag. But the message report on line 4
{:error, "expected string \"</\"",
"<fa>\n <son>son</son>\n <dau>\n <gson>grand son</gson\n </dau>\n </fa>\n</foo>",
%{}, {5, 30}, 32}
It seems that NimbleParsec return the error for out most tag that not complete parsing, not the tag which really cause the error.
Do you have any idea?