Skip to content

Commit a19c0ce

Browse files
agnivadegriesemer
authored andcommitted
Revert "go/parser: include more comments in a struct or interface"
This reverts commit https://golang.org/cl/161177/. Reason for revert: this led to non-contiguous comments spaced by an empty line to be grouped into a single CommentGroup Fixes #32944 Updates #10858 Change-Id: I5e16663b308c3b560496da8e66c33befdf9ed9dd Reviewed-on: https://go-review.googlesource.com/c/go/+/185040 Reviewed-by: Robert Griesemer <[email protected]>
1 parent c893ea8 commit a19c0ce

File tree

5 files changed

+1
-353
lines changed

5 files changed

+1
-353
lines changed

src/go/doc/testdata/issue10858.0.golden

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/go/doc/testdata/issue10858.1.golden

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/go/doc/testdata/issue10858.2.golden

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/go/doc/testdata/issue10858.go

Lines changed: 0 additions & 102 deletions
This file was deleted.

src/go/parser/parser.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ type parser struct {
6363
topScope *ast.Scope // top-most scope; may be pkgScope
6464
unresolved []*ast.Ident // unresolved identifiers
6565
imports []*ast.ImportSpec // list of imports
66-
inStruct bool // if set, parser is parsing a struct or interface (for comment collection)
6766

6867
// Label scopes
6968
// (maintained by open/close LabelScope)
@@ -338,15 +337,7 @@ func (p *parser) next() {
338337
// consume successor comments, if any
339338
endline = -1
340339
for p.tok == token.COMMENT {
341-
n := 1
342-
// When inside a struct (or interface), we don't want to lose comments
343-
// separated from individual field (or method) documentation by empty
344-
// lines. Allow for some white space in this case and collect those
345-
// comments as a group. See issue #10858 for details.
346-
if p.inStruct {
347-
n = 2
348-
}
349-
comment, endline = p.consumeCommentGroup(n)
340+
comment, endline = p.consumeCommentGroup(1)
350341
}
351342

352343
if endline+1 == p.file.Line(p.pos) {
@@ -757,7 +748,6 @@ func (p *parser) parseStructType() *ast.StructType {
757748
}
758749

759750
pos := p.expect(token.STRUCT)
760-
p.inStruct = true
761751
lbrace := p.expect(token.LBRACE)
762752
scope := ast.NewScope(nil) // struct scope
763753
var list []*ast.Field
@@ -768,7 +758,6 @@ func (p *parser) parseStructType() *ast.StructType {
768758
list = append(list, p.parseFieldDecl(scope))
769759
}
770760
rbrace := p.expect(token.RBRACE)
771-
p.inStruct = false
772761

773762
return &ast.StructType{
774763
Struct: pos,
@@ -970,15 +959,13 @@ func (p *parser) parseInterfaceType() *ast.InterfaceType {
970959
}
971960

972961
pos := p.expect(token.INTERFACE)
973-
p.inStruct = true
974962
lbrace := p.expect(token.LBRACE)
975963
scope := ast.NewScope(nil) // interface scope
976964
var list []*ast.Field
977965
for p.tok == token.IDENT {
978966
list = append(list, p.parseMethodSpec(scope))
979967
}
980968
rbrace := p.expect(token.RBRACE)
981-
p.inStruct = false
982969

983970
return &ast.InterfaceType{
984971
Interface: pos,

0 commit comments

Comments
 (0)