github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/internal/cmd/ast-to-pattern/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "go/ast" 6 "go/token" 7 "io" 8 "os" 9 10 "github.com/amarpal/go-tools/pattern" 11 ) 12 13 func main() { 14 src, err := io.ReadAll(os.Stdin) 15 if err != nil { 16 fmt.Fprintln(os.Stderr, err) 17 os.Exit(1) 18 } 19 fset := token.NewFileSet() 20 node, err := parseDetectingNode(fset, string(src)) 21 if err != nil { 22 fmt.Fprintln(os.Stderr, err) 23 os.Exit(1) 24 } 25 26 if _, ok := node.(*ast.File); ok { 27 fmt.Fprintln(os.Stderr, "cannot convert entire file to Node") 28 os.Exit(1) 29 } 30 fmt.Println(pattern.ASTToNode(node)) 31 }