1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// This file contains support functions for parsing .go files.
6
// Similar functionality is found in package go/parser but the
7
// functions here operate using godoc's file system fs instead
8
// of calling the OS's file operations directly.
20
func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.Package, first os.Error) {
21
pkgs = make(map[string]*ast.Package)
22
for _, filename := range filenames {
23
src, err := fs.ReadFile(filename)
31
file, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
39
name := file.Name.Name
40
pkg, found := pkgs[name]
42
// TODO(gri) Use NewPackage here; reconsider ParseFiles API.
43
pkg = &ast.Package{name, nil, nil, make(map[string]*ast.File)}
46
pkg.Files[filename] = file
52
func parseDir(fset *token.FileSet, path string, filter func(FileInfo) bool) (map[string]*ast.Package, os.Error) {
53
list, err := fs.ReadDir(path)
58
filenames := make([]string, len(list))
60
for _, d := range list {
61
if filter == nil || filter(d) {
62
filenames[i] = filepath.Join(path, d.Name())
66
filenames = filenames[0:i]
68
return parseFiles(fset, filenames)