]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: more tolerant parsing of const and var decls
authorRobert Griesemer <gri@golang.org>
Wed, 10 Jul 2013 19:01:07 +0000 (12:01 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 10 Jul 2013 19:01:07 +0000 (12:01 -0700)
Instead, rely on the type checker.

R=adonovan
CC=golang-dev
https://golang.org/cl/10826044

src/pkg/go/parser/parser.go
src/pkg/go/parser/short_test.go

index ded733489bd6c218227187b796f698d8211d0de6..42a1c5e57c31efe755b39887437190f6a8ae15fa 100644 (file)
@@ -2180,8 +2180,9 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
        idents := p.parseIdentList()
        typ := p.tryType()
        var values []ast.Expr
-       if p.tok == token.ASSIGN || keyword == token.CONST && (typ != nil || iota == 0) || keyword == token.VAR && typ == nil {
-               p.expect(token.ASSIGN)
+       // always permit optional initialization for more tolerant parsing
+       if p.tok == token.ASSIGN {
+               p.next()
                values = p.parseRhsList()
        }
        p.expectSemi() // call before accessing p.linecomment
index a15b3ed35c29ee2fae1c7d359419d69ef49881c8..a581319e05cd5ea973e4d2f441ba2b6d11405cb1 100644 (file)
@@ -47,7 +47,6 @@ var invalids = []string{
        `package p; func f() { if { /* ERROR "expected operand" */ } };`,
        `package p; func f() { if ; { /* ERROR "expected operand" */ } };`,
        `package p; func f() { if f(); { /* ERROR "expected operand" */ } };`,
-       `package p; const c; /* ERROR "expected '='" */`,
        `package p; func f() { if _ /* ERROR "expected condition" */ = range x; true {} };`,
        `package p; func f() { switch _ /* ERROR "expected condition" */ = range x; true {} };`,
        `package p; func f() { for _ = range x ; /* ERROR "expected '{'" */ ; {} };`,