[Python-Dev] AST manipulation and source code generation

Andy Gross andy at andygross.org
Wed May 25 19:31:34 CEST 2005


I wrote something like this (called pyunparse) a little while ago.   
It's not the cleanest code in the world, but it worked for my  
original use case (debugging Logix, which uses python ASTs as an IR):

http://www.pycs.net/users/0000445/stories/7.html

Cheers,

/arg




On May 24, 2005, at 9:56 AM, Jeremy Hylton wrote:


> On 5/24/05, Ka-Ping Yee <python-dev at zesty.ca> wrote:
>
>
>> Would there be any interest in extending the compiler package with  
>> tools
>> for AST transformations and for emitting Python source code from  
>> ASTs?
>>
>>
>
> Sure.  Eventually, we'll have to figure out how to unify the compiler
> package AST and the ast-branch AST, but don't let that delay you now.
>
>
>
>> I was experimenting with possible translations for exception chaining
>> and wanted to run some automated tests, so i started playing around
>> with the compiler package to do source-to-source transformations.
>> Then i started working on a way to do template-based substitution of
>> ASTs and a way to spit source code back out, and i'm wondering if
>> that might be good for experimenting with future Python features.
>>
>> (If there's already stuff out there for doing this, let me know --
>> i don't intend to duplicate existing work.)
>>
>>
>
> I don't know of any existing work, but it certainly sounds useful.
>
> Jeremy
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/andy% 
> 40andygross.org
>
>




More information about the Python-Dev mailing list