From efbaac87ed5df1764747ea89043475db86c52e19 Mon Sep 17 00:00:00 2001 From: forsyth Date: Fri, 30 Dec 2011 18:56:40 +0000 Subject: 20111222-0900 --- limbo/lex.c | 65 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'limbo') diff --git a/limbo/lex.c b/limbo/lex.c index 749f2a7a..d75e28f2 100644 --- a/limbo/lex.c +++ b/limbo/lex.c @@ -815,37 +815,57 @@ escchar(void) } void -lexstring(void) +lexstring(int israw) { char *str; - int c; + int c, t, startlno; Rune r; int len, alloc; alloc = 32; len = 0; str = allocmem(alloc * sizeof(str)); + startlno = lineno; for(;;){ c = getrune(); - switch(c){ - case '\\': - c = escchar(); - if(c != Beof) + if(israw){ + switch(c){ + case '`': + yylval.tok.v.idval = enterstring(str, len); + return; + case '\n': + lineno++; + linepos = Linestart; break; - /* fall through */ - case Beof: - yyerror("end of file in string constant"); - yylval.tok.v.idval = enterstring(str, len); - return; - case '\n': - yyerror("newline in string constant"); - lineno++; - linepos = Linestart; - yylval.tok.v.idval = enterstring(str, len); - return; - case '"': - yylval.tok.v.idval = enterstring(str, len); - return; + case Beof: + t = lineno; + lineno = startlno; + yyerror("end of file in raw string constant"); + lineno = t; + yylval.tok.v.idval = enterstring(str, len); + return; + } + }else{ + switch(c){ + case '\\': + c = escchar(); + if(c != Beof) + break; + /* fall through */ + case Beof: + yyerror("end of file in string constant"); + yylval.tok.v.idval = enterstring(str, len); + return; + case '\n': + yyerror("newline in string constant"); + lineno++; + linepos = Linestart; + yylval.tok.v.idval = enterstring(str, len); + return; + case '"': + yylval.tok.v.idval = enterstring(str, len); + return; + } } while(len+UTFmax+1 >= alloc){ alloc += 32; @@ -893,7 +913,10 @@ loop: case '\f': goto loop; case '"': - lexstring(); + lexstring(0); + return Lsconst; + case '`': + lexstring(1); return Lsconst; case '\'': c = getrune(); -- cgit v1.2.3