Created
September 16, 2019 15:55
-
-
Save chriskirkland/9faead5cd627ed50818e6af39fc4e7b8 to your computer and use it in GitHub Desktop.
print AST for Go file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"go/ast" | |
"go/parser" | |
"go/token" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
src, err := ioutil.ReadFile(os.Args[1]) | |
if err != nil { | |
panic(err) | |
} | |
// Create the AST by parsing src. | |
fset := token.NewFileSet() // positions are relative to fset | |
f, err := parser.ParseFile(fset, "", string(src), 0) | |
if err != nil { | |
panic(err) | |
} | |
// Print the AST. | |
ast.Print(fset, f) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment