berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

Pretty-printing enhancements for decompiler. #34

Closed pmaupin closed 9 years ago

pmaupin commented 9 years ago
berkerpeksag commented 9 years ago

Sorry for my late response. Can we keep pretty printing related code in a single file(prettyprint.py instead of *_repr files)? Also, SetPrecedence can stay in code_gen.py or misc.py/utils.py. Adding a new module for every class look like a bit Java to me :)

pmaupin commented 9 years ago

That's entirely possible. I'm still refactoring the precedence to get the corner cases right, and may change how I do the tree walk (and do it all in one). I have some pretty good test code now.

As far as the _repr files, it may be that the reformatting of the entire output is quite involved with a lot of subfunctions. That's why I broke it out for now. If that turns out not to be the case, then sure.

Thanks, Pat

pmaupin commented 9 years ago

Berker:

This is done, except for wrapping long Python lines. It has been exhaustively tested against everything in all my python libraries, plus some generated expression permutations. I think it is ready to merge into the master, and perhaps we can add long line support later.

I took your suggestion of moving the precedence handling in with code_gen (it now even occurs on the same tree walk).

OTOH, I did not take your suggestion about merging the beautification of the strings with the TBD beautification of the source code. The reason for this is that the string handling has a LOT of fugly 2 vs 3, str vs unicode crap, and I don't think that will be needed, useful, or wanted to look at when doing other stuff.

pmaupin commented 9 years ago

@berkerpeksag

FWIW, I noticed that the pretty_print changes don't diff very well, which may be part of why you haven't gotten to this. My git-fu is getting stronger -- let me pull out a few changes from pretty-print into a pre_pretty_print branch to be merged first. I think if I do that right, the story on the master branch will look more coherent.

pmaupin commented 9 years ago

OK, I pulled some of the easier stuff out into a code_gen_cleanup branch. You should look at that and merge it into master first if you think it's OK, and then the diffs from there to this branch are much smaller.

Thanks, Pat

pmaupin commented 9 years ago

I have merged this into the pm_develop branch