]> Cypherpunks repositories - gostls13.git/commitdiff
use separate lex buf for better errors:
authorRuss Cox <rsc@golang.org>
Fri, 3 Apr 2009 00:59:09 +0000 (17:59 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 3 Apr 2009 00:59:09 +0000 (17:59 -0700)
package main
func main() { func(){}() + + }

x.go:2: syntax error near _f001

becomes

x.go:2: syntax error near func

R=ken
OCL=27047
CL=27047

src/cmd/gc/go.h
src/cmd/gc/lex.c
src/cmd/gc/subr.c

index 2d8f0920882556a1b801d6673d2bb4117c4c6a80..b3f8a50bce36a0486b399821ae16171b7850d388 100644 (file)
@@ -533,6 +533,7 @@ EXTERN      char*   package;
 EXTERN Biobuf* bout;
 EXTERN int     nerrors;
 EXTERN char    namebuf[NSYMB];
+EXTERN char    lexbuf[NSYMB];
 EXTERN char    debug[256];
 EXTERN Sym*    hash[NHASH];
 EXTERN Sym*    dclstack;
index c186058b4436a6a2bb142c0bca149c4bbdb91d53..3477a2cffc9f2a0a2f7880f5df0eb49470554a76 100644 (file)
@@ -370,12 +370,12 @@ l0:
 
        if(c >= Runeself) {
                /* all multibyte runes are alpha */
-               cp = namebuf;
+               cp = lexbuf;
                goto talph;
        }
 
        if(isalpha(c)) {
-               cp = namebuf;
+               cp = lexbuf;
                goto talph;
        }
 
@@ -388,13 +388,13 @@ l0:
                return -1;
 
        case '_':
-               cp = namebuf;
+               cp = lexbuf;
                goto talph;
 
        case '.':
                c1 = getc();
                if(isdigit(c1)) {
-                       cp = namebuf;
+                       cp = lexbuf;
                        *cp++ = c;
                        c = c1;
                        c1 = 0;
@@ -413,7 +413,7 @@ l0:
 
        case '"':
                /* "..." */
-               strcpy(namebuf, "\"<string>\"");
+               strcpy(lexbuf, "\"<string>\"");
                cp = mal(sizeof(int32));
                clen = sizeof(int32);
 
@@ -437,7 +437,7 @@ l0:
 
        case '`':
                /* `...` */
-               strcpy(namebuf, "`<string>`");
+               strcpy(lexbuf, "`<string>`");
                cp = mal(sizeof(int32));
                clen = sizeof(int32);
 
@@ -719,7 +719,7 @@ asop:
 
 talph:
        /*
-        * cp is set to namebuf and some
+        * cp is set to lexbuf and some
         * prefix has been stored
         */
        for(;;) {
@@ -748,7 +748,7 @@ talph:
        *cp = 0;
        ungetc(c);
 
-       s = lookup(namebuf);
+       s = lookup(lexbuf);
        if(s->lexical == LIGNORE)
                goto l0;
 
@@ -768,7 +768,7 @@ talph:
 
 tnum:
        c1 = 0;
-       cp = namebuf;
+       cp = lexbuf;
        if(c != '0') {
                for(;;) {
                        *cp++ = c;
@@ -790,7 +790,7 @@ tnum:
                                continue;
                        if(c >= 'A' && c <= 'F')
                                continue;
-                       if(cp == namebuf+2)
+                       if(cp == lexbuf+2)
                                yyerror("malformed hex constant");
                        goto ncu;
                }
@@ -826,7 +826,7 @@ ncu:
        ungetc(c);
 
        yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval));
-       mpatofix(yylval.val.u.xval, namebuf);
+       mpatofix(yylval.val.u.xval, lexbuf);
        if(yylval.val.u.xval->ovf) {
                yyerror("overflow in constant");
                mpmovecfix(yylval.val.u.xval, 0);
@@ -880,7 +880,7 @@ caseout:
        ungetc(c);
 
        yylval.val.u.fval = mal(sizeof(*yylval.val.u.fval));
-       mpatoflt(yylval.val.u.fval, namebuf);
+       mpatoflt(yylval.val.u.fval, lexbuf);
        if(yylval.val.u.fval->val.ovf) {
                yyerror("overflow in float constant");
                mpmovecflt(yylval.val.u.fval, 0.0);
index d6414f7eb6a467da9c684cff4de5ff91f04dba8a..fe5d33084ec82c679c2227204eb1643f07434e03 100644 (file)
@@ -23,7 +23,7 @@ yyerror(char *fmt, ...)
        vfprint(1, fmt, arg);
        va_end(arg);
        if(strcmp(fmt, "syntax error") == 0)
-               print(" near %s", namebuf);
+               print(" near %s", lexbuf);
        print("\n");
        if(debug['h'])
                *(int*)0 = 0;