From e7c4a6dfcaf88644f08fbc6ddc5904f4857aafb8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 8 Apr 2011 13:53:32 -0400 Subject: [PATCH] gc: fix weird error message Fixes #1670. R=ken2 CC=golang-dev https://golang.org/cl/4386045 --- src/cmd/gc/subr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index eb0fc3c624..2098794a7c 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -135,6 +135,7 @@ yyerror(char *fmt, ...) int i; static int lastsyntax; va_list arg; + char buf[512], *p; if(strncmp(fmt, "syntax error", 12) == 0) { nsyntaxerrors++; @@ -147,6 +148,16 @@ yyerror(char *fmt, ...) return; lastsyntax = lexlineno; + if(strstr(fmt, "{ or {")) { + // The grammar has { and LBRACE but both show up as {. + // Rewrite syntax error referring to "{ or {" to say just "{". + strecpy(buf, buf+sizeof buf, fmt); + p = strstr(buf, "{ or {"); + if(p) + memmove(p+1, p+6, strlen(p+6)+1); + fmt = buf; + } + // look for parse state-specific errors in list (see go.errors). for(i=0; i