mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
dev: add script for printing AST of file
This commit is contained in:
parent
8d8ba245e1
commit
2b7ea844ab
1 changed files with 22 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue