Teach doc.go about // comments.
This is in preparation for changing all the comments.
Change-Id: Id7ff24331a3b9d108402238c63eeeb462c7cd809
Reviewed-on: https://boringssl-review.googlesource.com/18945
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/util/doc.go b/util/doc.go
index f96a154..2d5a297 100644
--- a/util/doc.go
+++ b/util/doc.go
@@ -74,8 +74,13 @@
cppGuard = "#if defined(__cplusplus)"
commentStart = "/* "
commentEnd = " */"
+ lineComment = "// "
)
+func isComment(line string) bool {
+ return strings.HasPrefix(line, commentStart) || strings.HasPrefix(line, lineComment)
+}
+
func extractComment(lines []string, lineNo int) (comment []string, rest []string, restLineNo int, err error) {
if len(lines) == 0 {
return nil, lines, lineNo, nil
@@ -84,7 +89,10 @@
restLineNo = lineNo
rest = lines
- if !strings.HasPrefix(rest[0], commentStart) {
+ var isBlock bool
+ if strings.HasPrefix(rest[0], commentStart) {
+ isBlock = true
+ } else if !strings.HasPrefix(rest[0], lineComment) {
panic("extractComment called on non-comment")
}
commentParagraph := rest[0][len(commentStart):]
@@ -92,25 +100,34 @@
restLineNo++
for len(rest) > 0 {
- i := strings.Index(commentParagraph, commentEnd)
- if i >= 0 {
- if i != len(commentParagraph)-len(commentEnd) {
- err = fmt.Errorf("garbage after comment end on line %d", restLineNo)
+ if isBlock {
+ i := strings.Index(commentParagraph, commentEnd)
+ if i >= 0 {
+ if i != len(commentParagraph)-len(commentEnd) {
+ err = fmt.Errorf("garbage after comment end on line %d", restLineNo)
+ return
+ }
+ commentParagraph = commentParagraph[:i]
+ if len(commentParagraph) > 0 {
+ comment = append(comment, commentParagraph)
+ }
return
}
- commentParagraph = commentParagraph[:i]
+ }
+
+ line := rest[0]
+ if isBlock {
+ if !strings.HasPrefix(line, " *") {
+ err = fmt.Errorf("comment doesn't start with block prefix on line %d: %s", restLineNo, line)
+ return
+ }
+ } else if !strings.HasPrefix(line, "//") {
if len(commentParagraph) > 0 {
comment = append(comment, commentParagraph)
}
return
}
-
- line := rest[0]
- if !strings.HasPrefix(line, " *") {
- err = fmt.Errorf("comment doesn't start with block prefix on line %d: %s", restLineNo, line)
- return
- }
- if len(line) == 2 || line[2] != '/' {
+ if len(line) == 2 || !isBlock || line[2] != '/' {
line = line[2:]
}
if strings.HasPrefix(line, " ") {
@@ -309,7 +326,7 @@
}
oldLines = lines
- if len(lines) > 0 && strings.HasPrefix(lines[0], commentStart) {
+ if len(lines) > 0 && isComment(lines[0]) {
comment, rest, restLineNo, err := extractComment(lines, lineNo)
if err != nil {
return nil, err
@@ -345,7 +362,7 @@
var section HeaderSection
- if strings.HasPrefix(line, commentStart) {
+ if isComment(line) {
comment, rest, restLineNo, err := extractComment(lines, lineNo)
if err != nil {
return nil, err
@@ -380,7 +397,7 @@
var comment []string
var decl string
- if strings.HasPrefix(line, commentStart) {
+ if isComment(line) {
comment, lines, lineNo, err = extractComment(lines, lineNo)
if err != nil {
return nil, err