Hi, I want to modify elixir files based on the AST.
For the result I want to the elixir formatter.
For a prototype I tried the following and it almost works:
File.read!("example.ex")
|> read_contents_of_file()
|> Code.string_to_quoted!()
|> Macro.to_string()
# |> Code.format_string!()
# |> IO.iodata_to_binary
The problem are the parentheses. They’re added everywhere. An example result:
"defmodule(Example) do\n def(output(str)) do\n IO.inspect(str)\n end\nend"
The documentation for Macro.to_string states “This function discards all formatting of the original code.”.
So is it possible to keep the formatting of the original code?
Thanks in advance for every piece of advice or idea
- Sascha