]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix weird error message
authorRuss Cox <rsc@golang.org>
Fri, 8 Apr 2011 17:53:32 +0000 (13:53 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 8 Apr 2011 17:53:32 +0000 (13:53 -0400)
Fixes #1670.

R=ken2
CC=golang-dev
https://golang.org/cl/4386045

src/cmd/gc/subr.c

index eb0fc3c624b43421bd20c45304ce462afe3d6b5a..2098794a7ce0b1728d4e82ffa2c0f1b69ebb56a9 100644 (file)
@@ -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<nelem(yymsg); i++) {
                        if(yymsg[i].yystate == yystate && yymsg[i].yychar == yychar) {