diff --git a/src/pkg/go/doc/comment.go b/src/pkg/go/doc/comment.go index 44a047588d..d7bb384ed0 100644 --- a/src/pkg/go/doc/comment.go +++ b/src/pkg/go/doc/comment.go @@ -303,9 +303,8 @@ func heading(line []byte) []byte { return nil } - // allow ' for possessive 's only - b := line - for { + // allow "'" for possessive "'s" only + for b := line; ; { i := bytes.IndexRune(b, '\'') if i < 0 { break @@ -339,7 +338,7 @@ func heading(line []byte) []byte { func ToHTML(w io.Writer, s []byte, words map[string]string) { inpara := false lastWasBlank := false - lastNonblankWasHeading := false + lastWasHeading := false close := func() { if inpara { @@ -389,10 +388,11 @@ func ToHTML(w io.Writer, s []byte, words map[string]string) { emphasize(w, line, nil, false) // no nice text formatting } w.Write(html_endpre) + lastWasHeading = false continue } - if lastWasBlank && !lastNonblankWasHeading && i+2 < len(lines) && + if lastWasBlank && !lastWasHeading && i+2 < len(lines) && isBlank(lines[i+1]) && !isBlank(lines[i+2]) && indentLen(lines[i+2]) == 0 { // current line is non-blank, sourounded by blank lines // and the next non-blank line is not indented: this @@ -403,7 +403,7 @@ func ToHTML(w io.Writer, s []byte, words map[string]string) { template.HTMLEscape(w, head) w.Write(html_endh) i += 2 - lastNonblankWasHeading = true + lastWasHeading = true continue } } @@ -411,7 +411,7 @@ func ToHTML(w io.Writer, s []byte, words map[string]string) { // open paragraph open() lastWasBlank = false - lastNonblankWasHeading = false + lastWasHeading = false emphasize(w, lines[i], words, true) // nice text formatting i++ } diff --git a/src/pkg/go/doc/comment_test.go b/src/pkg/go/doc/comment_test.go index 9e77ae2cde..870660ad62 100644 --- a/src/pkg/go/doc/comment_test.go +++ b/src/pkg/go/doc/comment_test.go @@ -19,7 +19,7 @@ var headingTests = []struct { {"", false}, {"section", false}, {"A typical usage:", true}, - {"δ is Greek", false}, // TODO: consider allowing this + {"δ is Greek", false}, {"Foo §", false}, {"Fermat's Last Sentence", true}, {"Fermat's", true}, diff --git a/src/pkg/go/doc/headscan.go b/src/pkg/go/doc/headscan.go index 95953b3bdc..83f24627c9 100644 --- a/src/pkg/go/doc/headscan.go +++ b/src/pkg/go/doc/headscan.go @@ -1,53 +1,111 @@ +// 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. + +/* + The headscan command extracts comment headings from package files; + it is used to detect false positives which may require an adjustment + to the comment formatting heuristics in comment.go. + + Usage: headscan [-root root_directory] + + By default, the $GOROOT/src directory is scanned. +*/ package main import ( "bytes" "flag" + "fmt" "go/doc" "go/parser" "go/token" - "log" "os" "path/filepath" + "runtime" "strings" ) +var ( + root = flag.String("root", filepath.Join(runtime.GOROOT(), "src"), "root of filesystem tree to scan") + verbose = flag.Bool("v", false, "verbose mode") +) + +const ( + html_h = "