Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider movement from outputing code to outputting ast. #283

Open
wende opened this issue Feb 5, 2018 · 2 comments
Open

Consider movement from outputing code to outputting ast. #283

wende opened this issue Feb 5, 2018 · 2 comments

Comments

@wende
Copy link
Owner

wende commented Feb 5, 2018

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:

  • Better (hopefully) readability
  • A lot less unnecessary parens
  • Much better support of line ordering (it might even be possible to do 1 to 1 line representation)
  • Smaller chance of making a mistake in output code
  • Much more universal and easier to reason about
  • !!! FREE MACROS !!!

Cons

  • Time taking
  • Additional layer of abstraction
  • Might be harder to manage
  • Removes the possibility of doing dirty tricks with the code (double edged sword though)
  • A lot of work for (almost) no added functionality for the end user
@OvermindDL1
Copy link

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
Copy link
Owner Author

wende commented Feb 8, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants