Question

Is it possible to take a quoted Elixir expression (AST tree) like this:

quote do: 1 + 1
=> {:+, [context: Elixir, import: Kernel], [1, 1]}

And convert it to an Erlang AST?

I looked through the Code module as well as some of the Kernel modules looking for a function that did this but I didn't find anything. I am not even sure if this would be possible... I don't know how things like Elixir macros would be represented in Erlang AST.

Thanks in advance!

Was it helpful?

Solution

There isn't currently a public API to do so. You could look into the elixir module to know how it is done but it is private API and it can be changed any time with no guarantee of compatibility, or even removed.

OTHER TIPS

For example I wrote 'gist' how it can be done - https://gist.github.com/habibutsu/bc6791d3d81b6ea54e1a

There are used two functions:

fun elixir:'string_to_quoted!'/4
fun elixir:quoted_to_erl/3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top