Ast tree and python code

Y

Yermat

Hi,

Does someone know how I can reverse an AST tree back into python code
with few modification ?
What I want to do is to complete trees before writing them back but in a
way not to far from the original code ? Especially, indentation, line
return, etc.

Of course, I could program it myself but if someone already done it...

Yermat
 
I

Ira Baxter

Yermat said:
Does someone know how I can reverse an AST tree back into python code
with few modification ?
What I want to do is to complete trees before writing them back but in a
way not to far from the original code ? Especially, indentation, line
return, etc.

Of course, I could program it myself but if someone already done it...

If you insist on doing this in Python, I don't have any help.

Otherwise, if you want to carry out arbitrary transforms on Python code,
you might be interested in the DMS Software Reengineering Toolkit.
It parses many languages (including Python) into a language
specific AST, can carry out source-to-source transformations
on those trees, and can then prettyprint source text from
those tree. It retains comments, indentation, the
format of numbers, you name it.

See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top