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
+11k How to test Facebook App on localhost ?
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+9.1k Golang : Gonum standard normal random numbers example
+34k Golang : Proper way to set function argument default value
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+11k Golang : Create S3 bucket with official aws-sdk-go package
+19.2k Golang : Delete item from slice based on index/key position
+16k Golang : Get sub string example
+13.9k Golang : convert(cast) string to float value
+6.1k Golang : Missing Subversion command
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example