A short story of adding Scala support to AST Explorer
You can type some code in, it gets parsed on the fly and you get an interactive AST that you can explore. Also, you can play around with tools that work on AST, such as linters, compilers and code-shifting tools.
All of this, directly in your browser, no need to install anything. It is wonderful.
I finished my talk, went for some food and beers with friends, and I started thinking “it would be really cool if we had this for Scala!”.
Then the realization: we can have it!
The quest for a Scala parser in JS
The first tool that came to mind is Scalameta, a meta-programming toolkit for Scala whose AST representation is at the core of many present and future Scala tools (macros, migration tools, code formatters etc). Conveniently, Scalameta provides its own parser module.
And let me tell you: publishing a Scala library to npm was something!
Try it out, and be sure to provide feedback!
I’m standing on the shoulders of giants, and my tiny contribution is just glue to stitch together the great work of others that I’d like to thank.
First, Eugene Burmako (author of Scalameta) and Ólafur Geirsson(maintainer of Scalameta and author of Scalafmt and Scalafix): they have been very supportive, by providing help and feedback and reviewing the PRs on Scalameta at the speed of light.
Also, thanks to Sébastien Doeraene and the Scala.js team. Their work to bridge the gap between Scala and JS is what made this kind of tools possible.
I think this is an exciting step for everyone involved in meta-programming. AST Explorer makes experimenting with ASTs incredibly easy and I’m sure it will facilitate the life of anyone willing to build on Scalameta.
Now that we have parsing, I’d love to experiment on transformations, another interesting feature of AST Explorer. Imagine sketching a macro or a Scalafix rewrite directly in the browser, wouldn’t it be amazing?