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
+8.3k Swift : Convert (cast) Character to Integer?
+10.1k Golang : Compare files modify date example
+14.2k Golang : Fix image: unknown format error
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+9.6k Golang : How to generate Code 39 barcode?
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+17.7k Golang : Read data from config file and assign to variables
+37.5k Golang : Converting a negative number to positive number
+26.8k Golang : Convert file content into array of bytes
+8.4k Your page has meta tags in the body instead of the head
+9.6k Golang : Validate IPv6 example
+8.8k Android Studio : Image button and button example