title: can I get Elixir to execute quoted code matched to a variable?
body: <p>maybe it’s not the way to go, but this was my initial guess and I'm open to hints and corrections.</p>
  
  <p>I <a href="https://elixirforum.com/t/parsing-custom-query-language-and-query-ecto-database/23243/13" rel="nofollow noreferrer">have been writing a parser</a> for a reduced query dialect that I have partially inherited and much expanded, allowing users write things like:</p>
  
  <p><code>plant where accession.code='2018.0047'</code></p>
  
  <p>it’s not ready, but the missing intermediate steps are clear, except the final one: how do I have the result executed?</p>
  
  <p>I am targeting as result the quote representation of the equivalent <code>Ecto.Query.from</code> query. for the above example the equivalent as far as I am concerned would be:</p>
  
  <pre><code>from(p in "plant", 
    select: [:id], 
    join: a in "accession", 
    on: a.id==p.accession_id, 
    where: a.code=="2018.0047")
  </code></pre>
  
  <p>I have been looking into the structures returned by the <code>__schema__</code> functions, and all looks quite doable, I mean I know how to extract the table name from the modules, and owner and related modules and keys from the association given its name, so let’s assume that my parser does return this value:</p>
  
  <pre><code>{:from, [context: Elixir, import: Ecto.Query],
   [
     {:in, [context: Elixir, import: Kernel], [{:p, [], Elixir}, "plant"]},
     [
       select: [:id],
       join: {:in, [context: Elixir, import: Kernel],
        [{:a, [], Elixir}, "accession"]},
       on: {:==, [context: Elixir, import: Kernel],
        [
          {{:., [], [{:a, [], Elixir}, :id]}, [], []},
          {{:., [], [{:p, [], Elixir}, :accession_id]}, [], []}
        ]},
       where: {:==, [context: Elixir, import: Kernel],
        [{{:., [], [{:a, [], Elixir}, :code]}, [], []}, "2018.0047"]}
     ]
   ]}
  </code></pre>
  
  <p>how do I get Ecto to execute it?  </p>
  
  <p>or what's the best way to produce Elixir code from a yecc parser?</p>