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-07-28T14·01+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-07-28T14·01+0000
commitc11839d7b24993f9639d59f9fa3420e8ccc22e02 (patch)
tree624ef0a1ceb8fc9946da438e4899a5cfe1f3c818 /src/libexpr/nixexpr.cc
parentca2238cf818e27ebb663c83a9fe9ae7f58eb830f (diff)
* `nix-instantiate --print-args': print out the valid values for
  functions arguments that have a domain.

Diffstat (limited to 'src/libexpr/nixexpr.cc')
-rw-r--r--src/libexpr/nixexpr.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 56b23cc62211..06ca8c928ea3 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -308,3 +308,27 @@ string showType(Expr e)
     return "an unknown type";
 }
 
+
+string showValue(Expr e)
+{
+    ATerm s;
+    int i;
+    if (matchStr(e, s)) {
+        string t = aterm2String(s), u;
+        for (string::iterator i = t.begin(); i != t.end(); ++i)
+            if (*i == '\"' || *i == '\\') u += "\\" + *i;
+            else if (*i == '\n') u += "\\n";
+            else if (*i == '\r') u += "\\r";
+            else if (*i == '\t') u += "\\t";
+            else u += *i;
+        return "\"" + u + "\"";
+    }
+    if (matchPath(e, s)) return aterm2String(s);
+    if (matchUri(e, s)) return aterm2String(s);
+    if (matchNull(e)) return "null";
+    if (matchInt(e, i)) return (format("%1%") % i).str();
+    if (e == eTrue) return "true";
+    if (e == eFalse) return "false";
+    /* !!! incomplete */
+    return "<unknown>";
+}