case _Semi:
return "semicolon or newline"
}
- return tok.String()
+ s := tok.String()
+ if _Break <= tok && tok <= _Var {
+ return "keyword " + s
+ }
+ return s
}
// Convenience methods using the current token position.
if p.tok != _Semi {
// accept potential varDecl but complain
if p.got(_Var) {
- p.syntaxError(fmt.Sprintf("var declaration not allowed in %s initializer", tokstring(keyword)))
+ p.syntaxError(fmt.Sprintf("var declaration not allowed in %s initializer", keyword.String()))
}
init = p.simpleStmt(nil, keyword)
// If we have a range clause, we are done (can only happen for keyword == _For).
--- /dev/null
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+var _ (/* ERROR unexpected keyword type */ type T)
package a
var? // ERROR "invalid character U\+003F '\?'|invalid character 0x3f in input file"
-var x int // ERROR "unexpected var|expected identifier|expected type"
+var x int // ERROR "unexpected keyword var|expected identifier|expected type"
func main() {
}
switch {
case 0: f(); case 0:
- case 0: f() case 0: // ERROR "unexpected case at end of statement"
+ case 0: f() case 0: // ERROR "unexpected keyword case at end of statement"
}
switch {
case 0: f(); default:
- case 0: f() default: // ERROR "unexpected default at end of statement"
+ case 0: f() default: // ERROR "unexpected keyword default at end of statement"
}
switch {
func main() {
if x { } // GCCGO_ERROR "undefined"
- else { } // ERROR "unexpected semicolon or newline before .?else.?|unexpected else"
+ else { } // ERROR "unexpected semicolon or newline before .?else.?|unexpected keyword else"
}