lix/tests/lang
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
..
dir1 * Add a Nix expression search path feature. Paths between angle 2011-08-06 16:05:24 +00:00
dir2 * Add a Nix expression search path feature. Paths between angle 2011-08-06 16:05:24 +00:00
dir3 * Add a Nix expression search path feature. Paths between angle 2011-08-06 16:05:24 +00:00
dir4 * Add a Nix expression search path feature. Paths between angle 2011-08-06 16:05:24 +00:00
eval-fail-abort.nix
eval-fail-antiquoted-path.nix Add a regression test for correct path antiquotation behavior 2013-10-16 23:29:11 +02:00
eval-fail-assert.nix
eval-fail-bad-antiquote-1.nix Add a test for type correctness of antiquotes 2013-10-17 00:51:07 +02:00
eval-fail-bad-antiquote-2.nix Add a test for type correctness of antiquotes 2013-10-17 00:51:07 +02:00
eval-fail-bad-antiquote-3.nix Add a test for type correctness of antiquotes 2013-10-17 00:51:07 +02:00
eval-fail-blackhole.nix
eval-fail-missing-arg.nix
eval-fail-remove.nix
eval-fail-scope-5.nix
eval-fail-substring.nix
eval-fail-to-path.nix
eval-fail-undeclared-arg.nix
eval-okay-arithmetic.exp Let the ordering operators also work on strings 2013-08-02 18:53:02 +02:00
eval-okay-arithmetic.nix Let the ordering operators also work on strings 2013-08-02 18:53:02 +02:00
eval-okay-attrnames.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-attrnames.nix
eval-okay-attrs.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-attrs.nix
eval-okay-attrs2.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-attrs2.nix
eval-okay-attrs3.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-attrs3.nix
eval-okay-attrs4.exp * Test case. 2011-07-06 10:58:53 +00:00
eval-okay-attrs4.nix * Test case. 2011-07-06 10:58:53 +00:00
eval-okay-attrs5.exp * Allow a default value in attribute selection by writing 2011-07-13 12:19:57 +00:00
eval-okay-attrs5.nix Allow dashes in identifiers 2012-09-27 15:49:20 -04:00
eval-okay-autoargs.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-autoargs.flags
eval-okay-autoargs.nix Fix typos, especially those that end up in the Nix manual 2013-08-26 11:15:22 +02:00
eval-okay-builtins.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-builtins.nix
eval-okay-closure.exp.xml
eval-okay-closure.nix
eval-okay-concat.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-concat.nix
eval-okay-context.exp * Check for duplicate attribute names / function arguments. `make 2010-04-22 11:02:24 +00:00
eval-okay-context.nix
eval-okay-curpos.exp Add a symbol __curPos that expands to the current source location 2013-11-18 20:16:02 +01:00
eval-okay-curpos.nix Add a symbol __curPos that expands to the current source location 2013-11-18 20:16:02 +01:00
eval-okay-delayed-with-inherit.exp Simplify inherited attribute handling 2013-08-26 11:31:56 +02:00
eval-okay-delayed-with-inherit.nix Simplify inherited attribute handling 2013-08-26 11:31:56 +02:00
eval-okay-delayed-with.exp Test the delayed with a bit more 2013-07-31 13:12:35 +02:00
eval-okay-delayed-with.nix Test the delayed with a bit more 2013-07-31 13:12:35 +02:00
eval-okay-dynamic-attrs.exp Dynamic attrs 2013-12-31 20:59:49 +00:00
eval-okay-dynamic-attrs.nix Dynamic attrs 2013-12-31 20:59:49 +00:00
eval-okay-empty-args.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-empty-args.nix
eval-okay-eq-derivations.exp * Add a test case for comparing derivations. 2012-01-19 22:10:24 +00:00
eval-okay-eq-derivations.nix * Add a test case for comparing derivations. 2012-01-19 22:10:24 +00:00
eval-okay-eq.exp.disabled
eval-okay-eq.nix
eval-okay-flatten.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-flatten.nix
eval-okay-functionargs.exp.xml * Two primops: builtins.intersectAttrs and builtins.functionArgs. 2009-09-15 13:01:46 +00:00
eval-okay-functionargs.nix * Two primops: builtins.intersectAttrs and builtins.functionArgs. 2009-09-15 13:01:46 +00:00
eval-okay-getattrpos.exp Add a primop unsafeGetAttrPos to return the position of an attribute 2013-11-18 22:22:35 +01:00
eval-okay-getattrpos.nix Add a primop unsafeGetAttrPos to return the position of an attribute 2013-11-18 22:22:35 +01:00
eval-okay-getenv.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-getenv.nix
eval-okay-hash.exp Rename "hash" to "hashString" and handle SHA-1 2013-02-08 19:36:23 +01:00
eval-okay-hash.nix Rename "hash" to "hashString" and handle SHA-1 2013-02-08 19:36:23 +01:00
eval-okay-if.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-if.nix
eval-okay-ind-string.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-ind-string.nix
eval-okay-let.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-let.nix
eval-okay-list.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-list.nix
eval-okay-listtoattrs.exp * Regression test for listToAttr's behaviour if an attribute name 2010-10-23 22:55:30 +00:00
eval-okay-listtoattrs.nix * Keep attribute sets in sorted order to speed up attribute lookups. 2010-10-24 19:52:33 +00:00
eval-okay-logic.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-logic.nix
eval-okay-map.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-map.nix
eval-okay-new-let.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-new-let.nix
eval-okay-overrides.exp * Regression test for __overrides. 2010-10-22 15:15:12 +00:00
eval-okay-overrides.nix * Regression test for __overrides. 2010-10-22 15:15:12 +00:00
eval-okay-pathexists.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-pathexists.nix
eval-okay-patterns.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-patterns.nix * Simplify @-patterns: only {attrs}@name' or name@{attrs}' are now 2010-03-25 12:19:41 +00:00
eval-okay-readfile.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-readfile.nix
eval-okay-redefine-builtin.exp Add the ExprBuiltin Expr type to the AST 2013-12-31 17:45:47 +00:00
eval-okay-redefine-builtin.nix Add the ExprBuiltin Expr type to the AST 2013-12-31 17:45:47 +00:00
eval-okay-remove.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-remove.nix
eval-okay-scope-1.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-scope-1.nix
eval-okay-scope-2.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-scope-2.nix
eval-okay-scope-3.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-scope-3.nix
eval-okay-scope-4.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-scope-4.nix
eval-okay-scope-6.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-scope-6.nix
eval-okay-scope-7.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-scope-7.nix
eval-okay-search-path.exp * Allow redirections in search path entries. E.g. if you have a 2011-08-06 17:48:57 +00:00
eval-okay-search-path.flags * Allow redirections in search path entries. E.g. if you have a 2011-08-06 17:48:57 +00:00
eval-okay-search-path.nix * Refactoring: Get rid of a few subdirectories in corepkgs/, and some 2012-01-03 00:16:29 +00:00
eval-okay-string.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-string.nix
eval-okay-strings-as-attrs-names.exp * Allow attribute names to be strings. Based on the 2011-07-13 15:53:24 +00:00
eval-okay-strings-as-attrs-names.nix * Allow attribute names to be strings. Based on the 2011-07-13 15:53:24 +00:00
eval-okay-substring.exp * builtins.substring: if "start" is beyond the end of the string, 2011-01-14 12:47:10 +00:00
eval-okay-substring.nix * builtins.substring: if "start" is beyond the end of the string, 2011-01-14 12:47:10 +00:00
eval-okay-tail-call-1.exp Add a test to check that tail calls run in bounded stack space 2013-11-12 12:34:22 +01:00
eval-okay-tail-call-1.nix Add a test to check that tail calls run in bounded stack space 2013-11-12 12:34:22 +01:00
eval-okay-tojson.exp Add a toJSON primop 2013-11-19 00:04:11 +01:00
eval-okay-tojson.nix Add a toJSON primop 2013-11-19 00:04:11 +01:00
eval-okay-toxml.exp * Sync with the trunk. 2010-05-07 14:46:47 +00:00
eval-okay-toxml.nix Make source location info in the XML output optional. 2010-03-31 12:38:31 +00:00
eval-okay-toxml2.exp * Sync with the trunk. 2010-05-07 14:46:47 +00:00
eval-okay-toxml2.nix * Sync with the trunk. 2010-05-07 14:46:47 +00:00
eval-okay-tryeval.exp * Print attributes in sorted order. 2010-05-12 12:15:49 +00:00
eval-okay-tryeval.nix * Implemented tryEval, the last missing primop in the fast-eval 2010-05-12 11:23:44 +00:00
eval-okay-types.exp Rename "attribute sets" to "sets" 2013-10-24 16:41:04 +02:00
eval-okay-types.nix Add a test of the type primops 2013-10-24 02:51:28 +02:00
eval-okay-versions.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-versions.nix
eval-okay-with.exp * Update the expected test output (no longer an ATerm). 2010-04-21 16:22:03 +00:00
eval-okay-with.nix * Doh. 2010-03-23 14:51:32 +00:00
eval-okay-xml.exp.xml * Simplify @-patterns: only {attrs}@name' or name@{attrs}' are now 2010-03-25 12:19:41 +00:00
eval-okay-xml.nix
lib.nix Add integer ‘-’, ‘*’ and ‘/’ operators 2013-08-02 16:03:02 +00:00
parse-fail-dup-attrs-1.nix
parse-fail-dup-attrs-2.nix
parse-fail-dup-attrs-3.nix
parse-fail-dup-attrs-4.nix
parse-fail-dup-attrs-6.nix
parse-fail-dup-attrs-7.nix * Check for duplicate attribute names / function arguments. `make 2010-04-22 11:02:24 +00:00
parse-fail-dup-formals.nix
parse-fail-patterns-1.nix
parse-fail-regression-20060610.nix
parse-fail-undef-var-2.nix
parse-fail-undef-var.nix
parse-okay-1.nix
parse-okay-crlf.nix
parse-okay-dup-attrs-5.nix * Check for duplicate attribute names / function arguments. `make 2010-04-22 11:02:24 +00:00
parse-okay-regression-20041027.nix
parse-okay-subversion.nix
parse-okay-url.nix