go/ast 包中的 Doc 和 Comment 有什么区别?

What is the difference between Doc and Comment in go/ast package?

我正在使用 go/astgo/parser 包来做一些事情,但我对 DocComment 之间的区别感到困惑。

第一行评论是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是一行或几行连续的注释(// ...) before the 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 是与字段本身关联的注释,从同一行开始,但可以分布在多个连续行(因此"CommentGroup")

    Name    *Ident        // type name
                          ^^^^^^^^^^^
                          // the comment associated to Name
                          // could go on over several lines