[sugar] Education?
Antoine van Gelder
hummingbird at hivemind.net
Sun Mar 11 13:02:11 EDT 2007
Guido van Rossum wrote:
> On 3/11/07, Antoine van Gelder <hummingbird at hivemind.net> wrote:
>> Anyone know the current status of being able to turn an AST tree emitted
>> by the Python compiler module back into code after it has been modified ?
>
> The word "code" is ambiguous in the context.
Apologies - am still deciding on what I need - thanks for taking the
time to address both meanings.
> If you meant byte code, the final stage of the compiler should be able
> to do that just fine.
Aha! Was not aware that this was already possible! Best to start digging
in compiler.pycodegen ?
> If you meant to turn a tree back into source code, I wrote a tool that
> can do this for the purpose of transforming Python 2 source code into
> Python 3 source code. It doesn't use the same parse tree datatype that
> the compiler uses, but it's very handy for source-to-source
> transformations, as it retains the exact formatting, comments etc. of
> the input source code (to the extent possible given transformations,
> of course). It's not yet documented, though I have a few users helping
> out writing transformations already. Check it out in our repository:
> http://svn.python.org/view/sandbox/trunk/2to3/
This is useful. Thank you!
> I hope you weren't merely stating a rhetorical question.
Spent the weekend starting to play with a little toy visual scripting
editor that takes an AST generated from a python source file by
compiler.parse() as input and am having some wonderings about the best
way to go from the edited AST to:
a) byte code for execution
b) back to source code for non-visual editing
Of course if I have b) I could simply recompile but I think it would be
neat to not go the long way round :-)
Thanks Guido!
- antoine
More information about the Sugar
mailing list