A
Avner Ben
Hi,
I am working on a reverse-engineering system that relies on comments. I
have taken a look at the "compile" module in the Python library. Quite
expectedly, the AST does not contain comment lines. The only exception I
have noticed is the very first comment in the source, which is
interpreted as the module's docstring and is surprisingly also stored in
the AST as a "discardable"-type node. This leaves me with the dismal
task of reading the source on my own, parsing the comments and then
matching them with the AST through the lineno node attribute. Which is a
waste, because the compiler has been there before me. (For my own
reasons, I had rather use comments than resort to such esoteric but
compiler-friendly means as dummy variables etc.)
My question: Is there a way to configure the Python compiler to keep All
comments from the source as AST nodes (e.g. "discardable")?
Avner.
I am working on a reverse-engineering system that relies on comments. I
have taken a look at the "compile" module in the Python library. Quite
expectedly, the AST does not contain comment lines. The only exception I
have noticed is the very first comment in the source, which is
interpreted as the module's docstring and is surprisingly also stored in
the AST as a "discardable"-type node. This leaves me with the dismal
task of reading the source on my own, parsing the comments and then
matching them with the AST through the lineno node attribute. Which is a
waste, because the compiler has been there before me. (For my own
reasons, I had rather use comments than resort to such esoteric but
compiler-friendly means as dummy variables etc.)
My question: Is there a way to configure the Python compiler to keep All
comments from the source as AST nodes (e.g. "discardable")?
Avner.