]> Cypherpunks repositories - gostls13.git/commitdiff
- collect line comments for methods in interfaces
authorRobert Griesemer <gri@golang.org>
Mon, 2 Nov 2009 17:18:02 +0000 (09:18 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 2 Nov 2009 17:18:02 +0000 (09:18 -0800)
  (previously not shown in godoc)
- simplify parsing of struct types (match code structure for parsing interface types)

R=rsc, r
http://go/go-review/1016019

src/pkg/go/parser/parser.go
src/pkg/go/printer/testdata/comments.x

index 723f40f0110338706b8bd580794ad2961ec295c2..79b99e96a16047a3a6d9c983adb6b40397e95b10 100644 (file)
@@ -485,16 +485,13 @@ func (p *parser) parseStructType() *ast.StructType {
        pos := p.expect(token.STRUCT);
        lbrace := p.expect(token.LBRACE);
        list := vector.New(0);
-       for p.tok != token.RBRACE && p.tok != token.EOF {
+       for p.tok == token.IDENT || p.tok == token.MUL {
                f := p.parseFieldDecl();
-               list.Push(f);
-               if p.tok == token.SEMICOLON {
-                       p.next();
-                       f.Comment = p.lineComment;
-               } else {
-                       f.Comment = p.lineComment;
-                       break;
+               if p.tok != token.RBRACE {
+                       p.expect(token.SEMICOLON);
                }
+               f.Comment = p.lineComment;
+               list.Push(f);
        }
        rbrace := p.expect(token.RBRACE);
        p.optSemi = true;
@@ -699,10 +696,12 @@ func (p *parser) parseInterfaceType() *ast.InterfaceType {
        lbrace := p.expect(token.LBRACE);
        list := vector.New(0);
        for p.tok == token.IDENT {
-               list.Push(p.parseMethodSpec());
+               m := p.parseMethodSpec();
                if p.tok != token.RBRACE {
                        p.expect(token.SEMICOLON);
                }
+               m.Comment = p.lineComment;
+               list.Push(m);
        }
        rbrace := p.expect(token.RBRACE);
        p.optSemi = true;
index 72ac8f0eb82fb355da0cfa201ee6a1743e0e3a61..d10eb2e5604a042e4644c86a9d1d28c6a7c0219f 100644 (file)
@@ -42,7 +42,7 @@ type I0 interface {
 // The I1 interface; some methods are not exported.
 type I1 interface {
        I0;
-       F(x float) float;
+       F(x float) float;       // exported methods
        // contains unexported methods
 }
 
@@ -50,6 +50,6 @@ type I1 interface {
 // The I2 interface; all methods are exported.
 type I2 interface {
        I0;
-       F(x float) float;
-       G(x float) float;
+       F(x float) float;       // exported method
+       G(x float) float;       // exported method
 }