about summary refs log tree commit diff
path: root/nix-repl.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-02T16·00+0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-02T16·00+0000
commit3202206d1d906ea6279dadfe608ea92ea0aaf927 (patch)
tree328592f7400e7affba7860ba062c6eec2e044830 /nix-repl.cc
parent287c88ca59c5eae2b33874acc6271ca30b7b7e52 (diff)
Add a command :t for showing the type of an expression
Diffstat (limited to 'nix-repl.cc')
-rw-r--r--nix-repl.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/nix-repl.cc b/nix-repl.cc
index 10e91ec5328e..9858a034d728 100644
--- a/nix-repl.cc
+++ b/nix-repl.cc
@@ -30,6 +30,7 @@ struct NixRepl
     void processLine(string line);
     void addVar(const Symbol & name, Value * v);
     Expr * parseString(string s);
+    void evalString(string s, Value & v);
 };
 
 
@@ -91,22 +92,26 @@ void NixRepl::mainLoop()
 void NixRepl::processLine(string line)
 {
     if (string(line, 0, 2) == ":a") {
-        Expr * e = parseString(string(line, 2));
         Value v;
-        e->eval(state, *env, v);
+        evalString(string(line, 2), v);
         state.forceAttrs(v);
         foreach (Bindings::iterator, i, *v.attrs)
             addVar(i->name, i->value);
     }
 
+    else if (string(line, 0, 2) == ":t") {
+        Value v;
+        evalString(string(line, 2), v);
+        std::cout << showType(v) << std::endl;
+    }
+
     else if (string(line, 0, 1) == ":") {
         throw Error(format("unknown command ‘%1%’") % string(line, 0, 2));
     }
 
     else {
-        Expr * e = parseString(line);
         Value v;
-        e->eval(state, *env, v);
+        evalString(line, v);
         state.strictForceValue(v);
         std::cout << v << std::endl;
     }
@@ -127,6 +132,14 @@ Expr * NixRepl::parseString(string s)
 }
 
 
+void NixRepl::evalString(string s, Value & v)
+{
+    Expr * e = parseString(s);
+    e->eval(state, *env, v);
+    state.forceValue(v);
+}
+
+
 void run(nix::Strings args)
 {
     NixRepl repl;