diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-08-16 10:28:44 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-08-16 10:28:44 +0000 |
commit | 267064273301ee9547589fd5874eee693415352f (patch) | |
tree | 50c50e6e7976ee6136effd9417a7302d519bc5fa /src/libexpr | |
parent | bfe19b3c3728d90cad7575c5d2571d48f0ef0d14 (diff) |
* Handle carriage returns. Fixes NIX-53.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/lexer.l | 8 | ||||
-rw-r--r-- | src/libexpr/parser.cc | 11 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index bc9a38da4..892543ec2 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -21,6 +21,10 @@ static void adjustLoc(YYLTYPE * loc, const char * s, size_t len) { while (len--) { switch (*s++) { + case '\r': + if (*s == '\n') /* cr/lf */ + s++; + /* fall through */ case '\n': ++loc->first_line; loc->first_column = 1; @@ -85,8 +89,8 @@ inherit { return INHERIT; } {PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ } {URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ } -[ \t\n]+ /* eat up whitespace */ -\#[^\n]* /* single-line comments */ +[ \t\r\n]+ /* eat up whitespace */ +\#[^\r\n]* /* single-line comments */ \/\*([^*]|\*[^\/])*\*\/ /* long comments */ . return yytext[0]; diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc index 9b3e9041d..fa6c4e2f3 100644 --- a/src/libexpr/parser.cc +++ b/src/libexpr/parser.cc @@ -79,11 +79,16 @@ Expr unescapeStr(const char * s) if (c == '\\') { assert(*s); c = *s++; - if (c == 'n') t += "\n"; - else if (c == 'r') t += "\r"; - else if (c == 't') t += "\t"; + if (c == 'n') t += '\n'; + else if (c == 'r') t += '\r'; + else if (c == 't') t += '\t'; 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; } return makeStr(toATerm(t)); |