* Extended the `inherit' syntax to optionally select attributes from

other attribute sets, rather than the current scope.  E.g.,
  
    {inherit (pkgs) gcc binutils;}

  is equivalent to

    {gcc = pkgs.gcc; binutils = pkgs.binutils;}

  I am not so happy about the syntax.
This commit is contained in:
Eelco Dolstra 2004-02-04 17:23:26 +00:00
parent 9d25466b34
commit d445da7a7b
2 changed files with 18 additions and 8 deletions

View File

@ -50,11 +50,16 @@ ATerm fixAttrs(int recursive, ATermList as)
ATermList * is = recursive ? &cs : &bs;
for (ATermIterator i(as); i; ++i) {
ATermList names;
if (atMatch(m, *i) >> "Inherit" >> names)
for (ATermIterator j(names); j; ++j)
*is = ATinsert(*is,
ATmake("Bind(<term>, Var(<term>))", *j, *j));
else bs = ATinsert(bs, *i);
Expr src;
if (atMatch(m, *i) >> "Inherit" >> src >> names) {
bool fromScope = atMatch(m, src) >> "Scope";
for (ATermIterator j(names); j; ++j) {
Expr rhs = fromScope
? ATmake("Var(<term>)", *j)
: ATmake("Select(<term>, <term>)", src, *j);
*is = ATinsert(*is, ATmake("Bind(<term>, <term>)", *j, rhs));
}
} else bs = ATinsert(bs, *i);
}
if (recursive)
return ATmake("Rec(<term>, <term>)", bs, cs);

View File

@ -33,7 +33,7 @@ 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 <t> expr_app expr_select expr_simple bind inheritsrc formal
%type <ts> binds ids expr_list formals
%token <t> ID INT STR PATH URI
%token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL
@ -114,8 +114,13 @@ binds
bind
: ID '=' expr ';'
{ $$ = ATmake("Bind(<term>, <term>)", $1, $3); }
| INHERIT ids ';'
{ $$ = ATmake("Inherit(<term>)", $2); }
| INHERIT inheritsrc ids ';'
{ $$ = ATmake("Inherit(<term>, <term>)", $2, $3); }
;
inheritsrc
: '(' expr ')' { $$ = $2; }
| { $$ = ATmake("Scope"); }
;
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };