Pyjaco - Python to JavaScript translator.
github.com
github.com
Last year, I wrote a comparison of the ones I could find, but none of them actually was in very good shape: http://chargen.blogspot.com/2011/08/survey-of-python-to-java...
I'm in the very early stages of porting an app from Python to Javascript, and I have no illusion that it's going to work out of the box from a translator (lots of third party libraries, and switching from server side to client side). But it would be nice if at least some of the obvious syntax could be translated.
However, all of the several translators I've tried simply die with a message like "this library is not supported" or "this language feature isn't supported" and then they produce absolutely no output, which isn't any help at all. Are there any translators that will simply skip over stuff they don't understand while translating stuff they do understand?
Also, side note, those floating boxes on the right side of your blog make it impossible to grab the scrollbar thingie when it is under them, as it is near the top of the page, which is very annoying to me.
I'm not sure how a converter could "skip over stuff it doesn't understand while translating stuff it does understand": it may make sense to work on "small" translation units (e.g., a function or method), but the code that comes out of the translation of a unit should be -at least syntactically- correct in the target language. Indeed, the more mature Python-to-C translators (e.g., Cython) do restrict the Python that are allowed in the source file, and refuse to compile the entire file if your code contains unsupported syntax.
If you are willing to invest some effort into adapting a translator yourself, (besides Pyjaco! :-)) PJS and Py2Js are both very clean and easy to understand/patch. Although they are no longer developed, they might provide a good starting point to build the "simple minded" translator that you would like to have.
(Thanks for the remark on the blog layout - I just picked one of the standard styles and did not pay much attention to the details.)
Unfortunately, the error reporting of the live demo isn't very helpful at this stage. I quickly ran into some compilation errors:
syntax not supported (IfExp: <_ast.IfExp object at 0x7f161d834a10>)The unique trouble I found by myself is that list comprehension are not fully supported.
[x for x in (1, 2, 3, 4) if (x % 2) == 0]
This won't work as expected. I opened an issue about this: https://github.com/chrivers/pyjaco/issues/69True
ok, I love this thing already!
wow, it also knows about bound-methods https://gist.github.com/2947907 , no need to hack with _.bindAll().