]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: add support for arbitrary notes
authorCosmos Nicolaou <cnicolaou@google.com>
Fri, 15 Feb 2013 04:20:32 +0000 (20:20 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 15 Feb 2013 04:20:32 +0000 (20:20 -0800)
Add support for arbitrary notes of the form // MARKER(userid): comment
in the same vein as BUG(userid): A marker must be two or more upper case [A-Z] letters.

R=gri, rsc, bradfitz, jscrockett01
CC=golang-dev
https://golang.org/cl/7322061

src/pkg/go/doc/doc.go
src/pkg/go/doc/reader.go
src/pkg/go/doc/testdata/a.0.golden
src/pkg/go/doc/testdata/a.1.golden
src/pkg/go/doc/testdata/a.2.golden
src/pkg/go/doc/testdata/a0.go
src/pkg/go/doc/testdata/a1.go
src/pkg/go/doc/testdata/template.txt

index 9c606315d406f5a498338258cd6491d7c0c4350f..6fc98d49510be5b83994615e912b2611ff684d84 100644 (file)
@@ -18,6 +18,12 @@ type Package struct {
        Imports    []string
        Filenames  []string
        Bugs       []string
+       // Notes such as TODO(userid): or SECURITY(userid):
+       // along the lines of BUG(userid). Any marker with 2 or more upper
+       // case [A-Z] letters is recognised.
+       // BUG is explicitly not included in these notes but will
+       // be in a subsequent change when the Bugs field above is removed.
+       Notes map[string][]string
 
        // declarations
        Consts []*Value
@@ -89,6 +95,7 @@ func New(pkg *ast.Package, importPath string, mode Mode) *Package {
                Imports:    sortedKeys(r.imports),
                Filenames:  r.filenames,
                Bugs:       r.bugs,
+               Notes:      r.notes,
                Consts:     sortedValues(r.values, token.CONST),
                Types:      sortedTypes(r.types, mode&AllMethods != 0),
                Vars:       sortedValues(r.values, token.VAR),
index fafd8f98eaf1225ddae4bdadede8207e84c0a2a8..69c11411672774adcb676362ed03554c7131d81a 100644 (file)
@@ -149,6 +149,7 @@ type reader struct {
        doc       string // package documentation, if any
        filenames []string
        bugs      []string
+       notes     map[string][]string
 
        // declarations
        imports map[string]int
@@ -400,10 +401,24 @@ func (r *reader) readFunc(fun *ast.FuncDecl) {
 }
 
 var (
-       bug_markers = regexp.MustCompile("^/[/*][ \t]*BUG\\(.*\\):[ \t]*") // BUG(uid):
-       bug_content = regexp.MustCompile("[^ \n\r\t]+")                    // at least one non-whitespace char
+       noteMarker  = regexp.MustCompile(`^/[/*][ \t]*([A-Z][A-Z]+)\(.+\):[ \t]*(.*)`) // MARKER(uid)
+       noteContent = regexp.MustCompile(`[^ \n\r\t]+`)                                // at least one non-whitespace char
 )
 
+func readNote(c *ast.CommentGroup) (marker, annotation string) {
+       text := c.List[0].Text
+       if m := noteMarker.FindStringSubmatch(text); m != nil {
+               if btxt := m[2]; noteContent.MatchString(btxt) {
+                       // non-empty MARKER comment; collect comment without the MARKER prefix
+                       list := append([]*ast.Comment(nil), c.List...) // make a copy
+                       list[0].Text = m[2]
+
+                       return m[1], (&ast.CommentGroup{List: list}).Text()
+               }
+       }
+       return "", ""
+}
+
 // readFile adds the AST for a source file to the reader.
 //
 func (r *reader) readFile(src *ast.File) {
@@ -469,16 +484,15 @@ func (r *reader) readFile(src *ast.File) {
                }
        }
 
-       // collect BUG(...) comments
+       // collect MARKER(...): annotations
        for _, c := range src.Comments {
-               text := c.List[0].Text
-               if m := bug_markers.FindStringIndex(text); m != nil {
-                       // found a BUG comment; maybe empty
-                       if btxt := text[m[1]:]; bug_content.MatchString(btxt) {
-                               // non-empty BUG comment; collect comment without BUG prefix
-                               list := append([]*ast.Comment(nil), c.List...) // make a copy
-                               list[0].Text = text[m[1]:]
-                               r.bugs = append(r.bugs, (&ast.CommentGroup{List: list}).Text())
+               if marker, text := readNote(c); marker != "" {
+                       // Remove r.bugs in a separate CL along with
+                       // any necessary changes to client code.
+                       if marker == "BUG" {
+                               r.bugs = append(r.bugs, text)
+                       } else {
+                               r.notes[marker] = append(r.notes[marker], text)
                        }
                }
        }
@@ -492,6 +506,7 @@ func (r *reader) readPackage(pkg *ast.Package, mode Mode) {
        r.mode = mode
        r.types = make(map[string]*namedType)
        r.funcs = make(methodSet)
+       r.notes = make(map[string][]string)
 
        // sort package files before reading them so that the
        // result does not depend on map iteration order
index 24db02d348f5cc81cdabfb978d126d185d74a710..04fe885930980c7068b926c7311d994e80848de2 100644 (file)
@@ -11,3 +11,10 @@ FILENAMES
 BUGS
        // bug0 
        // bug1 
+
+SECBUG
+       // sec hole 0 need to fix asap 
+
+TODO
+       // todo0 
+       // todo1 
index 24db02d348f5cc81cdabfb978d126d185d74a710..04fe885930980c7068b926c7311d994e80848de2 100644 (file)
@@ -11,3 +11,10 @@ FILENAMES
 BUGS
        // bug0 
        // bug1 
+
+SECBUG
+       // sec hole 0 need to fix asap 
+
+TODO
+       // todo0 
+       // todo1 
index 24db02d348f5cc81cdabfb978d126d185d74a710..04fe885930980c7068b926c7311d994e80848de2 100644 (file)
@@ -11,3 +11,10 @@ FILENAMES
 BUGS
        // bug0 
        // bug1 
+
+SECBUG
+       // sec hole 0 need to fix asap 
+
+TODO
+       // todo0 
+       // todo1 
index dc552989ec26ce6d11f76d1cd47ce7e542bed1c0..d2bd146df18d6ef46e4e82a602262fc135ef54d8 100644 (file)
@@ -6,3 +6,8 @@
 package a
 
 //BUG(uid): bug0
+
+//TODO(uid): todo0
+
+// SECBUG(uid): sec hole 0
+// need to fix asap
index 098776c1b0e43a590614ef2624314227aa841ec4..9fad1e09bc44bbbe51f67153b875c47aaa90f51c 100644 (file)
@@ -6,3 +6,7 @@
 package a
 
 //BUG(uid): bug1
+
+//TODO(uid): todo1
+
+//TODO(): ignored
index 32e331cdd101e0724e4ad044cf2e271e301b0a4d..489b5d4ea7e0a358b102fa1da6edfc21636a9487 100644 (file)
@@ -62,4 +62,7 @@ TYPES
 */}}{{with .Bugs}}
 BUGS
 {{range .}}    {{synopsis .}}
-{{end}}{{end}}
\ No newline at end of file
+{{end}}{{end}}{{with .Notes}}{{range $marker, $content := .}}
+{{$marker}}
+{{range $content}}     {{synopsis .}}
+{{end}}{{end}}{{end}}
\ No newline at end of file