我正在使用 go/ast
和 go/parser
包来做一些事情,但我对 Doc
和 Doc
之间的区别感到困惑注释
。
第一行注释是Doc
,然后是Comment
吗?
这是一个示例:
TypeSpec struct {
Doc *CommentGroup // associated documentation; or nil
Name *Ident // type name
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
Comment *CommentGroup // line comments; or nil
}
最佳答案
来自 src/go/ast/ast.go#L70-L75
:
// A CommentGroup represents a sequence of comments
// with no other tokens and no empty lines between.
正在关注 Godoc: documenting Go code :
Doc
是一行或几行连续的注释 (//...
) 在TypeSpec
之前
write a regular comment directly preceding its declaration, with no intervening blank line
// A TypeSpec node represents a type declaration (TypeSpec production).
^^^^^^^^^^^^...
TypeSpec struct {
Comment
是与字段本身关联的注释,从同一行开始,但可以分布在多个连续行(因此“评论组
")Name *Ident // type name ^^^^^^^^^^^ // the comment associated to Name // could go on over several lines
关于go - go/ast 包中的 Doc 和 Comment 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30092417/