import (
"fmt";
+ "go/ast";
"io";
"once";
"regexp";
comment_junk = makeRex("^[ \t]*(/\\*|\\*/)[ \t]*$");
}
-// Aggregate comment text, without comment markers.
-func commentText(comments []string) string {
+// CommentText returns the text of comment,
+// with the comment markers - //, /*, and */ - removed.
+func CommentText(comment *ast.CommentGroup) string {
+ if comment == nil {
+ return "";
+ }
+ comments := make([]string, len(comment.List));
+ for i, c := range comment.List {
+ comments[i] = string(c.Text);
+ }
+
once.Do(setupRegexps);
lines := make([]string, 0, 20);
for _, c := range comments {
// ----------------------------------------------------------------------------
// Conversion to external representation
-func astComment(comment *ast.CommentGroup) string {
- if comment != nil {
- text := make([]string, len(comment.List));
- for i, c := range comment.List {
- text[i] = string(c.Text);
- }
- return commentText(text);
- }
- return "";
-}
-
-
// ValueDoc is the documentation for a group of declared
// values, either vars or consts.
//
for i := range d {
decl := v.At(i).(*ast.GenDecl);
if decl.Tok == tok {
- d[n] = &ValueDoc{astComment(decl.Doc), decl, i};
+ d[n] = &ValueDoc{CommentText(decl.Doc), decl, i};
n++;
decl.Doc = nil; // doc consumed - removed from AST
}
i := 0;
for _, f := range m {
doc := new(FuncDoc);
- doc.Doc = astComment(f.Doc);
+ doc.Doc = CommentText(f.Doc);
f.Doc = nil; // doc consumed - remove from ast.FuncDecl node
if f.Recv != nil {
doc.Recv = f.Recv.Type;
doc = decl.Doc;
}
decl.Doc = nil; // doc consumed - remove from ast.Decl node
- t.Doc = astComment(doc);
+ t.Doc = CommentText(doc);
t.Type = typespec;
t.Consts = makeValueDocs(old.values, token.CONST);
t.Vars = makeValueDocs(old.values, token.VAR);
func makeBugDocs(v *vector.Vector) []string {
d := make([]string, v.Len());
for i := 0; i < v.Len(); i++ {
- d[i] = astComment(v.At(i).(*ast.CommentGroup));
+ d[i] = CommentText(v.At(i).(*ast.CommentGroup));
}
return d;
}
p.FilePath = filepath;
sort.SortStrings(filenames);
p.Filenames = filenames;
- p.Doc = astComment(doc.doc);
+ p.Doc = CommentText(doc.doc);
// makeTypeDocs may extend the list of doc.values and
// doc.funcs and thus must be called before any other
// function consuming those lists