about summary refs log tree commit diff
path: root/src/libexpr/nixexpr.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-10-16T15·55+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-10-16T15·55+0000
commitd7efd7639420f4c840cbfdfcbbb3c45292f3ac54 (patch)
treed48871893e6d3446b6298b0e5e612086233e3947 /src/libexpr/nixexpr.cc
parent4c9aa821b985b8e334790a03497a56af3a021f3b (diff)
* Big cleanup of the semantics of paths, strings, contexts, string
  concatenation and string coercion.  This was a big mess (see
  e.g. NIX-67).  Contexts are now folded into strings, so that they
  don't cause evaluation errors when they're not expected.  The
  semantics of paths has been clarified (see nixexpr-ast.def).
  toString() and coerceToString() have been merged.

  Semantic change: paths are now copied to the store when they're in a
  concatenation (and in most other situations - that's the
  formalisation of the meaning of a path).  So

    "foo " + ./bla

  evaluates to "foo /nix/store/hash...-bla", not "foo
  /path/to/current-dir/bla".  This prevents accidental impurities, and
  is more consistent with the treatment of derivation outputs, e.g.,
  `"foo " + bla' where `bla' is a derivation.  (Here `bla' would be
  replaced by the output path of `bla'.)

Diffstat (limited to 'src/libexpr/nixexpr.cc')
-rw-r--r--src/libexpr/nixexpr.cc37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index a36b45bc1567..cb006d147e52 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -293,13 +293,35 @@ Expr makeBool(bool b)
 }
 
 
+bool matchStr(Expr e, string & s, PathSet & context)
+{
+    ATermList l;
+    ATerm s_;
+
+    if (!matchStr(e, s_, l)) return false;
+
+    s = aterm2String(s_);
+
+    for (ATermIterator i(l); i; ++i)
+        context.insert(aterm2String(*i));
+
+    return true;
+}
+
+
+Expr makeStr(const string & s, const PathSet & context)
+{
+    return makeStr(toATerm(s), toATermList(context));
+}
+
+
 string showType(Expr e)
 {
     ATerm t1, t2, t3;
     ATermList l1;
     ATermBlob b1;
     int i1;
-    if (matchStr(e, t1)) return "a string";
+    if (matchStr(e, t1, l1)) return "a string";
     if (matchPath(e, t1)) return "a path";
     if (matchNull(e)) return "null";
     if (matchInt(e, i1)) return "an integer";
@@ -309,18 +331,19 @@ string showType(Expr e)
     if (matchAttrs(e, l1)) return "an attribute set";
     if (matchList(e, l1)) return "a list";
     if (matchPrimOp(e, i1, b1, l1)) return "a partially applied built-in function";
-    if (matchContext(e, l1, t1)) return "a context containing " + showType(t1);
     return "an unknown type";
 }
 
 
 string showValue(Expr e)
 {
-    ATerm s;
+    PathSet context;
+    string s;
+    ATerm s2;
     int i;
-    if (matchStr(e, s)) {
-        string t = aterm2String(s), u;
-        for (string::iterator i = t.begin(); i != t.end(); ++i)
+    if (matchStr(e, s, context)) {
+        string u;
+        for (string::iterator i = s.begin(); i != s.end(); ++i)
             if (*i == '\"' || *i == '\\') u += "\\" + *i;
             else if (*i == '\n') u += "\\n";
             else if (*i == '\r') u += "\\r";
@@ -328,7 +351,7 @@ string showValue(Expr e)
             else u += *i;
         return "\"" + u + "\"";
     }
-    if (matchPath(e, s)) return aterm2String(s);
+    if (matchPath(e, s2)) return aterm2String(s2);
     if (matchNull(e)) return "null";
     if (matchInt(e, i)) return (format("%1%") % i).str();
     if (e == eTrue) return "true";