Golang go/ast.Print() function examples
package go/ast
Print prints x to standard output, skipping nil fields. Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
Golang go/ast.Print() function usage examples
Example 1 :
fset := token.NewFileSet()
astPkgs, err := parser.ParseDir(fset, dir, nil, 0)
if err != nil {
errorfExit("can not parse package %s, %s", dir, err)
}
for _, pkg := range astPkgs {
ast.Print(fset, pkg)
}
Example 2 : ( from http://golang.org/pkg/go/ast/#Print )
package main
import (
"go/ast"
"go/parser"
"go/token"
)
func main() {
// src is the input for which we want to print the AST.
src := `
package main
func main() {
println("Hello, World!")
}
`
// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, "", src, 0)
if err != nil {
panic(err)
}
// Print the AST.
ast.Print(fset, f)
}
References :
Advertisement
Something interesting
Tutorials
+10.2k Golang : How to profile or log time spend on execution?
+9.4k Golang : How to protect your source code from client, hosting company or hacker?
+17.8k Golang : Iterate linked list example
+7.1k Golang : Get Alexa ranking data example
+5.1k Swift : Convert (cast) Float to Int or Int32 value
+19.1k Mac OSX : Homebrew and Golang
+9.3k Golang : Temperatures conversion example
+7.5k Golang : How to stop user from directly running an executable file?
+14.7k Golang : Reset buffer example
+14.1k Javascript : Prompt confirmation before exit
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+12.8k Golang : http.Get example