英文:
Is there any parser for go:generate directives?
问题
似乎标准的doc包无法解析go:generate注释。有什么办法可以获取这些注释吗?
英文:
It seems the standard doc package is not parsing go:generate comments. Any idea how can I get those comments?
答案1
得分: -1
go/parser
包是标准库中的一个包,它可以获取一个 ast.Package
值,表示一个单独包的抽象语法树。这个树包含了 ast.Comment
节点,你可以通过它们的 Text
字段轻松访问它们的文本内容。
编辑:
Dewy Broto 提供了一个更直接的选项,即调用带有 ScanComments
标志设置为 true
的 go/scanner
包。不需要构建 AST 来查找注释。
英文:
Package go/parser
in the standard library gets you an ast.Package
value, representing an abstract syntax tree of a single package. This tree includes ast.Comment
nodes, whose textual content you can easily access through their Text
field.
Edit:
Dewy Broto contributed: A more direct option is to call the go/scanner package with the ScanComments flag set to true. There's no need to build an AST to find the comments
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论