about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-02-04T16·49+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-02-04T16·49+0000
commit9d25466b34a5f7c1c8b1c273976cf59c33961a6c (patch)
treeee4a5a60ae5de90fb301d75258ea627300065b2a /src/libexpr/eval.cc
parent6d46e647ba16e19100dcd0abda9ca5a81ccf764f (diff)
* An attribute set update operator (//). E.g.,
  {x=1; y=2; z=3;} // {y=4;}  =>  {x=1; y=4; z=3;}

Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 802b83aa160d..eaa4b4ea444c 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -134,6 +134,18 @@ ATerm expandRec(ATerm e, ATermList rbnds, ATermList nrbnds)
 }
 
 
+static Expr updateAttrs(Expr e1, Expr e2)
+{
+    /* Note: e1 and e2 should be in normal form. */
+
+    ATermMap attrs;
+    queryAllAttrs(e1, attrs);
+    queryAllAttrs(e2, attrs);
+
+    return makeAttrs(attrs);
+}
+
+
 string evalString(EvalState & state, Expr e)
 {
     e = evalExpr(state, e);
@@ -264,6 +276,10 @@ Expr evalExpr2(EvalState & state, Expr e)
     if (atMatch(m, e) >> "OpOr" >> e1 >> e2)
         return makeBool(evalBool(state, e1) || evalBool(state, e2));
 
+    /* Attribut set update (//). */
+    if (atMatch(m, e) >> "OpUpdate" >> e1 >> e2)
+        return updateAttrs(evalExpr(state, e1), evalExpr(state, e2));
+
     /* Barf. */
     throw badTerm("invalid expression", e);
 }