I would
appreciate it if you would read the thread in detail, and let me know if
the following reply seems on topic and useful. Thanks.
> So if users want to write tools that manipulate Python code, the standard
library doesn't provide them with great options.
> I suggest the following plan:
Hello all,
I would like to suggest another possibility.
For
about three months I have been obsessed with the general problem of
manipulating Python source code *easily*. I have long experience with
such tools. Along the way I have studied the
[asttokens](
https://pypi.org/project/asttokens/),
[fstringify](
https://pypi.org/project/fstringify/), and
[black](
https://pypi.org/project/black/) projects.
Imo,
each in its own way illustrates that something significantly better
would be welcome. Each project uses complex, idiosyncratic, opaque
generators to generate results. What if something much simpler were
possible?
In late October, 2019 I completed a token-based version
of fstringify. I could have stopped there, but then a new thought
intruded. What if we could define a **token-order traversal** of parse
trees? This new idea sparked an avalanche of new ideas. I couldn't let
them go.
After three months of literally day and night
development this single idea has turned into a major new tool, contained
at present in [leoAst.py](
https://github.com/leo-editor/leo-editor/blob/fstrings/leo/core/leoAst.py). The code is simple, general, flexible, and fast, in stark contrast to the tools mentioned above.
Leo's [issue #1440](
https://github.com/leo-editor/leo-editor/issues/1440) (Unify the ast and token worlds)
contains
extensive documentation for this project. The first comment contains an
overview of the project, the second comment contains a Theory of
Operation, and the third contains a History of the Project, with links
to the many Engineering Notebook (ENB) post that I wrote along the way.
Imo,
the TokenOrderGenerator (TOG) and TokenOrderTraverser (TOT) might be
candidates for inclusion in the standard library, but first you Python
devs will want to decide whether this project is actually something that
is even vaguely of interest to you :-)
I will be happy to answer any questions you may have. Please let me know your thoughts.
Edward K. Ream
An old man, crazy about computer programming