To support tooling that retains comments, like a format tool (such as gofmt), AST nodes should have comments attached to them. How they'll be attached is another question -- possilby with Before []*Comment and Line *Comment fields? That way commends preceding a node are bundled up in before, along with an end-of-line comment.
Reformatting would want to preserve at least one line break between comment blocks, but comment tokens should already retain their line number to make that easier.
This one needs some thinking to determine how to support it, since initial codf design supports comment tokens but does not preserve them in the AST. (Maybe tools shouldn't use the parser?)
To support tooling that retains comments, like a format tool (such as gofmt), AST nodes should have comments attached to them. How they'll be attached is another question -- possilby with
Before []*CommentandLine *Commentfields? That way commends preceding a node are bundled up in before, along with an end-of-line comment.Reformatting would want to preserve at least one line break between comment blocks, but comment tokens should already retain their line number to make that easier.
This one needs some thinking to determine how to support it, since initial codf design supports comment tokens but does not preserve them in the AST. (Maybe tools shouldn't use the parser?)