Hi,
I am trying to define a parser for a simple grammar and I am getting hung up on something that I think is simple but I can’t figure out.
The grammar has two main structures, a definition and an invocation, of the form:
invocationname($a$b)(c<>d<>)
definitionname[(a<>b<>)($c$d)somestuff:someotherstuff]
I have the invocation one working, but for some reason even though the definition structure is very similar, I get an error that it is expecting the opening bracket, even though I am sending it.
The whole parser definition is here, and I will copy my interaction with it:
defmodule Atomix.Invocation.Parser do
import NimbleParsec
name = ascii_string([?A..?z], min: 1)
definition_name = ascii_string([?A..?z], min: 1)
invocation_name = ascii_string([?a..?z], min: 1)
content_name = ascii_string([?A..?Z], min: 1)
destination_place =
string("$")
|> concat(name)
destination_list =
destination_place
|> repeat(destination_place)
source_place =
name
|> string("<>")
source_list =
source_place
|> repeat(source_place)
place_of_resolution =
string("+")
contained_definitions =
string("=")
defparsec(
:invocation,
invocation_name
|> string("(")
|> concat(destination_list)
|> string(")")
|> string("(")
|> concat(source_list)
|> string(")")
)
defparsec(
:definition,
definition_name
|> string("[")
|> concat(source_list)
|> concat(destination_list)
|> concat(place_of_resolution)
|> string(":")
|> concat(contained_definitions)
|> string("]")
)
end
iex(2)> Parser.invocation(“dfsd($a$b)(a<>b<>)”)
{:ok, [“dfsd”, “(”, “$”, “a”, “$”, “b”, “)”, “(”, “a”, “<>”, “b”, “<>”, “)”],
“”, %{}, {1, 0}, 18}
iex(3)> Parser.definition(“fdafa[(a<>b<>)fdsaf:fadf]”)
{:error, “expected string “[””, “(a<>b<>)fdsaf:fadf]”, %{}, {1, 0}, 6}
Why am I getting the error about expecting the bracket when it is clearly there?
Thanks for any pointers.