seek python parser

E

Evil Bastard

Hi,

Does anyone know of a python source parser program which can return the
parsed source file as a coherent dom-like data structure?

I'm playing around with ast, and the output of ast.tolist(), but it's
got a lot of chaff, and would need a lot of hacking to break it down to
simple data structures

All recommendations appreciated
 
P

Paul Boddie

I tend to use the compiler module:

http://docs.python.org/lib/compiler.html

With the output of the parsing functions I selectively inspect the AST
nodes using the named attributes listed in the documentation:

http://docs.python.org/lib/module-compiler.ast.html

For cases where one just needs to traverse the child nodes of an AST
node, the getChildNodes method is probably more helpful than the
getChildren method, which returns things like name strings and other
miscellaneous information mixed up with the list of nodes.

If you want a genuine XML DOM version of a Python AST, the following
project might provide you with a solution:

http://pysch.sourceforge.net/ast.html

See also:

http://uucode.com/texts/genxml/genxml.html

Paul
 

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

Forum statistics

Threads
474,262
Messages
2,571,311
Members
47,983
Latest member
Derek9890

Latest Threads

Top