Anyone seen a Javascript interpreter in Python?

holger krekel pyth at devel.trillke.net
Tue Dec 10 12:08:33 EST 2002


Brian Kelley wrote:
> > I've never seen it actually done but it's not that bad idea and I've
> > thought about it on various occasions, mostly for the purpose of
> > writing robot web clients in Python that could deal with JS on
> > downloaded pages.  Pythoneers don't like to admit it but Python's
> > semantics are not that distant from JS's.
> 
> Tell me about it.  I wrote a XUL (mozilla's layout format) interpreter 
> in python and was suprised to discover that all the JavaScript commands 
> used as callbacks in their tutorials were also valid python commands.

btw, has anyone done an "pythonic syntax" javascript variant?  I look into 
having javascript without curly braces and ';'.  

I intend to implement *very small* conversion code both in javascript and 
python. Here is an example on how javascript would then look like:

def TransportDriver_http (parent):
	this.p = new XMLHttpRequest()
	this.parent = parent
	
	def load(filename, callback):
        var docu = document.implementation.createDocument("","",null)
        docu.loader = this.parent
		if (callback):
			docu.onload = callback
		else: 
			docu.onload = this.parent.xmlloaded
		docu.load(filename)
        return docu
	TransportDriver_http.prototype.load = load


def  translates to   function
:    translates to   {}ing the following indented block
\n   translates to   ;

There would probably only be a small user base but i would
be among them, i guess :-)  For me it's just to tiresome when 
switching often from python server code to client javascript code.

And for pythonistas it's still immediately recognizable as
javascript because of "this", "var" and other oddities :-)

regards,

    holger




More information about the Python-list mailing list