forked from lix-project/lix
* listToAttrs: the list now should consist of {name, value} attribute
sets instead of {attr, value}. "name" is better than "attr" because the *combination* of the two forms the attribute.
This commit is contained in:
parent
8a9fe6c11c
commit
27a0662828
|
@ -755,15 +755,14 @@ static Expr prim_hasAttr(EvalState & state, const ATermVector & args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* takes
|
/* Builds an attribute set from a list specifying (name, value)
|
||||||
* param: list of { attr="attr"; value=value }
|
pairs. To be precise, a list [{name = "name1"; value = value1;}
|
||||||
* returns an attribute set
|
... {name = "nameN"; value = valueN;}] is transformed to {name1 =
|
||||||
* */
|
value1; ... nameN = valueN;}. */
|
||||||
static Expr prim_listToAttrs(EvalState & state, const ATermVector & args)
|
static Expr prim_listToAttrs(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ATermMap res = ATermMap();
|
ATermMap res = ATermMap();
|
||||||
|
|
||||||
ATermList list;
|
ATermList list;
|
||||||
list = evalList(state, args[0]);
|
list = evalList(state, args[0]);
|
||||||
for (ATermIterator i(list); i; ++i){
|
for (ATermIterator i(list); i; ++i){
|
||||||
|
@ -771,16 +770,18 @@ static Expr prim_listToAttrs(EvalState & state, const ATermVector & args)
|
||||||
ATermList attrs;
|
ATermList attrs;
|
||||||
Expr evaledExpr = evalExpr(state, *i);
|
Expr evaledExpr = evalExpr(state, *i);
|
||||||
if (matchAttrs(evaledExpr, attrs)){
|
if (matchAttrs(evaledExpr, attrs)){
|
||||||
Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("attr")));
|
Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("name")));
|
||||||
string attr = evalStringNoCtx(state,e);
|
string attr = evalStringNoCtx(state,e);
|
||||||
Expr r = makeSelect(evaledExpr, toATerm("value"));
|
Expr r = makeSelect(evaledExpr, toATerm("value"));
|
||||||
res.set(toATerm(attr), makeAttrRHS(r, makeNoPos()));
|
res.set(toATerm(attr), makeAttrRHS(r, makeNoPos()));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
throw EvalError(format("passed list item is a %s (value: %s). Set { attr=\"name\"; value=nix expr; } expected.") % showType(evaledExpr) % showValue(evaledExpr));
|
throw TypeError(format("list element in `listToAttrs' is %s, expected a set { name = \"<name>\"; value = <value>; }")
|
||||||
|
% showType(evaledExpr));
|
||||||
}
|
}
|
||||||
} // for
|
|
||||||
return makeAttrs(res);
|
return makeAttrs(res);
|
||||||
|
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addPrefix(format("in `listToAttrs':\n"));
|
e.addPrefix(format("in `listToAttrs':\n"));
|
||||||
throw;
|
throw;
|
||||||
|
|
Loading…
Reference in a new issue