I need to add some lightweight syntactic sugar to JavaScript source code, and process it using a JavaScript-based build system. Are there any open source JavaScript parsers written in JavaScript? And are they reasonably fast when run on top of V8 or a similar high-performance JavaScript implementation?
Thank you for any pointers you can provide!
UglifyJS (JS compressor/beautifier in JavaScript) contains a complete JavaScript parser that exposes a simple API. It's heavily tested and used in some big projects (WebKit).
Crescent Fresh answered this question in the comments:
https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API:
Note that this is only an API in JavaScript, the parser is C++.
The fastest Javascript parser in Javascript was esprima.
It also gives you
acorn is a really fast JavaScript parser written in JavaScript. It's even faster than esprima now. The results I got in Chrome form esprima's speed comparison page:
It's compatible with Mozilla's Parser API, so you can use escodegen to generate JavaScript from the parse trees.
The only metacircular interpreter that I have seen implemented in JavaScript is the Narcissus Engine.
It was developed also by Brendan Eich, they used a lot of non-standard extensions that are specific to SpiderMonkey, I think it will not work on V8.