mirror of
https://github.com/NixOS/nix
synced 2025-06-29 02:11:15 +02:00
* Added syntactic sugar to the construction of attribute sets to
`inherit' variables from the surrounding lexical scope. E.g., {stdenv, libfoo}: derivation { builder = ./bla; inherit stdenv libfoo; xyzzy = 1; } is equivalent to {stdenv, libfoo}: derivation { builder = ./bla; stdenv = stdenv; libfoo = libfoo; xyzzy = 1; } Note that for mutually recursive attribute set definitions (`rec {...}'), this also works, that is, `rec {inherit x;}' is equivalent to `let {fresh = x; body = rec {x = fresh;};}', *not* `rec {x = x}'.
This commit is contained in:
parent
d9f30fe7c7
commit
1c9c0a5a46
6 changed files with 78 additions and 41 deletions
|
@ -18,6 +18,7 @@
|
|||
void setParseResult(void * data, ATerm t);
|
||||
void parseError(void * data, char * error, int line, int column);
|
||||
ATerm absParsedPath(void * data, ATerm t);
|
||||
ATerm fixAttrs(int recursive, ATermList as);
|
||||
|
||||
void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
|
||||
{
|
||||
|
@ -33,9 +34,9 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
|
|||
|
||||
%type <t> start expr expr_function expr_assert expr_op
|
||||
%type <t> expr_app expr_select expr_simple bind formal
|
||||
%type <ts> binds expr_list formals
|
||||
%type <ts> binds ids expr_list formals
|
||||
%token <t> ID INT STR PATH URI
|
||||
%token IF THEN ELSE ASSERT LET REC EQ NEQ AND OR IMPL
|
||||
%token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL
|
||||
|
||||
%nonassoc IMPL
|
||||
%left OR
|
||||
|
@ -90,9 +91,14 @@ expr_simple
|
|||
| PATH { $$ = ATmake("Path(<term>)", absParsedPath(data, $1)); }
|
||||
| URI { $$ = ATmake("Uri(<term>)", $1); }
|
||||
| '(' expr ')' { $$ = $2; }
|
||||
| LET '{' binds '}' { $$ = ATmake("LetRec(<term>)", $3); }
|
||||
| REC '{' binds '}' { $$ = ATmake("Rec(<term>)", $3); }
|
||||
| '{' binds '}' { $$ = ATmake("Attrs(<term>)", $2); }
|
||||
/* Let expressions `let {..., body = ...}' are just desugared
|
||||
into `(rec {..., body = ...}).body'. */
|
||||
| LET '{' binds '}'
|
||||
{ $$ = ATmake("Select(<term>, \"body\")", fixAttrs(1, $3)); }
|
||||
| REC '{' binds '}'
|
||||
{ $$ = fixAttrs(1, $3); }
|
||||
| '{' binds '}'
|
||||
{ $$ = fixAttrs(0, $2); }
|
||||
| '[' expr_list ']' { $$ = ATmake("List(<term>)", $2); }
|
||||
| IF expr THEN expr ELSE expr
|
||||
{ $$ = ATmake("If(<term>, <term>, <term>)", $2, $4, $6); }
|
||||
|
@ -106,8 +112,12 @@ binds
|
|||
bind
|
||||
: ID '=' expr ';'
|
||||
{ $$ = ATmake("Bind(<term>, <term>)", $1, $3); }
|
||||
| INHERIT ids ';'
|
||||
{ $$ = ATmake("Inherit(<term>)", $2); }
|
||||
;
|
||||
|
||||
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };
|
||||
|
||||
expr_list
|
||||
: expr_select expr_list { $$ = ATinsert($2, $1); }
|
||||
/* yes, this is right-recursive, but it doesn't matter since
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue