"pkg/net/url",
"pkg/text/template/parse",
"pkg/text/template",
+ "pkg/go/doc",
"cmd/go",
};
"pkg/fmt",
"pkg/go/ast",
"pkg/go/build",
+ "pkg/go/doc",
"pkg/go/parser",
"pkg/go/scanner",
"pkg/go/token",
"fmt"
"go/ast"
"go/build"
+ "go/doc"
"go/parser"
"go/token"
"os"
*seen = true
}
}
- for _, e := range ast.Examples(f) {
+ for _, e := range doc.Examples(f) {
if e.Output == "" {
// Don't run examples with no output.
continue
var exampleOutputRx = regexp.MustCompile(`(?i)//[[:space:]]*output:`)
-func example_htmlFunc(funcName string, examples []*ast.Example, fset *token.FileSet) string {
+func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.FileSet) string {
var buf bytes.Buffer
for _, eg := range examples {
name := eg.Name
FSet *token.FileSet // corresponding file set
PAst *ast.File // nil if no single AST with package exports
PDoc *doc.Package // nil if no single package documentation
- Examples []*ast.Example // nil if no example code
+ Examples []*doc.Example // nil if no example code
Dirs *DirList // nil if no directory information
DirTime time.Time // directory time stamp
DirFlat bool // if set, show directory in a flat (non-indented) manner
}
// get examples from *_test.go files
- var examples []*ast.Example
+ var examples []*doc.Example
filter = func(d os.FileInfo) bool {
return isGoFile(d) && strings.HasSuffix(d.Name(), "_test.go")
}
for _, f := range testpkg.Files {
files = append(files, f)
}
- examples = append(examples, ast.Examples(files...)...)
+ examples = append(examples, doc.Examples(files...)...)
}
}
// Extract example functions from file ASTs.
-package ast
+package doc
import (
+ "go/ast"
"go/token"
"regexp"
"sort"
type Example struct {
Name string // name of the item being exemplified
Doc string // example function doc string
- Code Node
- Comments []*CommentGroup
+ Code ast.Node
+ Comments []*ast.CommentGroup
Output string // expected output
}
-func Examples(files ...*File) []*Example {
+func Examples(files ...*ast.File) []*Example {
var list []*Example
for _, file := range files {
hasTests := false // file contains tests or benchmarks
numDecl := 0 // number of non-import declarations in the file
var flist []*Example
for _, decl := range file.Decls {
- if g, ok := decl.(*GenDecl); ok && g.Tok != token.IMPORT {
+ if g, ok := decl.(*ast.GenDecl); ok && g.Tok != token.IMPORT {
numDecl++
continue
}
- f, ok := decl.(*FuncDecl)
+ f, ok := decl.(*ast.FuncDecl)
if !ok {
continue
}
var outputPrefix = regexp.MustCompile(`(?i)^[[:space:]]*output:`)
-func exampleOutput(fun *FuncDecl, comments []*CommentGroup) string {
+func exampleOutput(fun *ast.FuncDecl, comments []*ast.CommentGroup) string {
// find the last comment in the function
- var last *CommentGroup
+ var last *ast.CommentGroup
for _, cg := range comments {
if cg.Pos() < fun.Pos() {
continue