Parser for ES6?
On Thu, May 7, 2015 at 5:37 PM, Park, Daejun <dpark69 at illinois.edu> wrote:
Is there any parser for ES6?
shapesecurity/shift-parser-js supports ES6/ES2015 RC2. You can read more about it here: engineering.shapesecurity.com/2015/04/two-phase-parsing.html
There's my crappy transpiler:
joeedh/fairmotion/tree/master/tools/extjs_cc
Which uses a parser generator (and yes, the standard is quite helpful in pointing out ways to make JS work in a bottom-up grammar). The grammar is inline with the code, so I've extracted it and attached it to this email. Note that I've extended the grammar a bit, mostly to implement a type annotation system but there are a few other non-standard things as well (I still need to replace my python-style multiline strings with template strings, for example). The grammar is also a bit messy.
I believe the only thing I'm missing is template strings and some of the new numeric literal stuff (e.g. binary literals). I just recently added a bunch of stuff in preparation to move my codebase to a different transpiler (one I don't have to maintain myself). Oh, and I think I'm missing yield assignments in generators (e.g. var x = yield y), too. Also, I'm not sure if arrow functions work in all cases, I have an ambiguity in my grammar there (which I don't feel like debugging because I'm switching to babel :) ).
The regular expression stuff is kindof interesting; figuring out how to parse RE literals wasn't easy (it's not strictly possible to parse them with a RE tokenizer, but I managed to hackishly make it work).
Joe
The Shift parser has, to my knowledge, the most complete support for ES6. You can try it out in the online demo at jsoverson.github.io/shift-visualizer. Note that the demo is using a slightly out of date parser, but I've asked the maintainer to update it ASAP.
The Closure Compiler parser is here:
google/closure-compiler/tree/master/src/com/google/javascript/jscomp/parsing/parser
I know it is still missing new.target, I believe it is otherwise up to date.
Is there any parser for ES6? It seems that no implementation completely supports ES6 yet (kangax.github.io/compat-table/es6), and I'm just curious to see if there is at least a parser supporting all the features of ES6. For example, the grammar given in the spec seems to be fit to a parser generator, and I wonder if the grammar has been mechanized in such a parser generator or is just a written spec.
Best, Daejun