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

标签 go abstract-syntax-tree

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

第一行注释是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/

相关文章:

go - 带逗号与或的 bool 开关

typescript - 在类型检查之前转换 typescript

go - Go中的设计模式

go - 在设置 Hyperledger 开发环境和网络时获取 grpc 超时

python - 如何将 python 比较 ast 节点转换为 c?

java - 使用 groovy AST Transform 修改 java

c++ - 递归下降解析器问题

java - 如何使用 JDT 以编程方式重命名方法

unit-testing - 如何使用定义为常量的文件路径来测试 Go 代码

go - Go中有 move 语义吗