dev: add script for printing AST of file
This commit is contained in:
parent
8d8ba245e1
commit
2b7ea844ab
22
scripts/print_ast/main.go
Normal file
22
scripts/print_ast/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var filename string
|
||||
flag.StringVar(&filename, "f", "", "input file")
|
||||
flag.Parse()
|
||||
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse file %s: %s", filename, err)
|
||||
}
|
||||
ast.Print(fset, f)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user