Commit feb1c77f authored by Ken Thompson's avatar Ken Thompson

cafebabe

SVN=121574
parent d9178fce
...@@ -387,7 +387,7 @@ void lexinit(void); ...@@ -387,7 +387,7 @@ void lexinit(void);
char* lexname(int); char* lexname(int);
long getr(void); long getr(void);
int getnsc(void); int getnsc(void);
ulong escchar(int, int*); int escchar(int, int*, vlong*);
int getc(void); int getc(void);
void ungetc(int); void ungetc(int);
void mkpackage(char*); void mkpackage(char*);
......
...@@ -171,7 +171,8 @@ cannedimports(void) ...@@ -171,7 +171,8 @@ cannedimports(void)
long long
yylex(void) yylex(void)
{ {
ulong c, c1; int c, c1;
vlong v;
char *cp; char *cp;
Rune rune; Rune rune;
int escflag; int escflag;
...@@ -224,14 +225,14 @@ l0: ...@@ -224,14 +225,14 @@ l0:
caseq: caseq:
for(;;) { for(;;) {
c = escchar('"', &escflag); if(escchar('"', &escflag, &v))
if(c == EOF)
break; break;
if(escflag) { if(escflag) {
cp = remal(cp, c1, 1); cp = remal(cp, c1, 1);
cp[c1++] = c; cp[c1++] = v;
} else { } else {
rune = c; // botch - this limits size of runes
rune = v;
c = runelen(rune); c = runelen(rune);
cp = remal(cp, c1, c); cp = remal(cp, c1, c);
runetochar(cp+c1, &rune); runetochar(cp+c1, &rune);
...@@ -281,15 +282,13 @@ l0: ...@@ -281,15 +282,13 @@ l0:
case '\'': case '\'':
/* '.' */ /* '.' */
c = escchar('\'', &escflag); if(escchar('\'', &escflag, &v))
if(c == EOF) v = '\''; // allow '''
c = '\''; if(!escchar('\'', &escflag, &v)) {
c1 = escchar('\'', &escflag);
if(c1 != EOF) {
yyerror("missing '"); yyerror("missing '");
ungetc(c1); ungetc(v);
} }
yylval.val.vval = c; yylval.val.vval = v;
yylval.val.ctype = CTINT; yylval.val.ctype = CTINT;
DBG("lex: codepoint literal\n"); DBG("lex: codepoint literal\n");
return LLITERAL; return LLITERAL;
...@@ -696,11 +695,11 @@ getnsc(void) ...@@ -696,11 +695,11 @@ getnsc(void)
} }
ulong int
escchar(int e, int *escflg) escchar(int e, int *escflg, vlong *val)
{ {
ulong c, l; int i, c;
int i; vlong l;
*escflg = 0; *escflg = 0;
...@@ -708,13 +707,15 @@ loop: ...@@ -708,13 +707,15 @@ loop:
c = getr(); c = getr();
if(c == '\n') { if(c == '\n') {
yyerror("newline in string"); yyerror("newline in string");
return EOF; return 1;
} }
if(c != '\\') { if(c != '\\') {
if(c == e) if(c == e)
c = EOF; return 1;
return c; *val = c;
return 0;
} }
c = getr(); c = getr();
switch(c) { switch(c) {
case '\n': case '\n':
...@@ -742,20 +743,21 @@ loop: ...@@ -742,20 +743,21 @@ loop:
case '7': case '7':
goto oct; goto oct;
case 'a': return '\a'; case 'a': c = '\a'; break;
case 'b': return '\b'; case 'b': c = '\b'; break;
case 'f': return '\f'; case 'f': c = '\f'; break;
case 'n': return '\n'; case 'n': c = '\n'; break;
case 'r': return '\r'; case 'r': c = '\r'; break;
case 't': return '\t'; case 't': c = '\t'; break;
case 'v': return '\v'; case 'v': c = '\v'; break;
case '\\': return '\\'; case '\\': c = '\\'; break;
default: default:
if(c != e) if(c != e)
warn("unknown escape sequence: %c", c); warn("unknown escape sequence: %c", c);
} }
return c; *val = c;
return 0;
hex: hex:
l = 0; l = 0;
...@@ -778,7 +780,8 @@ hex: ...@@ -778,7 +780,8 @@ hex:
break; break;
} }
*escflg = 1; *escflg = 1;
return l; *val = l;
return 0;
oct: oct:
l = c - '0'; l = c - '0';
...@@ -794,7 +797,8 @@ oct: ...@@ -794,7 +797,8 @@ oct:
if(l > 255) if(l > 255)
warn("oct escape value > 255: %d", l); warn("oct escape value > 255: %d", l);
*escflg = 1; *escflg = 1;
return l; *val = l;
return 0;
} }
static struct static struct
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment