github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/godoc/parser.go (about) 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. 4 5 // This file contains support functions for parsing .go files 6 // accessed via godoc's file system fs. 7 8 package main 9 10 import ( 11 "go/ast" 12 "go/parser" 13 "go/token" 14 pathpkg "path" 15 ) 16 17 func parseFile(fset *token.FileSet, filename string, mode parser.Mode) (*ast.File, error) { 18 src, err := ReadFile(fs, filename) 19 if err != nil { 20 return nil, err 21 } 22 return parser.ParseFile(fset, filename, src, mode) 23 } 24 25 func parseFiles(fset *token.FileSet, abspath string, localnames []string) (map[string]*ast.File, error) { 26 files := make(map[string]*ast.File) 27 for _, f := range localnames { 28 absname := pathpkg.Join(abspath, f) 29 file, err := parseFile(fset, absname, parser.ParseComments) 30 if err != nil { 31 return nil, err 32 } 33 files[absname] = file 34 } 35 36 return files, nil 37 }