Package doc

import "go/doc"
Overview
Index

Overview ▾

打包文档从Go AST中提取源代码文档.

Variables

var IllegalPrefixes = []string{
    "copyright",
    "all rights",
    "author",
}

func IsPredeclared 1.8

func IsPredeclared(s string) bool

IsPredeclared报告s是否是预声明的标识符.

func Synopsis

func Synopsis(s string) string

概要返回s中第一句话的纯净版本. 该句子在第一个句点之后加空格,而不是紧跟一个大写字母. 结果字符串没有\ n,\ r或\ t字符,并且单词之间仅使用单个空格. 如果s以任何IllegalPrefixes开头,则结果为空字符串.

func ToHTML

func ToHTML(w io.Writer, text string, words map[string]string)

ToHTML将注释文本转换为格式化的HTML. 该注释是由DocReader准备的,因此众所周知,它没有前导,尾随的空白行,也没有尾随空格. 注释标记已被删除.

无缩进的非空白行的每个跨度都转换为单个段落. 该规则有一个例外:一个跨度由一行组成,后接另一个段落跨度,以大写字母开头,除括号外不包含任何标点符号,并且逗号被格式化为标题.

一段缩进的行将转换为<pre>块,并删除公共缩进前缀.

注释文本中的URL转换为链接; 如果URL也出现在单词映射中,则从映射中获取链接(如果对应的映射值为空字符串,则URL不会转换为链接).

出现在单词map中的Go标识符以斜体显示; 如果对应的映射值不是空字符串,则将其视为URL并将该单词转换为链接.

func ToText

func ToText(w io.Writer, text string, indent, preIndent string, width int)

ToText准备注释文本以在文本输出中呈现. 它将文本段落包装为宽度或更小的Unicode代码点,然后在每行前面加上缩进. 在预格式化的部分(例如程序文本)中,它在每个非空白行的前面加上preIndent.

type Example

Example代表在源文件中找到的示例函数.

type Example struct {
    Name        string // name of the item being exemplified
    Doc         string // example function doc string
    Code        ast.Node
    Play        *ast.File // a whole program version of the example; added in Go 1.1
    Comments    []*ast.CommentGroup
    Output      string // expected output
    Unordered   bool // Go 1.7
    EmptyOutput bool // expect empty output; added in Go 1.1
    Order       int  // original source code order; added in Go 1.1
}

func Examples

func Examples(files ...*ast.File) []*Example

示例返回在文件中找到的示例,并按"名称"字段排序. Order字段记录遇到示例的顺序.

可播放示例必须放在名称以" _test"结尾的程序包中. 在以下两种情况下,示例都是"可播放的"("播放"字段为非零):

- The example function is self-contained: the function references only
  identifiers from other packages (or predeclared identifiers, such as
  "int") and the test file does not include a dot import.
- The entire test file is the example: the file contains exactly one
  example function, zero test or benchmark functions, and at least one
  top-level function, type, variable, or constant declaration other
  than the example function.

type Filter

type Filter func(string) bool

type Func

Func是func声明的文档.

type Func struct {
    Doc  string
    Name string
    Decl *ast.FuncDecl

    // methods
    // (for functions, these fields have the respective zero value)
    Recv  string // actual   receiver "T" or "*T"
    Orig  string // original receiver "T" or "*T"
    Level int    // embedding level; 0 means not embedded
}

type Mode

模式值控制"新建"的操作.

type Mode int
const (
    // AllDecls says to extract documentation for all package-level
    // declarations, not just exported ones.
    AllDecls Mode = 1 << iota

    // AllMethods says to show all embedded methods, not just the ones of
    // invisible (unexported) anonymous fields.
    AllMethods

    // PreserveAST says to leave the AST unmodified. Originally, pieces of
    // the AST such as function bodies were nil-ed out to save memory in
    // godoc, but not all programs want that behavior.
    PreserveAST
)

type Note 1.1

注释表示以" MARKER(uid):注释正文"开头的标记注释. 任何带有2个或更多大写[AZ]字母标记和至少一个字符的uid的音符都会被识别. uid后面的":"是可选的. 便笺收集在Package.Notes映射中,由便笺标记索引.

type Note struct {
    Pos, End token.Pos // position range of the comment containing the marker
    UID      string    // uid found with the marker
    Body     string    // note body text
}

type Package

包是整个包的文档.

type Package struct {
    Doc        string
    Name       string
    ImportPath string
    Imports    []string
    Filenames  []string
    Notes      map[string][]*Note // Go 1.1

    // Deprecated: For backward compatibility Bugs is still populated,
    // but all new code should use Notes instead.
    Bugs []string

    // declarations
    Consts []*Value
    Types  []*Type
    Vars   []*Value
    Funcs  []*Func
}

func New

func New(pkg *ast.Package, importPath string, mode Mode) *Package

New计算给定包AST的包文档. New拥有AST pkg的所有权,并且可以对其进行编辑或覆盖.

func (*Package) Filter

func (p *Package) Filter(f Filter)

过滤器消除了没有通过过滤器f的名称的文档. TODO(gri):将" Type.Method"识别为名称.

type Type

Type是类型声明的文档.

type Type struct {
    Doc  string
    Name string
    Decl *ast.GenDecl

    // associated declarations
    Consts  []*Value // sorted list of constants of (mostly) this type
    Vars    []*Value // sorted list of variables of (mostly) this type
    Funcs   []*Func  // sorted list of functions returning this type
    Methods []*Func  // sorted list of methods (including embedded ones) of this type
}

type Value

值是var或const声明的文档(可能是分组的).

type Value struct {
    Doc   string
    Names []string // var or const names in declaration order
    Decl  *ast.GenDecl
    // contains filtered or unexported fields
}

by  ICOPY.SITE