views:

2554

answers:

4

There is a JavaScript parser at least in C and Java (Mozilla), in JavaScript (Mozilla again) and Ruby. Is there any currently out there for Python?

I don't need a JavaScript interpreter, per se, just a parser that's up to ECMA-262 standards.

A quick google search revealed no immediate answers, so I'm asking the SO community.

A: 

Maybe PyWebkitGtk? There's also PyXPCOM for Gecko. Haven't used either myself.

codelogic
+7  A: 

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

The ANTLR site provides many grammars , including one for JavaScript.

As it happens, there is a Python API available - so you can call the lexer (recognizer) generated from the grammar directly from Python (good luck).

gimel
this might be exactly what I need, as I actually want to extend the standard javascript grammar. thanks!
Claudiu
+3  A: 

You can try python-spidermonkey It is a wrapper over spidermonkey which is codename for Mozilla's C implementation of javascript.

swamy
A: 

http://code.google.com/p/pynarcissus/ seems to have a parser. I'm not sure what state it is in, but it looks to be complete.

pib