about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-08-29T15·29+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-08-29T15·29+0000
commit2132d9ddeba14ea2ddcbb16fa51ddb16c45c3c6a (patch)
treed77c3bd42f0a13c9fc78e58e6558c5deab8d99d2
parent1f6616dabff48028b2b08fc50889707928201ea6 (diff)
* Fix the ~ operator.
-rw-r--r--src/libexpr/eval.cc14
-rw-r--r--src/libexpr/primops.cc2
-rw-r--r--src/libutil/util.cc9
-rw-r--r--src/libutil/util.hh2
4 files changed, 24 insertions, 3 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 6b53f60a854f..90edbecb50cd 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -321,7 +321,6 @@ Expr evalExpr2(EvalState & state, Expr e)
     /* Normal forms. */
     if (sym == symStr ||
         sym == symPath ||
-        sym == symSubPath || /* !!! evaluate */
         sym == symUri ||
         sym == symNull ||
         sym == symInt ||
@@ -503,7 +502,7 @@ Expr evalExpr2(EvalState & state, Expr e)
     }
 
     /* String or path concatenation. */
-    ATermList es;
+    ATermList es = ATempty;
     if (matchOpPlus(e, e1, e2) || matchConcatStrings(e, es)) {
         ATermVector args;
         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. */
     if (matchOpConcat(e, e1, e2)) {
         try {
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 5496e945e31b..65e993708a34 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -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));
     
 }
 
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 02745498f9fc..54cfc6c7fded 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -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)
 {
     while (count) {
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 22e614d9585e..125ba2695c2c 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -178,6 +178,8 @@ void printMsg_(Verbosity level, const format & f);
 
 #define debug(f) printMsg(lvlDebug, f)
 
+void warnOnce(bool & haveWarned, const format & f);
+
 
 /* Wrappers arount read()/write() that read/write exactly the
    requested number of bytes. */