From f9913f4422d1317af3c6b5aff37ad18b78083eb5 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 6 Jan 2014 10:27:26 -0500 Subject: [PATCH] Allow "bare" dynamic attrs Now, in addition to a."${b}".c, you can write a.${b}.c (applicable wherever dynamic attributes are valid). Signed-off-by: Shea Levy --- src/libexpr/lexer.l | 2 ++ src/libexpr/parser.y | 1 + tests/lang/eval-okay-dynamic-attrs-bare.exp | 1 + tests/lang/eval-okay-dynamic-attrs-bare.nix | 17 +++++++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 tests/lang/eval-okay-dynamic-attrs-bare.exp create mode 100644 tests/lang/eval-okay-dynamic-attrs-bare.nix diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 5d0360401..911850cc5 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -117,6 +117,8 @@ or { return OR_KW; } return INT; } +\$\{ { return DOLLAR_CURLY; } + \" { BEGIN(STRING); return '"'; } ([^\$\"\\]|\$[^\{\"]|\\.)+ { /* !!! Not quite right: we want a follow restriction on diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 28972cf72..230584388 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -509,6 +509,7 @@ attr string_attr : '"' string_parts '"' { $$ = $2; } + | DOLLAR_CURLY expr '}' { $$ = $2; } ; expr_list diff --git a/tests/lang/eval-okay-dynamic-attrs-bare.exp b/tests/lang/eval-okay-dynamic-attrs-bare.exp new file mode 100644 index 000000000..df8750afc --- /dev/null +++ b/tests/lang/eval-okay-dynamic-attrs-bare.exp @@ -0,0 +1 @@ +{ binds = true; hasAttrs = true; multiAttrs = true; recBinds = true; selectAttrs = true; selectOrAttrs = true; } diff --git a/tests/lang/eval-okay-dynamic-attrs-bare.nix b/tests/lang/eval-okay-dynamic-attrs-bare.nix new file mode 100644 index 000000000..0dbe15e63 --- /dev/null +++ b/tests/lang/eval-okay-dynamic-attrs-bare.nix @@ -0,0 +1,17 @@ +let + aString = "a"; + + bString = "b"; +in { + hasAttrs = { a.b = null; } ? ${aString}.b; + + selectAttrs = { a.b = true; }.a.${bString}; + + selectOrAttrs = { }.${aString} or true; + + binds = { ${aString}."${bString}c" = true; }.a.bc; + + recBinds = rec { ${bString} = a; a = true; }.b; + + multiAttrs = { ${aString} = true; ${bString} = false; }.a; +}