Skip to content
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

Open
inklesspen opened this issue Dec 3, 2015 · 6 comments
Open

Add Comment node (for code generation purposes) #50

inklesspen opened this issue Dec 3, 2015 · 6 comments

Comments

@inklesspen
Copy link

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.

@pmaupin
Copy link
Collaborator

pmaupin commented Dec 3, 2015

Sounds like an awesome idea to me!

@berkerpeksag
Copy link
Owner

+1! Please send a pull request :)

@pmaupin
Copy link
Collaborator

pmaupin commented Apr 22, 2017

Closing for now; anyone who really wants the comments is welcome to re-open and work on the pull.

@pmaupin pmaupin closed this as completed Apr 22, 2017
@berkerpeksag
Copy link
Owner

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.

@berkerpeksag berkerpeksag reopened this Apr 24, 2017
@berkerpeksag berkerpeksag removed this from the 0.6 milestone Apr 24, 2017
pmaupin added a commit that referenced this issue Apr 30, 2017
 - Add a test for subclassing that shows how to add custom
   nodes for comments, as requested in issue #50.
@pmaupin
Copy link
Collaborator

pmaupin commented Apr 30, 2017

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.

@pmaupin pmaupin added this to the 0.6 milestone Apr 30, 2017
@berkerpeksag berkerpeksag removed this from the 0.6 milestone Oct 31, 2017
@mathben
Copy link

mathben commented Nov 19, 2021

The solution seems here : 4a152b8

@berkerpeksag berkerpeksag mentioned this issue Jan 4, 2025
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants