Golang go/ast.CommentMap type and NewCommentMap() function example
package go/ast
A CommentMap maps an AST node to a list of comment groups associated with it. See NewCommentMap for a description of the association.
Golang go/ast.CommentMap type and NewCommentMap() function usage example
Example( taken from http://golang.org/pkg/go/ast/#CommentMap )
// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, "src.go", src, parser.ParseComments)
if err != nil {
panic(err)
}
// Create an ast.CommentMap from the ast.File's comments.
// This helps keeping the association between comments
// and AST nodes.
cmap := ast.NewCommentMap(fset, f, f.Comments)
References :
Advertisement
Something interesting
Tutorials
+5.4k Golang : fmt.Println prints out empty data from struct
+9.1k Golang : Simple histogram example
+13.4k Golang : error parsing regexp: invalid or unsupported Perl syntax
+16.1k Golang : Generate universally unique identifier(UUID) example
+7.6k Golang : Convert(cast) io.Reader type to string
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+7.5k Golang : Handling Yes No Quit query input
+33.8k Golang : convert(cast) bytes to string
+8.8k Golang : Random integer with rand.Seed() within a given range
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+36.3k Golang : Convert(cast) int64 to string