github.com/linux4life798/complete@v1.1.2-0.20180410072631-7426158f3bcb/gocomplete/parse.go (about) 1 package main 2 3 import ( 4 "go/ast" 5 "go/parser" 6 "go/token" 7 "regexp" 8 9 "github.com/posener/complete" 10 ) 11 12 func functionsInFile(path string, regexp *regexp.Regexp) (tests []string) { 13 fset := token.NewFileSet() 14 f, err := parser.ParseFile(fset, path, nil, 0) 15 if err != nil { 16 complete.Log("Failed parsing %s: %s", path, err) 17 return nil 18 } 19 for _, d := range f.Decls { 20 if f, ok := d.(*ast.FuncDecl); ok { 21 name := f.Name.String() 22 if regexp == nil || regexp.MatchString(name) { 23 tests = append(tests, name) 24 } 25 } 26 } 27 return 28 }