* 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; ATermList * is = recursive ? &cs : &bs;
for (ATermIterator i(as); i; ++i) { for (ATermIterator i(as); i; ++i) {
ATermList names; ATermList names;
if (atMatch(m, *i) >> "Inherit" >> names) Expr src;
for (ATermIterator j(names); j; ++j) if (atMatch(m, *i) >> "Inherit" >> src >> names) {
*is = ATinsert(*is, bool fromScope = atMatch(m, src) >> "Scope";
ATmake("Bind(<term>, Var(<term>))", *j, *j)); for (ATermIterator j(names); j; ++j) {
else bs = ATinsert(bs, *i); 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) if (recursive)
return ATmake("Rec(<term>, <term>)", bs, cs); 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> 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 %type <ts> binds ids expr_list formals
%token <t> ID INT STR PATH URI %token <t> ID INT STR PATH URI
%token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL %token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL
@ -114,8 +114,13 @@ binds
bind bind
: ID '=' expr ';' : ID '=' expr ';'
{ $$ = ATmake("Bind(<term>, <term>)", $1, $3); } { $$ = ATmake("Bind(<term>, <term>)", $1, $3); }
| INHERIT ids ';' | INHERIT inheritsrc ids ';'
{ $$ = ATmake("Inherit(<term>)", $2); } { $$ = ATmake("Inherit(<term>, <term>)", $2, $3); }
;
inheritsrc
: '(' expr ')' { $$ = $2; }
| { $$ = ATmake("Scope"); }
; ;
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; }; ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };