Golang go/ast.File type examples

package go/ast

A File node represents a Go source file.

The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields.

Golang go/ast.File type usage examples

Example 1:

 func NodeDescription(n ast.Node) string {
 switch n := n.(type) {
 case *ast.ArrayType:
 return "array type"
 case *ast.AssignStmt:
 return "assignment"
 case *ast.File:
 return "source file"
  }

Example 2:

 func parseStdin() (*ast.File, error) {
 src, err := ioutil.ReadAll(os.Stdin)
 if err != nil {
 return nil, err
 }
 return parse("<standard input>", src)
 }

Reference :

http://golang.org/pkg/go/ast/#File

Advertisement