mirror of
https://github.com/golang/go
synced 2024-11-22 05:34:39 -07:00
go/parser: better error sync. if commas are missing
This time for sure. Runs all tests. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5752060
This commit is contained in:
parent
3a065c5a73
commit
9e8e4a9313
@ -376,17 +376,15 @@ func (p *parser) expectSemi() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) seesComma(context string) bool {
|
func (p *parser) atComma(context string) bool {
|
||||||
if p.tok == token.COMMA {
|
if p.tok == token.COMMA {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
/*
|
if p.tok == token.SEMICOLON && p.lit == "\n" {
|
||||||
if p.tok == token.SEMICOLON && p.lit == "\n" {
|
p.error(p.pos, "missing ',' before newline in "+context)
|
||||||
p.error(p.pos, "missing ',' before newline in "+context)
|
return true // "insert" the comma and continue
|
||||||
return true // "insert" the comma and continue
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,7 +659,7 @@ func (p *parser) parseVarList(isParam bool) (list []ast.Expr, typ ast.Expr) {
|
|||||||
// accept them all for more robust parsing and complain later
|
// accept them all for more robust parsing and complain later
|
||||||
for typ := p.parseVarType(isParam); typ != nil; {
|
for typ := p.parseVarType(isParam); typ != nil; {
|
||||||
list = append(list, typ)
|
list = append(list, typ)
|
||||||
if !p.seesComma("variable list") {
|
if p.tok != token.COMMA {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
@ -702,7 +700,7 @@ func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params [
|
|||||||
// Go spec: The scope of an identifier denoting a function
|
// Go spec: The scope of an identifier denoting a function
|
||||||
// parameter or result variable is the function body.
|
// parameter or result variable is the function body.
|
||||||
p.declare(field, nil, scope, ast.Var, idents...)
|
p.declare(field, nil, scope, ast.Var, idents...)
|
||||||
if !p.seesComma("parameter list") {
|
if !p.atComma("parameter list") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
@ -1092,7 +1090,7 @@ func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
|
|||||||
ellipsis = p.pos
|
ellipsis = p.pos
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
if !p.seesComma("argument list") {
|
if !p.atComma("argument list") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
@ -1132,7 +1130,7 @@ func (p *parser) parseElementList() (list []ast.Expr) {
|
|||||||
|
|
||||||
for p.tok != token.RBRACE && p.tok != token.EOF {
|
for p.tok != token.RBRACE && p.tok != token.EOF {
|
||||||
list = append(list, p.parseElement(true))
|
list = append(list, p.parseElement(true))
|
||||||
if !p.seesComma("composite literal") {
|
if !p.atComma("composite literal") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
|
Loading…
Reference in New Issue
Block a user