aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-05-14 16:47:53 -0700
committerRobert Griesemer <gri@golang.org>2015-05-15 17:58:56 +0000
commit40fad6c286ca57317e94aeca50b75fa3444ca1fa (patch)
treed2de98ccfe8ec15bc975c276e79e40808255d91c /src/go/parser/parser.go
parent1467776b17c7dc232f5586944785f85f48862b49 (diff)
downloadgo-40fad6c286ca57317e94aeca50b75fa3444ca1fa.tar.gz
go-40fad6c286ca57317e94aeca50b75fa3444ca1fa.zip
go/parser: better error message for missing ',' in lists
Fixes #8940. Change-Id: Ie9e5149983518ba8d56ddd82ac8f4cde6b644167 Reviewed-on: https://go-review.googlesource.com/10089 Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r--src/go/parser/parser.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index 0095d7facf..fb6ca76a77 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -412,14 +412,17 @@ func (p *parser) expectSemi() {
}
}
-func (p *parser) atComma(context string) bool {
+func (p *parser) atComma(context string, follow token.Token) bool {
if p.tok == token.COMMA {
return true
}
- if p.tok == token.SEMICOLON && p.lit == "\n" {
- p.error(p.pos, "missing ',' before newline in "+context)
- return true // "insert" the comma and continue
-
+ if p.tok != follow {
+ msg := "missing ','"
+ if p.tok == token.SEMICOLON && p.lit == "\n" {
+ msg += " before newline"
+ }
+ p.error(p.pos, msg+" in "+context)
+ return true // "insert" comma and continue
}
return false
}
@@ -825,7 +828,7 @@ func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params [
// parameter or result variable is the function body.
p.declare(field, nil, scope, ast.Var, idents...)
p.resolve(typ)
- if !p.atComma("parameter list") {
+ if !p.atComma("parameter list", token.RPAREN) {
return
}
p.next()
@@ -838,7 +841,7 @@ func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params [
// parameter or result variable is the function body.
p.declare(field, nil, scope, ast.Var, idents...)
p.resolve(typ)
- if !p.atComma("parameter list") {
+ if !p.atComma("parameter list", token.RPAREN) {
break
}
p.next()
@@ -1248,7 +1251,7 @@ func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
ellipsis = p.pos
p.next()
}
- if !p.atComma("argument list") {
+ if !p.atComma("argument list", token.RPAREN) {
break
}
p.next()
@@ -1323,7 +1326,7 @@ func (p *parser) parseElementList() (list []ast.Expr) {
for p.tok != token.RBRACE && p.tok != token.EOF {
list = append(list, p.parseElement())
- if !p.atComma("composite literal") {
+ if !p.atComma("composite literal", token.RBRACE) {
break
}
p.next()