Author: eelco
Date: Wed Jul 13 15:53:24 2011
New Revision: 27763
URL: https://svn.nixos.org/websvn/nix/?rev=27763&sc=1

Log:
* Allow attribute names to be strings.  Based on the
  allow-arbitrary-strinsg-in-names patch by Marc Weber.

Added:
   nix/trunk/tests/lang/eval-okay-strings-as-attrs-names.exp
   nix/trunk/tests/lang/eval-okay-strings-as-attrs-names.nix
Modified:
   nix/trunk/src/libexpr/parser.y

Modified: nix/trunk/src/libexpr/parser.y
==============================================================================
--- nix/trunk/src/libexpr/parser.y      Wed Jul 13 15:00:59 2011        (r27762)
+++ nix/trunk/src/libexpr/parser.y      Wed Jul 13 15:53:24 2011        (r27763)
@@ -411,6 +411,8 @@
 attr
   : ID { $$ = $1; }
   | OR_KW { $$ = "or"; }
+  | '"' STR '"'
+    { $$ = strdup(((string) ((ExprString *) $2)->s).c_str()); delete $2; }
   ;
 
 expr_list

Added: nix/trunk/tests/lang/eval-okay-strings-as-attrs-names.exp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nix/trunk/tests/lang/eval-okay-strings-as-attrs-names.exp   Wed Jul 13 
15:53:24 2011        (r27763)
@@ -0,0 +1 @@
+true

Added: nix/trunk/tests/lang/eval-okay-strings-as-attrs-names.nix
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nix/trunk/tests/lang/eval-okay-strings-as-attrs-names.nix   Wed Jul 13 
15:53:24 2011        (r27763)
@@ -0,0 +1,20 @@
+let
+
+  attr = {
+    "key 1" = "test";
+    "key 2" = "caseok";
+  };
+
+  t1 = builtins.getAttr "key 1" attr;
+  t2 = attr."key 2";
+  t3 = attr ? "key 1";
+  t4 = builtins.attrNames { inherit (attr) "key 1"; };
+
+  # This is permitted, but there is currently no way to reference this
+  # variable.
+  "foo bar" = 1;
+
+in t1 == "test"
+   && t2 == "caseok"
+   && t3 == true
+   && t4 == ["key 1"]
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to