Resources on Elixir AST
I made a prototype for CirruSepal for Elixir. In order to create AST the generate Elixir code, I need to know detail on Elixir AST. Here’s the docs I gathered.
Exampls in the docs is quite helpful:
iex> quote do: 1 + 2
{:+, [context: Elixir, import: Kernel], [1, 2]}
iex> quote do: sum(1, 2, 3)
{:sum, [], [1, 2, 3]}
Then I put some pieces togather so I can see it easily:
(
ast = quote do: (
for n <- [1, 2, 3, 4], do: n * n
)
IO.inspect ast
IO.puts Macro.to_string ast
)
A bit more details can be found here, on `quote` and `unquote`:
iex> Code.eval_quoted(quote do: 1 + 2 * 3)
{7, []}
In this slide there’s a nice overview of AST of Elixir
Also this article, just a simple glance on how AST is working and used.
Understanding Elixir macros, total 6 posts, I mainly focused on two of them:
`quote` `unquote` and `expansion`
Talks on structure of AST, macro of `assert`
Ans this book is useful too.