15 "honnef.co/go/tools/pattern"
18 func match(fset *token.FileSet, pat pattern.Pattern, f *ast.File) {
19 ast.Inspect(f, func(node ast.Node) bool {
24 for _, rel := range pat.Relevant {
25 if rel == reflect.TypeOf(node) {
26 m := &pattern.Matcher{}
27 if m.Match(pat.Root, node) {
28 fmt.Printf("%s: ", fset.Position(node.Pos()))
29 format.Node(os.Stdout, fset, node)
33 // OPT(dh): we could further speed this up by not
34 // chasing down impossible subtrees. For example,
35 // we'll never find an ImportSpec beneath a FuncLit.
46 // XXX don't use MustParse, handle error
47 p := &pattern.Parser{}
48 q, err := p.Parse(flag.Args()[0])
54 // XXX should we create a new fileset per file? what if we're
55 // checking millions of files, will this use up a lot of memory?
56 fset := token.NewFileSet()
57 filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
62 if !strings.HasSuffix(path, ".go") {
65 // XXX don't try to parse irregular files or directories
66 f, err := parser.ParseFile(fset, path, nil, parser.ParseComments)