Parsing custom query language and query Ecto database

I’m almost there, sorry for the interruptions.

iex> "city where country.code='se' or (country='USA' and name='New York')" |>
...> to_charlist() |> 
...> :lexer.string() |> 
...> (fn {_, x, _} -> x end).() |> 
...> :parser.parse() |> 
...> (fn {_, x} -> x end).()
{:from, [context: Elixir, import: :"Ecto.Query"],
 [
   {:in, [context: Elixir, import: :Kernel],
    [{:domain, [], Elixir}, "city"]},
   [

the rest looks fine to me, but what do I do with this import: :"Ecto.Query", which in my quoted target should look like import: Ecto.Query? same for the :Kernel, what’s that leading colon?

the yecc code looks like this:
query -> domain where expression : {from, [{context, 'Elixir'}, {import, 'Ecto.Query'}], [{in, [{context, 'Elixir'}, {import, 'Kernel'}], [{domain, [], 'Elixir'}, '$1']}, [{where, '$3'}]]}.

I found it.
it’s the raw representation that I’m giving, in Erlang, and they start with Elixir.
so when Elixir tells me Ecto.Query, I need Elixir.Ecto.Query.

1 Like