From 56370378023fc84eb0153b991f4138f6acd011e3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Jul 2011 10:58:17 +0000 Subject: * 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’. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/libexpr/nixexpr.hh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/libexpr/nixexpr.hh') diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 8f976f1de8f9..205f579daf3d 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -40,6 +40,12 @@ struct EvalState; struct StaticEnv; +/* An attribute path is a sequence of attribute names. */ +typedef vector AttrPath; + +string showAttrPath(const AttrPath & attrPath); + + /* Abstract syntax of Nix expressions. */ struct Expr @@ -124,8 +130,8 @@ struct ExprSelect : Expr struct ExprOpHasAttr : Expr { Expr * e; - Symbol name; - ExprOpHasAttr(Expr * e, const Symbol & name) : e(e), name(name) { }; + AttrPath attrPath; + ExprOpHasAttr(Expr * e, const AttrPath & attrPath) : e(e), attrPath(attrPath) { }; COMMON_METHODS }; -- cgit 1.4.1