* Handle carriage returns. Fixes NIX-53.

This commit is contained in:
Eelco Dolstra 2006-08-16 10:28:44 +00:00
parent bfe19b3c37
commit 2670642733
2 changed files with 14 additions and 5 deletions

View file

@ -21,6 +21,10 @@ static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
{ {
while (len--) { while (len--) {
switch (*s++) { switch (*s++) {
case '\r':
if (*s == '\n') /* cr/lf */
s++;
/* fall through */
case '\n': case '\n':
++loc->first_line; ++loc->first_line;
loc->first_column = 1; loc->first_column = 1;
@ -85,8 +89,8 @@ inherit { return INHERIT; }
{PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ } {PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ }
{URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ } {URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ }
[ \t\n]+ /* eat up whitespace */ [ \t\r\n]+ /* eat up whitespace */
\#[^\n]* /* single-line comments */ \#[^\r\n]* /* single-line comments */
\/\*([^*]|\*[^\/])*\*\/ /* long comments */ \/\*([^*]|\*[^\/])*\*\/ /* long comments */
. return yytext[0]; . return yytext[0];

View file

@ -79,11 +79,16 @@ Expr unescapeStr(const char * s)
if (c == '\\') { if (c == '\\') {
assert(*s); assert(*s);
c = *s++; c = *s++;
if (c == 'n') t += "\n"; if (c == 'n') t += '\n';
else if (c == 'r') t += "\r"; else if (c == 'r') t += '\r';
else if (c == 't') t += "\t"; else if (c == 't') t += '\t';
else t += c; else t += c;
} }
else if (c == '\r') {
/* Normalise CR and CR/LF into LF. */
t += '\n';
if (*s == '\n') s++; /* cr/lf */
}
else t += c; else t += c;
} }
return makeStr(toATerm(t)); return makeStr(toATerm(t));