mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
The plan for godoc: - Copy godoc source from the core repo to go.tools (this CL). - Break godoc into several packages inside go.tools, leaving a package main that merely sets up a local file system, interprets the command line, and otherwise delegates the heavy-lifting to the new packages. - Remove godoc from the core repo. - Update cmd/go to install this godoc binary in $GOROOT/bin. - Update misc/dist to include godoc when building binary distributions. R=bradfitz CC=golang-dev https://golang.org/cl/11408043
38 lines
926 B
Go
38 lines
926 B
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This file contains support functions for parsing .go files
|
|
// accessed via godoc's file system fs.
|
|
|
|
package main
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
pathpkg "path"
|
|
)
|
|
|
|
func parseFile(fset *token.FileSet, filename string, mode parser.Mode) (*ast.File, error) {
|
|
src, err := ReadFile(fs, filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return parser.ParseFile(fset, filename, src, mode)
|
|
}
|
|
|
|
func parseFiles(fset *token.FileSet, abspath string, localnames []string) (map[string]*ast.File, error) {
|
|
files := make(map[string]*ast.File)
|
|
for _, f := range localnames {
|
|
absname := pathpkg.Join(abspath, f)
|
|
file, err := parseFile(fset, absname, parser.ParseComments)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
files[absname] = file
|
|
}
|
|
|
|
return files, nil
|
|
}
|