about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 89cc8254d2ee..215692aeb313 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -230,7 +230,7 @@ Expr evalExpr2(EvalState & state, Expr e)
             try {
                 return evalExpr(state, substArgs(e4, formals, e2));
             } catch (Error & e) {
-                throw Error(format("while evaluating function at %1%:\n%2%")
+                throw Error(format("while evaluating the function at %1%:\n%2%")
                     % showPos(pos) % e.msg());
             }
         }
@@ -241,7 +241,7 @@ Expr evalExpr2(EvalState & state, Expr e)
                 subs.set(name, e2);
                 return evalExpr(state, substitute(subs, e4));
             } catch (Error & e) {
-                throw Error(format("while evaluating function at %1%:\n%2%")
+                throw Error(format("while evaluating the function at %1%:\n%2%")
                     % showPos(pos) % e.msg());
             }
         }
@@ -258,7 +258,7 @@ Expr evalExpr2(EvalState & state, Expr e)
         try {
             return evalExpr(state, a);
         } catch (Error & e) {
-            throw Error(format("while evaluating attribute `%1%' at %2%:\n%3%")
+            throw Error(format("while evaluating the attribute `%1%' at %2%:\n%3%")
                 % s1 % showPos(pos) % e.msg());
         }
     }
@@ -283,6 +283,26 @@ Expr evalExpr2(EvalState & state, Expr e)
         return evalExpr(state, e2);
     }
 
+    /* Withs. */
+    if (atMatch(m, e) >> "With" >> e1 >> e2 >> pos) {
+        ATermMap attrs;
+        try {
+            e1 = evalExpr(state, e1);
+            queryAllAttrs(e1, attrs);
+        } catch (Error & e) {
+            throw Error(format("while evaluating the `with' definitions at %1%:\n%2%")
+                % showPos(pos) % e.msg());
+        }
+        try {
+            e2 = substitute(attrs, e2);
+            checkVarDefs(state.primOps, e2);
+            return evalExpr(state, e2);
+        } catch (Error & e) {
+            throw Error(format("while evaluating the `with' body at %1%:\n%2%")
+                % showPos(pos) % e.msg());
+        } 
+    }
+
     /* Generic equality. */
     if (atMatch(m, e) >> "OpEq" >> e1 >> e2)
         return makeBool(evalExpr(state, e1) == evalExpr(state, e2));
@@ -357,7 +377,7 @@ Expr evalFile(EvalState & state, const Path & path)
     try {
         return evalExpr(state, e);
     } catch (Error & e) {
-        throw Error(format("while evaluating file `%1%':\n%2%")
+        throw Error(format("while evaluating the file `%1%':\n%2%")
             % path % e.msg());
     }
 }