Standard library / go/parser

go/parser.ParseComments

Retains comment groups in the AST. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
const ParseComments Mode = 4

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/parser"  "go/token")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  f, e := parser.ParseFile(token.NewFileSet(), "demo.go", "// note\npackage demo", parser.ParseComments)  check(e)  fmt.Println(len(f.Comments))}
Go Reference