Standard library / go/scanner
go/scanner.ScanComments
Returns comment tokens rather than skipping them. Expected stdout: 'COMMENT // note\n'.
Formal Syntax & Structure
go syntaxgo
const ScanComments Mode = 1 << iotaWorking Example
Example Snippetgo
package main
import ( "fmt" "go/scanner" "go/token")
func main() { src := []byte("// note") var s scanner.Scanner s.Init(token.NewFileSet().AddFile("demo.go", -1, len(src)), src, nil, scanner.ScanComments) _, t, l := s.Scan() fmt.Println(t, l)}