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
789b31a4
Commit
789b31a4
authored
Nov 04, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better placement of /*-style comments interspersed with code on one line
R=rsc
http://go/go-review/1017030
parent
5d436b9d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
printer.go
src/pkg/go/printer/printer.go
+22
-9
comments.go
src/pkg/go/printer/testdata/comments.go
+5
-0
comments.golden
src/pkg/go/printer/testdata/comments.golden
+5
-0
declarations.golden
src/pkg/go/printer/testdata/declarations.golden
+1
-1
No files found.
src/pkg/go/printer/printer.go
View file @
789b31a4
...
...
@@ -256,11 +256,10 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, isFirst, isKeywor
return
;
}
n
:=
pos
.
Line
-
p
.
last
.
Line
;
if
n
==
0
{
if
pos
.
Line
==
p
.
last
.
Line
{
// comment on the same line as last item:
// separate with at least one
tab
has
Tab
:=
false
;
// separate with at least one
separator
has
Sep
:=
false
;
if
isFirst
{
j
:=
0
;
for
i
,
ch
:=
range
p
.
buffer
{
...
...
@@ -272,7 +271,7 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, isFirst, isKeywor
case
vtab
:
// respect existing tabs - important
// for proper formatting of commented structs
has
Tab
=
true
;
has
Sep
=
true
;
continue
;
case
indent
:
// apply pending indentation
...
...
@@ -283,9 +282,16 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, isFirst, isKeywor
}
p
.
writeWhitespace
(
j
);
}
// make sure there is at least one tab
if
!
hasTab
{
p
.
write
(
htab
);
// make sure there is at least one separator
if
!
hasSep
{
if
pos
.
Line
==
next
.
Line
{
// next item is on the same line as the comment
// (which must be a /*-style comment): separate
// with a blank instead of a tab
p
.
write
([]
byte
{
' '
});
}
else
{
p
.
write
(
htab
);
}
}
}
else
{
...
...
@@ -321,7 +327,7 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, isFirst, isKeywor
}
p
.
writeWhitespace
(
j
);
}
p
.
writeNewlines
(
n
);
p
.
writeNewlines
(
pos
.
Line
-
p
.
last
.
Line
);
}
}
...
...
@@ -560,14 +566,21 @@ func (p *printer) writeCommentSuffix(needsLinebreak bool) {
func
(
p
*
printer
)
intersperseComments
(
next
token
.
Position
,
isKeyword
bool
)
{
isFirst
:=
true
;
needsLinebreak
:=
false
;
var
last
*
ast
.
Comment
;
for
;
p
.
commentBefore
(
next
);
p
.
comment
=
p
.
comment
.
Next
{
for
_
,
c
:=
range
p
.
comment
.
List
{
p
.
writeCommentPrefix
(
c
.
Pos
(),
next
,
isFirst
,
isKeyword
);
isFirst
=
false
;
p
.
writeComment
(
c
);
needsLinebreak
=
c
.
Text
[
1
]
==
'/'
;
last
=
c
;
}
}
if
last
!=
nil
&&
!
needsLinebreak
&&
last
.
Pos
()
.
Line
==
next
.
Line
{
// the last comment is a /*-style comment and the next item
// follows on the same line: separate with an extra blank
p
.
write
([]
byte
{
' '
});
}
p
.
writeCommentSuffix
(
needsLinebreak
);
}
...
...
src/pkg/go/printer/testdata/comments.go
View file @
789b31a4
...
...
@@ -215,6 +215,11 @@ func _() {
}
// Some interesting interspersed comments
func
_
(
/* this */
x
/* is *//* an */
int
)
{
}
// Line comments with tabs
func
_
()
{
var
finput
*
bufio
.
Reader
;
// input file
...
...
src/pkg/go/printer/testdata/comments.golden
View file @
789b31a4
...
...
@@ -215,6 +215,11 @@ func _() {
}
// Some interesting interspersed comments
func _( /* this */ x /* is */ /* an */ int) {
}
// Line comments with tabs
func _() {
var finput *bufio.Reader; // input file
...
...
src/pkg/go/printer/testdata/declarations.golden
View file @
789b31a4
...
...
@@ -294,7 +294,7 @@ func _() {
// formatting of structs
type _ struct{}
type _ struct {
/* this comment should be visible */
}
type _ struct {
/* this comment should be visible */
}
type _ struct {
// this comment should be visible and properly indented
...
...
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