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
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+7.3k Golang : alternative to os.Exit() function
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+25.3k Golang : Convert uint value to string type
+4.7k Adding Skype actions such as call and chat into web page examples
+31.5k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+11.5k CodeIgniter : Import Linkedin data
+5.5k Golang : If else example and common mistake
+5.3k Golang : How to deal with configuration data?
+5.7k Golang : Struct field tags and what is their purpose?