Testing whether a string contains valid Elixir code?

This looks extremely hard and very error-prone.

You might be better off searching for a tool that converts your input to another format that is supported by Elixir.