Commit eba82f43 authored by Ken Thompson's avatar Ken Thompson

better diagnostics for eof in a string.

this assumes that embedded newlines are
legal in back-quote strings.

R=r
OCL=30502
CL=30502
parent db7a6221
...@@ -371,11 +371,11 @@ isfrog(int c) ...@@ -371,11 +371,11 @@ isfrog(int c)
static int32 static int32
_yylex(void) _yylex(void)
{ {
int c, c1, clen; int c, c1, clen, escflag;
vlong v; vlong v;
char *cp; char *cp;
Rune rune; Rune rune;
int escflag; int32 lno;
Sym *s; Sym *s;
prevlineno = lineno; prevlineno = lineno;
...@@ -459,9 +459,14 @@ l0: ...@@ -459,9 +459,14 @@ l0:
clen = sizeof(int32); clen = sizeof(int32);
casebq: casebq:
lno = lineno;
for(;;) { for(;;) {
c = getc(); c = getc();
if(c == EOF || c == '`') if(c == EOF) {
yyerror("eof in string starting at line %L", lno);
break;
}
if(c == '`')
break; break;
cp = remal(cp, clen, 1); cp = remal(cp, clen, 1);
cp[clen++] = c; cp[clen++] = c;
...@@ -1082,11 +1087,16 @@ escchar(int e, int *escflg, vlong *val) ...@@ -1082,11 +1087,16 @@ escchar(int e, int *escflg, vlong *val)
loop: loop:
c = getr(); c = getr();
if(c == '\n') { switch(c) {
case EOF:
yyerror("eof in string");
return 1;
case '\n':
yyerror("newline in string"); yyerror("newline in string");
return 1; return 1;
} case '\\':
if(c != '\\') { break;
default:
if(c == e) if(c == e)
return 1; return 1;
*val = c; *val = c;
......
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