func (p *parser) want(tok token) {
if !p.got(tok) {
- p.syntaxError("expecting " + tokstring(tok))
+ p.syntaxError("expected " + tokstring(tok))
p.advance()
}
}
func (p *parser) gotAssign() bool {
switch p.tok {
case _Define:
- p.syntaxError("expecting =")
+ p.syntaxError("expected =")
fallthrough
case _Assign:
p.next()
// nothing to do
case strings.HasPrefix(msg, "in "), strings.HasPrefix(msg, "at "), strings.HasPrefix(msg, "after "):
msg = " " + msg
- case strings.HasPrefix(msg, "expecting "):
+ case strings.HasPrefix(msg, "expected "):
msg = ", " + msg
default:
// plain error - we don't care about current token
tok = tokstring(p.tok)
}
+ // TODO(gri) This may print "unexpected X, expected Y".
+ // Consider "got X, expected Y" in this case.
p.errorAt(pos, "syntax error: unexpected "+tok+msg)
}
}
if p.tok != _Name {
- p.syntaxError("expecting name or (")
+ p.syntaxError("expected name or (")
p.advance(_Lbrace, _Semi)
return nil
}
if dir == RecvOnly {
// t is type <-chan E but <-<-chan E is not permitted
// (report same error as for "type _ <-<-chan E")
- p.syntaxError("unexpected <-, expecting chan")
+ p.syntaxError("unexpected <-, expected chan")
// already progressed, no need to advance
}
c.Dir = RecvOnly
if dir == SendOnly {
// channel dir is <- but channel element E is not a channel
// (report same error as for "type _ <-chan<-E")
- p.syntaxError(fmt.Sprintf("unexpected %s, expecting chan", String(t)))
+ p.syntaxError(fmt.Sprintf("unexpected %s, expected chan", String(t)))
// already progressed, no need to advance
}
return x
default:
x := p.badExpr()
- p.syntaxError("expecting expression")
+ p.syntaxError("expected expression")
p.advance(_Rparen, _Rbrack, _Rbrace)
return x
}
p.want(_Rparen)
default:
- p.syntaxError("expecting name or (")
+ p.syntaxError("expected name or (")
p.advance(_Semi, _Rparen)
}
var comma bool
if p.tok == _Rbrack {
// invalid empty instance, slice or index expression; accept but complain
- p.syntaxError("expecting operand")
+ p.syntaxError("expected operand")
i = p.badExpr()
} else {
i, comma = p.typeList()
// x[i:...
// For better error message, don't simply use p.want(_Colon) here (issue #47704).
if !p.got(_Colon) {
- p.syntaxError("expecting comma, : or ]")
+ p.syntaxError("expected comma, : or ]")
p.advance(_Comma, _Colon, _Rbrack)
}
p.xnest++
typ := p.typeOrNil()
if typ == nil {
typ = p.badExpr()
- p.syntaxError("expecting type")
+ p.syntaxError("expected type")
p.advance(_Comma, _Colon, _Semi, _Rparen, _Rbrack, _Rbrace)
}
x.pos = pos
x.X = typ
if p.tok == _Rbrack {
- p.syntaxError("expecting type")
+ p.syntaxError("expected type argument list")
x.Index = p.badExpr()
} else {
x.Index, _ = p.typeList()
// Trailing commas are accepted in type parameter
// lists but not in array type declarations.
// Accept for better error handling but complain.
- p.syntaxError("unexpected comma; expecting ]")
+ p.syntaxError("unexpected comma; expected ]")
p.next()
}
p.want(_Rbrack)
p.addField(styp, pos, nil, typ, tag)
default:
- p.syntaxError("expecting field name or embedded type")
+ p.syntaxError("expected field name or embedded type")
p.advance(_Semi, _Rbrace)
}
}
t := p.typeOrNil()
if t == nil {
t = p.badExpr()
- p.syntaxError("expecting ~ term or type")
+ p.syntaxError("expected ~ term or type")
p.advance(_Operator, _Semi, _Rparen, _Rbrack, _Rbrace)
}
return f
}
- p.syntaxError("expecting " + tokstring(follow))
+ p.syntaxError("expected " + tokstring(follow))
p.advance(_Comma, follow)
return nil
}
return p.newAssignStmt(pos, op, lhs, rhs)
default:
- p.syntaxError("expecting := or = or comma")
+ p.syntaxError("expected := or = or comma")
p.advance(_Semi, _Rbrace)
// make the best of what we have
if x, ok := lhs.(*ListExpr); ok {
// people coming from C may forget that braces are mandatory in Go
if !p.got(_Lbrace) {
- p.syntaxError("expecting { after " + context)
+ p.syntaxError("expected { after " + context)
p.advance(_Name, _Rbrace)
s.Rbrace = p.pos() // in case we found "}"
if p.got(_Rbrace) {
if keyword == _For {
if p.tok != _Semi {
if p.tok == _Lbrace {
- p.syntaxError("expecting for loop condition")
+ p.syntaxError("expected for loop condition")
goto done
}
condStmt = p.simpleStmt(nil, 0 /* range not permitted */)
case nil:
if keyword == _If && semi.pos.IsKnown() {
if semi.lit != "semicolon" {
- p.syntaxErrorAt(semi.pos, fmt.Sprintf("unexpected %s, expecting { after if clause", semi.lit))
+ p.syntaxErrorAt(semi.pos, fmt.Sprintf("unexpected %s, expected { after if clause", semi.lit))
} else {
p.syntaxErrorAt(semi.pos, "missing condition in if statement")
}
p.next()
default:
- p.syntaxError("expecting case or default or }")
+ p.syntaxError("expected case or default or }")
p.advance(_Colon, _Case, _Default, _Rbrace)
}
p.next()
default:
- p.syntaxError("expecting case or default or }")
+ p.syntaxError("expected case or default or }")
p.advance(_Colon, _Case, _Default, _Rbrace)
}
}
n := NewName(p.pos(), "_")
- p.syntaxError("expecting name")
+ p.syntaxError("expected name")
p.advance()
return n
}
x = p.name()
default:
x = NewName(p.pos(), "_")
- p.syntaxError("expecting name")
+ p.syntaxError("expected name")
p.advance(_Dot, _Semi, _Rbrace)
}