diff options
| author | Robert Griesemer <gri@golang.org> | 2016-10-21 17:23:01 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2016-10-25 00:54:30 +0000 |
| commit | c0e2318f7c9a83b237a08b208eb145d520e3a233 (patch) | |
| tree | ceb1e16cb754aa69b619beef830ec59803bbe80c /src/cmd/compile/internal/syntax/parser.go | |
| parent | 1b0cf430dd130ad53e9f43bc04d2ed91bcd87b26 (diff) | |
| download | go-c0e2318f7c9a83b237a08b208eb145d520e3a233.tar.xz | |
cmd/compile: simplify parsing of type aliases
Change-Id: Ia86841cf84bc17ff6ecc6e5ac4cec86384a0da00
Reviewed-on: https://go-review.googlesource.com/31719
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser.go')
| -rw-r--r-- | src/cmd/compile/internal/syntax/parser.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index 1eb85fb7ee..d0dec3ab1b 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -322,7 +322,8 @@ func (p *parser) aliasDecl(tok token, name *Name, group *Group) Decl { d := new(AliasDecl) d.initFrom(&name.node) - p.want(_Rarrow) + // lhs identifier and "=>" have been consumed already + d.Tok = tok d.Name = name d.Orig = p.dotname(p.name()) @@ -338,7 +339,7 @@ func (p *parser) constDecl(group *Group) Decl { } name := p.name() - if p.tok == _Rarrow { + if p.got(_Rarrow) { return p.aliasDecl(Const, name, group) } @@ -364,7 +365,8 @@ func (p *parser) typeDecl(group *Group) Decl { } name := p.name() - if p.tok == _Rarrow { + // permit both: type T => p.T and: type T = p.T for now + if p.got(_Rarrow) || p.got(_Assign) { return p.aliasDecl(Type, name, group) } @@ -372,9 +374,6 @@ func (p *parser) typeDecl(group *Group) Decl { d.initFrom(&name.node) d.Name = name - // accept "type T = p.T" for now so we can experiment - // with a type-alias only approach as well - d.Alias = p.got(_Assign) d.Type = p.tryType() if d.Type == nil { p.syntax_error("in type declaration") @@ -393,7 +392,7 @@ func (p *parser) varDecl(group *Group) Decl { } name := p.name() - if p.tok == _Rarrow { + if p.got(_Rarrow) { return p.aliasDecl(Var, name, group) } @@ -449,7 +448,7 @@ func (p *parser) funcDecl() Decl { } name := p.name() - if recv == nil && p.tok == _Rarrow { + if recv == nil && p.got(_Rarrow) { return p.aliasDecl(Func, name, nil) } |
