aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2018-01-16 16:17:54 -0800
committerRobert Griesemer <gri@golang.org>2018-02-12 21:43:41 +0000
commit7ac393a3f208ab72263a245b80e22ad62abae565 (patch)
tree851cf249f826d564191229ad9c6f60ba8e5e9582 /src/go/parser/parser.go
parent5408d799501432aa247307604df33c622d6a73d3 (diff)
downloadgo-7ac393a3f208ab72263a245b80e22ad62abae565.tar.gz
go-7ac393a3f208ab72263a245b80e22ad62abae565.zip
go/parser: improved error message for unexpected literals
R=go1.11 This is a follow up for #11377 which reported that an error like /tmp/xx.go:9:6: expected '(', found 'IDENT' F1 shouldn't print 'IDENT', as it's just an internal detail. The relevant change wasn't made in the original fix, so here it is. For #11377. Change-Id: Ib76957d86b88e3e63646fbe4abf03a3b9d045139 Reviewed-on: https://go-review.googlesource.com/87900 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r--src/go/parser/parser.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index 6f2955fd50..7671d2a4bb 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -375,13 +375,14 @@ func (p *parser) errorExpected(pos token.Pos, msg string) {
if pos == p.pos {
// the error happened at the current position;
// make the error message more specific
- if p.tok == token.SEMICOLON && p.lit == "\n" {
+ switch {
+ case p.tok == token.SEMICOLON && p.lit == "\n":
msg += ", found newline"
- } else {
+ case p.tok.IsLiteral():
+ // print 123 rather than 'INT', etc.
+ msg += ", found " + p.lit
+ default:
msg += ", found '" + p.tok.String() + "'"
- if p.tok.IsLiteral() {
- msg += " " + p.lit
- }
}
}
p.error(pos, msg)