From 3202206d1d906ea6279dadfe608ea92ea0aaf927 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 2 Sep 2013 16:00:48 +0000 Subject: [PATCH] Add a command :t for showing the type of an expression --- nix-repl.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/nix-repl.cc b/nix-repl.cc index 10e91ec53..9858a034d 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;