views:

280

answers:

4

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!

+1  A: 

It's not a JavaScript parser itself, but there's a project called Jison (like Bison) for generating parsers that's written in JS.

alunny
+1  A: 

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.

CMS
Interesting! I suppose there's a parser hiding in there somewhere. :-) Unfortunately, I'm looking for something that runs under V8. But thanks for the very interesting link!
emk
A: 

What about just using eval() ?

xavierm02
eval doesn't parse code, it runs it.
emk
Right..........
xavierm02
+2  A: 

Crescent Fresh answered this question in the comments:

JSLint contains a JavaScript parser written in JavaScript. See jslint.com/fulljslint.js Around line 2049 begins the parser. JSLint is written to also handle html so you'd have to gloss over those parts

emk
Crescent Fresh, if you'd like to repost your comment as an answer, I'll accept it and upvote you.
emk