My current favorite library to read for learning about neat code generation is NimbleParsec. It might give you some ideas.
Edit: The Elixir Forum thread for the library is also good- searching it for “quoted expressions” might give you a few more ideas.