mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
* In the ‘?’ operator, allow attribute paths. For instance, you can
write ‘attrs ? a.b’ to test whether ‘attrs’ has an attribute ‘a’ containing an attribute ‘b’. This is more convenient than ‘attrs ? a && attrs.a ? b’. Slight change in the semantics: it's no longer an error if the left-hand side of ‘?’ is not an attribute set. In that case it just returns false. So, ‘null ? foo’ no longer throws an error.
This commit is contained in:
parent
34f4b91820
commit
5637037802
4 changed files with 47 additions and 24 deletions
|
|
@ -48,7 +48,7 @@ void ExprSelect::show(std::ostream & str)
|
|||
|
||||
void ExprOpHasAttr::show(std::ostream & str)
|
||||
{
|
||||
str << "(" << *e << ") ? " << name;
|
||||
str << "(" << *e << ") ? " << showAttrPath(attrPath);
|
||||
}
|
||||
|
||||
void ExprAttrs::show(std::ostream & str)
|
||||
|
|
@ -140,6 +140,17 @@ std::ostream & operator << (std::ostream & str, const Pos & pos)
|
|||
}
|
||||
|
||||
|
||||
string showAttrPath(const AttrPath & attrPath)
|
||||
{
|
||||
string s;
|
||||
foreach (AttrPath::const_iterator, i, attrPath) {
|
||||
if (!s.empty()) s += '.';
|
||||
s += *i;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Pos noPos;
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue