Skip to content

Commit 2b7ea84

Browse files
committed
dev: add script for printing AST of file
1 parent 8d8ba24 commit 2b7ea84

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/print_ast/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"go/ast"
6+
"go/parser"
7+
"go/token"
8+
"log"
9+
)
10+
11+
func main() {
12+
var filename string
13+
flag.StringVar(&filename, "f", "", "input file")
14+
flag.Parse()
15+
16+
fset := token.NewFileSet()
17+
f, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
18+
if err != nil {
19+
log.Fatalf("Failed to parse file %s: %s", filename, err)
20+
}
21+
ast.Print(fset, f)
22+
}

0 commit comments

Comments
 (0)