-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Comment node (for code generation purposes) #50
Comments
Sounds like an awesome idea to me! |
+1! Please send a pull request :) |
Closing for now; anyone who really wants the comments is welcome to re-open and work on the pull. |
I think this should be left open. There might be someone out there who are looking for an issue to contribute to an open source project and it's not easy to find closed issues on GitHub. |
- Add a test for subclassing that shows how to add custom nodes for comments, as requested in issue #50.
I've added an example of how to do this in PR #75. So we should possibly document it, but I think the code is done. |
The solution seems here : 4a152b8 |
Although the AST does not include a Comment node, it is frequently a good idea to insert comments into generated code. It's possible to wrap textual comments in a string instead, but it doesn't look as nice.
I've been experimenting and it looks like it should be feasible to add a custom Comment node (inheriting from ast.Expr, possibly).
The really interesting bit is when you allow the Comment's value to be not just strings, but other AST nodes. In this case you could generate syntactically-valid and properly indented commented-out code.
I've got this working for single line statements and I think I can do it for multiple line blocks like function definitions as well. However, before I go further I want to be sure something like this would be accepted into the project.
The text was updated successfully, but these errors were encountered: