need some guidance on Python syntax smart editor for use with speech recognition

Chris Angelico rosuav at gmail.com
Mon Jan 5 13:24:29 CET 2015


On Mon, Jan 5, 2015 at 8:34 PM, Jonas Wielicki <jonas at wielicki.name> wrote:
> As a first iteration, I would try with any editor written in Python.
> Are you familiar with the ast[1] module? It could be worth trying to
> use this module and perform some kind of pattern matching on the
> results to recover the information.

An AST parse throws away a lot of information. You can't easily
reconstruct the original code from that; at best, you can decompile
the AST back into functionally-equivalent source code, but it's not
something you want to do as part of editing code. There's an
Unparser() in CPython/Tools/parser/unparse.py [1] which is great for
visualizing an AST structure, but if you take a .py file, compile it
to AST, and then unparse it, you'll end up with something quite
different.

However, back when I was doing my PEP 463 research, someone suggested
looking into the 2to3 parser. I regretfully admit that I have yet to
actually do so, but it ought in theory allow source-level
transformations with a measure of intelligence. It's not a ready-made
solution by any means, but it could be a useful tool. [2]

> Hope this helps. I find that topic pretty interesting. Is there
> anything I can follow to see progress on this?

Likewise!

ChrisA

[1] https://hg.python.org/cpython/file/tip/Tools/parser/unparse.py
[2] http://time-loop.tumblr.com/post/47664644/python-ast-preserving-whitespace-and-comments



More information about the Python-list mailing list