Skip to content

Commit

Permalink
Allow dashes in identifiers
Browse files Browse the repository at this point in the history
In Nixpkgs, the attribute in all-packages.nix corresponding to a
package is usually equal to the package name.  However, this doesn't
work if the package contains a dash, which is fairly common.  The
convention is to replace the dash with an underscore (e.g. "dbus-lib"
becomes "dbus_glib"), but that's annoying.  So now dashes are valid in
variable / attribute names, allowing you to write:

  dbus-glib = callPackage ../development/libraries/dbus-glib { };

and

  buildInputs = [ dbus-glib ];

Since we don't have a negation or subtraction operation in Nix, this
is unambiguous.
  • Loading branch information
edolstra committed Sep 27, 2012
1 parent f46612b commit 95c74ea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions doc/manual/release-notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

<itemizedlist>

<listitem>
<para>Dashes are now valid as part of identifiers and attribute
names.</para>
</listitem>

<listitem>
<para>Nix no longer sets the immutable bit on files in the Nix
store. Instead, the recommended way to guard the Nix store
Expand Down
2 changes: 1 addition & 1 deletion misc/emacs/nix-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The hook `nix-mode-hook' is run when Nix mode is started.
("\\<isNull\\>" . font-lock-builtin-face)
("[a-zA-Z][a-zA-Z0-9\\+-\\.]*:[a-zA-Z0-9%/\\?:@&=\\+\\$,_\\.!~\\*'-]+"
. font-lock-constant-face)
("\\<\\([a-zA-Z_][a-zA-Z0-9_'\.]*\\)[ \t]*="
("\\<\\([a-zA-Z_][a-zA-Z0-9_'\-\.]*\\)[ \t]*="
(1 font-lock-variable-name-face nil nil))
("<[a-zA-Z0-9._\\+-]+\\(/[a-zA-Z0-9._\\+-]+\\)*>"
. font-lock-constant-face)
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s)
%}


ID [a-zA-Z\_][a-zA-Z0-9\_\']*
ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
INT [0-9]+
PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\>
Expand Down
4 changes: 2 additions & 2 deletions tests/lang/eval-okay-attrs5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let

as = { x.y.z = 123; a.b.c = 456; };

bs = { foo.bar = "foo"; };
bs = { f-o-o.bar = "foo"; };

or = x: y: x || y;

Expand All @@ -13,7 +13,7 @@ in
as.foo or "foo"
as.x.y.bla or as.a.b.c
as.a.b.c or as.x.y.z
as.x.y.bla or bs.foo.bar or "xyzzy"
as.x.y.bla or bs.f-o-o.bar or "xyzzy"
as.x.y.bla or bs.bar.foo or "xyzzy"
123.bla or null.foo or "xyzzy"
# Backwards compatibility test.
Expand Down

0 comments on commit 95c74ea

Please sign in to comment.