Overview

Package doc extracts source code documentation from a Go AST.

Index

comment.go example.go filter.go synopsis.go

Variables

func

  1. func Examples(files ...*.File) []*

Examples returns the examples found in the files, sorted by Name field. The
Order fields record the order in which the examples were encountered.

Playable Examples must be in a package whose name ends in “_test”. An Example is
“playable” (the Play field is non-nil) in either of these circumstances:

  1. - The example function is self-contained: the function references only
  2. "int") and the test file does not include a dot import.
  3. example function, zero test or benchmark functions, and at least one
  4. than the example function.

  1. func IsPredeclared(s string)

IsPredeclared reports whether s is a predeclared identifier.

func Synopsis

  1. func Synopsis(s string)

Synopsis returns a cleaned version of the first sentence in s. That sentence
ends after the first period followed by space and not preceded by exactly one
uppercase letter. The result string has no \n, \r, or \t characters and uses
only single spaces between words. If s starts with any of the IllegalPrefixes,
the result is the empty string.

func ToHTML

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

ToHTML converts comment text to formatted HTML. The comment was prepared by
DocReader, so it is known not to have leading, trailing blank lines nor to have
trailing spaces at the end of lines. The comment markers have already been
removed.

Each span of unindented non-blank lines is converted into a single paragraph.
There is one exception to the rule: a span that consists of a single line, is
followed by another paragraph span, begins with a capital letter, and contains
no punctuation is formatted as a heading.

  1. block, with the common indent
    prefix removed.

  2. URLs in the comment text are converted into links; if the URL also appears in
    the words map, the link is taken from the map (if the corresponding map value is
    the empty string, the URL is not converted into a link).

  3. Go identifiers that appear in the words map are italicized; if the corresponding
    map value is not the empty string, it is considered a URL and the word is
    converted into a link.

  4. func

  5. func ToText(w .Writer, text , indent, preIndent string, width )
  6.  
  7. ToText prepares comment text for presentation in textual output. It wraps
    paragraphs of text to width or fewer Unicode code points and then prefixes each
    line with the indent. In preformatted sections (such as program text), it
    prefixes each non-blank line with preIndent.

  8. type Example

  9. type Example struct {
  10.     Name        string // name of the item being exemplified
  11.     Doc          // example function doc string
  12.     Code        ast.
  13.     Play        *ast. // a whole program version of the example
  14.     Comments    []*ast.
  15.     Output      string // expected output
  16.     Unordered   
  17.     EmptyOutput bool // expect empty output
  18. }
  19.  
  20. An Example represents an example function found in a source files.

  21. type Filter func() bool
  22.  
  23.  
  24. type

  25. type Func struct {
  26.     Doc  
  27.     Name string
  28.     Decl *.FuncDecl
  29.     // methods
  30.     // (for functions, these fields have the respective zero value)
  31.     Orig   // original receiver "T" or "*T"
  32.     Level int    // embedding level; 0 means not embedded
  33. }
  34.  
  35. Func is the documentation for a func declaration.

  36. type

  37. type Mode 
  38.  
  39. Mode values control the operation of New.

  40. const (
  41.     // extract documentation for all package-level declarations,
  42.     // not just exported ones
  43.     AllDecls Mode = 1 << 
  44.     // show all embedded methods, not just the ones of
  45.     // invisible (unexported) anonymous fields
  46.     AllMethods
  47. )
  48.  
  49.  
  50. type Note

  51. type Note struct {
  52.     Pos, End token. // position range of the comment containing the marker
  53.     UID      string    // uid found with the marker
  54.     Body         // note body text
  55. }
  56.  
  57. A Note represents a marked comment starting with MARKER(uid): note body”. Any
    note with a marker of 2 or more upper case [A-Z] letters and a uid of at least
    one character is recognized. The “:” following the uid is optional. Notes are
    collected in the Package.Notes map indexed by the notes marker.

  58. type Package

  59. type Package struct {
  60.     Doc        string
  61.     ImportPath 
  62.     Imports    []string
  63.     Filenames  []
  64.     Notes      map[string][]*
  65.     // but all new code should use Notes instead.
  66.     Bugs []string
  67.     // declarations
  68.     Consts []*
  69.     Types  []*Type
  70.     Vars   []*
  71.     Funcs  []*Func
  72. }
  73.  
  74. Package is the documentation for an entire package.

  75. func New(pkg *.Package, importPath , mode Mode) *
  76.  
  77. New computes the package documentation for the given package AST. New takes
    ownership of the AST pkg and may edit or overwrite it.

  78. func (p *Package) Filter(f )
  79.  
  80. Filter eliminates documentation for names that dont pass through the filter f.
    TODO(gri): Recognize Type.Method as a name.

  81. type Type struct {
  82.     Doc  string
  83.     Name 
  84.     Decl *ast.
  85.     // associated declarations
  86.     Consts  []*Value // sorted list of constants of (mostly) this type
  87.     Vars    []* // sorted list of variables of (mostly) this type
  88.     Funcs   []*Func  // sorted list of functions returning this type
  89.     Methods []*  // sorted list of methods (including embedded ones) of this type
  90. }
  91.  
  92. Type is the documentation for a type declaration.

  93. type Value

  94. type Value struct {
  95.     Doc   string
  96.     Names [] // var or const names in declaration order
  97.     Decl  *ast.
  98. }
  99.