6 ms·
The Go library's standard AST package[1] similarly stores comments and whitespace information. It has to, since it's used by gofmt, and you wouldn't be very hap
by edsrzf 10y ago
The Go library's standard AST package[1] similarly stores comments and whitespace information. It has to, since it's used by gofmt, and you wouldn't be very happy you lost comments when formatting your code.
[1] https://golang.org/pkg/go/ast/ https://golang.org/pkg/go/ast/
- nemo1618 10y agoUnfortunately, most people agree that the ast package is a mess. It isn't used by the actual compiler. There is some talk of eventually deprecating it and publishing the internal ast/parser/type-checker packages.
- edsrzf 10y agoI think calling it a "mess" is hyperbole, but yes, it's true that it has shortcomings and may be deprecated and replaced.
- placeybordeaux 10y agoI've used it before for a tool that transforms code that throws away an error code to code that takes the error code and panics if not nil. https://github.com/placeybordeaux/panic-attack https://github.com/placeybordeaux/panic-attack The package works fine, but I can't say it was fun to work with.
- bpicolo 10y agoIf I remember correctly rust-fmt deals with comments without them being explicitly part of the ast. Sure creates more work though