Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
11df49c4
Commit
11df49c4
authored
Sep 16, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
publish doc.CommentText
R=gri DELTA=29 (10 added, 12 deleted, 7 changed) OCL=34709 CL=34712
parent
127368d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
19 deletions
+17
-19
comment.go
src/pkg/go/doc/comment.go
+12
-2
doc.go
src/pkg/go/doc/doc.go
+5
-17
No files found.
src/pkg/go/doc/comment.go
View file @
11df49c4
...
@@ -8,6 +8,7 @@ package doc
...
@@ -8,6 +8,7 @@ package doc
import
(
import
(
"fmt"
;
"fmt"
;
"go/ast"
;
"io"
;
"io"
;
"once"
;
"once"
;
"regexp"
;
"regexp"
;
...
@@ -39,8 +40,17 @@ func setupRegexps() {
...
@@ -39,8 +40,17 @@ func setupRegexps() {
comment_junk
=
makeRex
(
"^[
\t
]*(/
\\
*|
\\
*/)[
\t
]*$"
);
comment_junk
=
makeRex
(
"^[
\t
]*(/
\\
*|
\\
*/)[
\t
]*$"
);
}
}
// Aggregate comment text, without comment markers.
// CommentText returns the text of comment,
func
commentText
(
comments
[]
string
)
string
{
// 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
);
once
.
Do
(
setupRegexps
);
lines
:=
make
([]
string
,
0
,
20
);
lines
:=
make
([]
string
,
0
,
20
);
for
_
,
c
:=
range
comments
{
for
_
,
c
:=
range
comments
{
...
...
src/pkg/go/doc/doc.go
View file @
11df49c4
...
@@ -304,18 +304,6 @@ func NewPackageDoc(pkg *ast.Package, importpath string) *PackageDoc {
...
@@ -304,18 +304,6 @@ func NewPackageDoc(pkg *ast.Package, importpath string) *PackageDoc {
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Conversion to external representation
// 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
// ValueDoc is the documentation for a group of declared
// values, either vars or consts.
// values, either vars or consts.
//
//
...
@@ -363,7 +351,7 @@ func makeValueDocs(v *vector.Vector, tok token.Token) []*ValueDoc {
...
@@ -363,7 +351,7 @@ func makeValueDocs(v *vector.Vector, tok token.Token) []*ValueDoc {
for
i
:=
range
d
{
for
i
:=
range
d
{
decl
:=
v
.
At
(
i
)
.
(
*
ast
.
GenDecl
);
decl
:=
v
.
At
(
i
)
.
(
*
ast
.
GenDecl
);
if
decl
.
Tok
==
tok
{
if
decl
.
Tok
==
tok
{
d
[
n
]
=
&
ValueDoc
{
astCommen
t
(
decl
.
Doc
),
decl
,
i
};
d
[
n
]
=
&
ValueDoc
{
CommentTex
t
(
decl
.
Doc
),
decl
,
i
};
n
++
;
n
++
;
decl
.
Doc
=
nil
;
// doc consumed - removed from AST
decl
.
Doc
=
nil
;
// doc consumed - removed from AST
}
}
...
@@ -395,7 +383,7 @@ func makeFuncDocs(m map[string] *ast.FuncDecl) []*FuncDoc {
...
@@ -395,7 +383,7 @@ func makeFuncDocs(m map[string] *ast.FuncDecl) []*FuncDoc {
i
:=
0
;
i
:=
0
;
for
_
,
f
:=
range
m
{
for
_
,
f
:=
range
m
{
doc
:=
new
(
FuncDoc
);
doc
:=
new
(
FuncDoc
);
doc
.
Doc
=
astCommen
t
(
f
.
Doc
);
doc
.
Doc
=
CommentTex
t
(
f
.
Doc
);
f
.
Doc
=
nil
;
// doc consumed - remove from ast.FuncDecl node
f
.
Doc
=
nil
;
// doc consumed - remove from ast.FuncDecl node
if
f
.
Recv
!=
nil
{
if
f
.
Recv
!=
nil
{
doc
.
Recv
=
f
.
Recv
.
Type
;
doc
.
Recv
=
f
.
Recv
.
Type
;
...
@@ -459,7 +447,7 @@ func (doc *docReader) makeTypeDocs(m map[string] *typeDoc) []*TypeDoc {
...
@@ -459,7 +447,7 @@ func (doc *docReader) makeTypeDocs(m map[string] *typeDoc) []*TypeDoc {
doc
=
decl
.
Doc
;
doc
=
decl
.
Doc
;
}
}
decl
.
Doc
=
nil
;
// doc consumed - remove from ast.Decl node
decl
.
Doc
=
nil
;
// doc consumed - remove from ast.Decl node
t
.
Doc
=
astCommen
t
(
doc
);
t
.
Doc
=
CommentTex
t
(
doc
);
t
.
Type
=
typespec
;
t
.
Type
=
typespec
;
t
.
Consts
=
makeValueDocs
(
old
.
values
,
token
.
CONST
);
t
.
Consts
=
makeValueDocs
(
old
.
values
,
token
.
CONST
);
t
.
Vars
=
makeValueDocs
(
old
.
values
,
token
.
VAR
);
t
.
Vars
=
makeValueDocs
(
old
.
values
,
token
.
VAR
);
...
@@ -499,7 +487,7 @@ func (doc *docReader) makeTypeDocs(m map[string] *typeDoc) []*TypeDoc {
...
@@ -499,7 +487,7 @@ func (doc *docReader) makeTypeDocs(m map[string] *typeDoc) []*TypeDoc {
func
makeBugDocs
(
v
*
vector
.
Vector
)
[]
string
{
func
makeBugDocs
(
v
*
vector
.
Vector
)
[]
string
{
d
:=
make
([]
string
,
v
.
Len
());
d
:=
make
([]
string
,
v
.
Len
());
for
i
:=
0
;
i
<
v
.
Len
();
i
++
{
for
i
:=
0
;
i
<
v
.
Len
();
i
++
{
d
[
i
]
=
astCommen
t
(
v
.
At
(
i
)
.
(
*
ast
.
CommentGroup
));
d
[
i
]
=
CommentTex
t
(
v
.
At
(
i
)
.
(
*
ast
.
CommentGroup
));
}
}
return
d
;
return
d
;
}
}
...
@@ -530,7 +518,7 @@ func (doc *docReader) newDoc(pkgname, importpath, filepath string, filenames []s
...
@@ -530,7 +518,7 @@ func (doc *docReader) newDoc(pkgname, importpath, filepath string, filenames []s
p
.
FilePath
=
filepath
;
p
.
FilePath
=
filepath
;
sort
.
SortStrings
(
filenames
);
sort
.
SortStrings
(
filenames
);
p
.
Filenames
=
filenames
;
p
.
Filenames
=
filenames
;
p
.
Doc
=
astCommen
t
(
doc
.
doc
);
p
.
Doc
=
CommentTex
t
(
doc
.
doc
);
// makeTypeDocs may extend the list of doc.values and
// makeTypeDocs may extend the list of doc.values and
// doc.funcs and thus must be called before any other
// doc.funcs and thus must be called before any other
// function consuming those lists
// function consuming those lists
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment