lix/src
Shea Levy 18fefacf7d Dynamic attrs
This adds new syntax for attribute names:

* attrs."${name}" => getAttr name attrs
* attrs ? "${name}" => isAttrs attrs && hasAttr attrs name
* attrs."${name}" or def => if attrs ? "${name}" then attrs."${name}" else def
* { "${name}" = value; } => listToAttrs [{ inherit name value; }]

Of course, it's a bit more complicated than that. The attribute chains
can be arbitrarily long and contain combinations of static and dynamic
parts (e.g. attrs."${foo}".bar."${baz}" or qux), which is relatively
straightforward for the getAttrs/hasAttrs cases but is more complex for
the listToAttrs case due to rules about duplicate attribute definitions.

For attribute sets with dynamic attribute names, duplicate static
attributes are detected at parse time while duplicate dynamic attributes
are detected when the attribute set is forced. So, for example, { a =
null; a.b = null; "${"c"}" = true; } will be a parse-time error, while
{ a = {}; "${"a"}".b = null; c = true; } will be an eval-time error
(technically that case could theoretically be detected at parse time,
but the general case would require full evaluation). Moreover, duplicate
dynamic attributes are not allowed even in cases where they would be
with static attributes ({ a.b.d = true; a.b.c = false; } is legal, but {
a."${"b"}".d = true; a."${"b"}".c = false; } is not). This restriction
might be relaxed in the future in cases where the static variant would
not be an error, but it is not obvious that that is desirable.

Finally, recursive attribute sets with dynamic attributes have the
static attributes in scope but not the dynamic ones. So rec { a = true;
"${"b"}" = a; } is equivalent to { a = true; b = true; } but rec {
"${"a"}" = true; b = a; } would be an error or use a from the
surrounding scope if it exists.

Note that the getAttr, getAttr or default, and hasAttr are all
implemented purely in the parser as syntactic sugar, while attribute
sets with dynamic attribute names required changes to the AST to be
implemented cleanly.

This is an alternative solution to and closes #167

Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 20:59:49 +00:00
..
boost * Install some headers in the right location. 2009-03-05 14:57:50 +00:00
bsdiff-4.3 Drop the externals directory 2012-03-18 23:54:57 +01:00
libexpr Dynamic attrs 2013-12-31 20:59:49 +00:00
libmain nix-shell: Don't warn about the lack of a GC root 2013-12-20 12:19:10 +00:00
libstore Garbage collector: Release locks on temporary root files 2013-12-10 13:13:59 +01:00
libutil Remove nix-setuid-helper 2013-11-14 11:57:37 +01:00
nix-daemon Report OOM errors better 2013-10-02 14:34:36 +02:00
nix-env nix-env --set-flag: Barf if a selector doesn't match any installed package 2013-12-20 13:56:42 +01:00
nix-hash When ‘--help’ is given, just run ‘man’ to show the manual page 2012-10-03 16:40:09 -04:00
nix-instantiate Generalise meta attributes 2013-11-19 14:09:14 +01:00
nix-log2xml * Emit warning='1' or error='1' attributes for lines marked as 2010-03-05 12:54:58 +00:00
nix-store Doh 2013-12-20 13:09:12 +00:00
Makefile.am Remove nix-setuid-helper 2013-11-14 11:57:37 +01:00