Преглед изворни кода

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>
kris/onging/CECPQ3_patch15
David Benjamin пре 7 година
committed by CQ bot account: commit-bot@chromium.org
родитељ
комит
ef37ab5919
1 измењених фајлова са 33 додато и 16 уклоњено
  1. +33
    -16
      util/doc.go

+ 33
- 16
util/doc.go Прегледај датотеку

@@ -74,8 +74,13 @@ const (
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 @@ func extractComment(lines []string, lineNo int) (comment []string, rest []string
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 @@ func extractComment(lines []string, lineNo int) (comment []string, rest []string
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]
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)
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
}
if len(line) == 2 || line[2] != '/' {
if len(line) == 2 || !isBlock || line[2] != '/' {
line = line[2:]
}
if strings.HasPrefix(line, " ") {
@@ -309,7 +326,7 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) {
}

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 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) {

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 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) {

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


Loading…
Откажи
Сачувај