* Fix the ~ operator.

This commit is contained in:
Eelco Dolstra 2006-08-29 15:29:38 +00:00
parent 1f6616dabf
commit 2132d9ddeb
4 changed files with 24 additions and 3 deletions

View File

@ -321,7 +321,6 @@ Expr evalExpr2(EvalState & state, Expr e)
/* Normal forms. */ /* Normal forms. */
if (sym == symStr || if (sym == symStr ||
sym == symPath || sym == symPath ||
sym == symSubPath || /* !!! evaluate */
sym == symUri || sym == symUri ||
sym == symNull || sym == symNull ||
sym == symInt || sym == symInt ||
@ -503,7 +502,7 @@ Expr evalExpr2(EvalState & state, Expr e)
} }
/* String or path concatenation. */ /* String or path concatenation. */
ATermList es; ATermList es = ATempty;
if (matchOpPlus(e, e1, e2) || matchConcatStrings(e, es)) { if (matchOpPlus(e, e1, e2) || matchConcatStrings(e, es)) {
ATermVector args; ATermVector args;
if (matchOpPlus(e, e1, e2)) { if (matchOpPlus(e, e1, e2)) {
@ -520,6 +519,17 @@ Expr evalExpr2(EvalState & state, Expr e)
} }
} }
/* Backwards compatability: subpath operator (~). */
if (matchSubPath(e, e1, e2)) {
static bool haveWarned;
warnOnce(haveWarned, "the subpath operator (~) is deprecated, use string concatenation (+) instead");
ATermList context = ATempty;
bool dummy;
string s1 = coerceToStringWithContext(state, context, e1, dummy);
string s2 = coerceToStringWithContext(state, context, e2, dummy);
return wrapInContext(context, makePath(toATerm(canonPath(s1 + "/" + s2))));
}
/* List concatenation. */ /* List concatenation. */
if (matchOpConcat(e, e1, e2)) { if (matchOpConcat(e, e1, e2)) {
try { try {

View File

@ -163,7 +163,7 @@ void toString(EvalState & state, Expr e,
} }
} }
else throw TypeError(format("%1% is not allowed as a derivation argument") % showType(e)); else throw TypeError(format("cannot convert %1% to a string") % showType(e));
} }

View File

@ -404,6 +404,15 @@ void printMsg_(Verbosity level, const format & f)
} }
void warnOnce(bool & haveWarned, const format & f)
{
if (!haveWarned) {
printMsg(lvlError, format("warning: %1%") % f.str());
haveWarned = true;
}
}
void readFull(int fd, unsigned char * buf, size_t count) void readFull(int fd, unsigned char * buf, size_t count)
{ {
while (count) { while (count) {

View File

@ -178,6 +178,8 @@ void printMsg_(Verbosity level, const format & f);
#define debug(f) printMsg(lvlDebug, f) #define debug(f) printMsg(lvlDebug, f)
void warnOnce(bool & haveWarned, const format & f);
/* Wrappers arount read()/write() that read/write exactly the /* Wrappers arount read()/write() that read/write exactly the
requested number of bytes. */ requested number of bytes. */