Hi
I've done some work on a framework for AST translation. My starting point is that many Unix programs (such as grep) are an adaption of copying stdin to stdout.
Here we want Python source in and JavaScript source out. And we're going via an AST.
So our starting point (similar to cat) is
1) Python source to Python AST (already provided by ast.parse).
2) Python AST to Python AST (but a deep copy, not simply returning the argument).
3) Python AST to Python source.
I've written some code that takes us in that direction. In particular it defines an AbstractSyntax base class and if you inherit from it you get a deep copy. I've also defined and AbstractTranslator base class, which provides a framework for all the syntax class translation functions.
It's in the toys branch, at
http://bitbucket.org/PeterRust/py2js/changeset/6de4c091c459The next tasks are to complete (3) and also
4) Python AST to JsPy AST
The JsPy AST is similar to the Python AST (and can share many of its classes if we wish) but it provides the appropriate starting point for generating JavaScript, and for further transformations.
Thus, a JsPy AST contains only items we can deal with in JavaScript. It would contain Yield, for example. Each function will have Locals and Globals fields.
The basic idea of a JsPy AST is that one can easily generated JavaScript from it, and one can easily transform it in various ways.
--
Jonathan
--
You received this message because you are subscribed to the Google Groups "JavaScript for Python programmers" group.
To post to this group, send an email to
js...@googlegroups.com.
To unsubscribe from this group, send email to
js4py+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/js4py?hl=en-GB.