Python 2.0 parser module bug(?) and a Q

murple at my-deja.com murple at my-deja.com
Mon Jan 22 05:07:15 EST 2001


Hi,

> > A  colleague of mine has an "unparser" module for Python AST; that
is
> > not (yet) released to the public, and works not (yet) for 2.0.

I'm the colleague mentioned. My solution to the
problem doesn't look as good as yours:

I was  rebuilding the Python-code by examining the structure of the
syntax-tree.
This is also the reason,why it's not working with Python 2.0.
I was using the strings in the syntax-tree
only for identifiers. Feeling a little bit
stupid for not seeing this other solution.

> Any constructive critisism is welcome!

Ok, your wish is my command :-)

I noticed two problems:

1. If you have double DEDENT, there is a
'\r' left in the resulting string. This
seems to be easely solved by an replace()

2. Anything like "modul.class.function" comes out
as "modul  . class . function". Using replace
to solve this is not good, since you would replace
also in wrong places. I think, here you would have
to look into the structure of the syntax-tree.

Maybe you have an solution for 2.?

Another question is, which way is faster.
You have to do more recursions, because when
I find a symbol.sym_name["class_stmt"] in the tree, I write a "class",
you go another step to find the "class"-string in the tree.
On the other side, I have to do a lot more comparisons then you do.

Maybe after a code-cleanup I will compare the
solutions.

Anyway, I learned a lot about Python by doing
this Unparser (as I call it). It was my first
Python-program ever. And I learned a lot about
Python-Syntax this way.

Hope my comments help you in any way.

By, Andreas


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list