10 ms·
For anyone thinking about building a language with a JavaScript target, I would strongly recommend building on Babel. I've found the tooling to be terrific. In
by rattray 10y ago
For anyone thinking about building a language with a JavaScript target, I would strongly recommend building on Babel. I've found the tooling to be terrific.
In my case, I wanted to build a (rough) superset of JS, adding the syntax and language features I was interested in but otherwise starting from a working (tested!) language. This made the task dramatically easier.
Forking babylon, Babel's parser, worked well for this in my case, but you could also write your own parser from scratch and use babel-types to build your AST.
In my case, I have a ~1,000-LOC babel plugin "compiler"[0] with maybe 1,000~2,000 LOC of mods to the parser[1], resulting in a language that looks fairly different from JS but feels pretty solid. Users of the language benefit from Babel's tooling – it works with webpack, ESLint (decently), etc.
[0] https://github.com/lightscript/babel-plugin-lightscript/ https://github.com/lightscript/babel-plugin-lightscript/
[1] https://github.com/lightscript/babylon-lightscript https://github.com/lightscript/babylon-lightscript
- deleted 10y ago[deleted]
- ftomassetti 10y agoThis sounds awesome! Another good thing to add to the list
- deleted 10y ago[deleted]
- mark_l_watson 10y agoThanks for the reference to your project, I might use it as a guide for writing a language. I like the book "Build Your Own Lisp" because the simple implementation is easy enough to understand and hack. Using your example as a guide would be a second step for building something more practical. Very cool stuff.
- rattray 10y agoThanks! Would be happy to help – email is in my profile if you're interested.