duanliang1898
2015-05-07 05:11
浏览 82
已采纳

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

I am using the go/ast and go/parser package to do something, but i am puzzled about the difference between Doc and Comment.

Is the first line of comments a Doc, then others as Comment?
Here is a sample:

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
}

图片转代码服务由CSDN问答提供 功能建议

我正在使用 go / ast go / parser 做某事,但我对 Doc Comment 之间的区别感到困惑。

是注释的第一行 Doc ,然后其他为 Comment
这是一个示例:

  TypeSpec struct {
 Doc  * CommentGroup //相关文档; 或nil 
 Name * Ident //类型名称
 Type Expr // * Ident,* ParenExpr,* SelectorExpr,* StarExpr或任何* XxxTypes 
 Comment * CommentGroup //行注释; 或nil 
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsfdsfdsfdsf1223 2015-05-07 05:20
    已采纳

    From src/go/ast/ast.go#L70-L75:

    // A CommentGroup represents a sequence of comments
    // with no other tokens and no empty lines between.
    

    Following Godoc: documenting Go code:

    • Doc is one or several continuous lines of comments (// ...) 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 is a comment associate to the field itself, starting on the same line, but which can spread over multiple continuous lines (hence "CommentGroup")

      Name    *Ident        // type name
                            ^^^^^^^^^^^
                            // the comment associated to Name
                            // could go on over several lines
      
    点赞 打赏 评论

相关推荐 更多相似问题