Add a command :t for showing the type of an expression
This commit is contained in:
parent
287c88ca59
commit
3202206d1d
1 changed files with 17 additions and 4 deletions
21
nix-repl.cc
21
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;
|
||||
|
|
Loading…
Reference in a new issue