wende / elchemy

Write Elixir code using statically-typed Elm-like syntax (compatible with Elm tooling)
https://wende.github.io/elchemy/
MIT License
1.15k stars 28 forks source link

Consider movement from outputing code to outputting ast. #283

Open wende opened 6 years ago

wende commented 6 years ago

Back when Elchemy started a year ago producing an output as a binary was an obvious choice because of readability. Right now, however, with an Elixir formatter being built-in and generally much nicer tools to produce readable code out of AST it's worth considering if overhauling the compiler from

Elchemy Code -> Ast -> Elixir Code

to

Elchemy Code -> Ast -> Elixir Ast -> Elixir Code

Pros:

Cons

OvermindDL1 commented 6 years ago

I'd definitely output AST, feed that through Macro.to_string then feed that through Code.format_strring!.

Removes the possibility of doing dirty tricks with the code (double edged sword though)

Actually this is entirely incorrect. Elixir itself is a reduced syntax, the AST can actually represent a lot of code that is just entirely invalid in Elixir's syntax itself (obviously you'd want to make sure to put in appropriate unquote's and such in the AST to allow the syntax itself to properly represent it if you want to format it). :-)

wende commented 6 years ago

Since this card requires Elixir parts that'd mean it first needs Elchemy to be run in its self-hosted version or we'd need to store the AST in intermediate files. Either way it's a too low in terms of bang for the buck ratio for right now.

It should stick around here until it's time for it though