Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
go/ast: optionally save comments #29821
go/ast doesn't save comments in the tree when a file is parsed, (they are kept in the field
I thought @griesemer's plan was to address this in the new syntax tree package.
Also, have you seen https://golang.org/pkg/go/ast/#CommentMap? It should solve most issues related to the relation of comments with nodes.
I'd also imagine that the
cmd/compile/internal/syntax has the tentative data structure for attached comments but doesn't actually do it at the moment (or whatever is there is not fully functional). The long-term plan is to make that happen, but it's not a high priority.
Also given the fact that all existing tools working on ASTs would have to be adjusted, in the short term it may be better to have an extra parser mode that does attach comments to go/ast nodes. Those nodes could be extended w/o imperiling existing code.
Please keep me in the loop if this is something you plan to work on. There's pre-existing work and we don't need to re-invent the wheel. Also, there are a lot of considerations regarding memory use.