From 37d7abd69402f0e7a78d4d2f2d78996409a8563a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 25 Oct 2004 16:54:56 +0000 Subject: * New language feature: with expressions. The expression `with E1; E2' evaluates to E2 with all bindings in the attribute set E1 substituted. E.g., with {x = 123;}; x evaluates to 123. That is, the attribute set E1 is in scope in E2. This is particularly useful when importing files containing lots definitions. E.g., instead of let { inherit (import ./foo.nix) a b c d e f; body = ... a ... f ...; } we can now say with import ./foo.nix; ... a ... f ... I.e., we don't have to say what variables should be brought into scope. --- src/libexpr/parser.y | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/libexpr/parser.y') diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 347516f69239..88ee8326b8d3 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -41,11 +41,11 @@ ATerm makePos(YYLTYPE * loc, void * data) ATermList ts; } -%type start expr expr_function expr_assert expr_if expr_op +%type start expr expr_function expr_if expr_op %type expr_app expr_select expr_simple bind inheritsrc formal %type binds ids expr_list formals %token ID INT STR PATH URI -%token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL +%token IF THEN ELSE ASSERT WITH LET REC INHERIT EQ NEQ AND OR IMPL %nonassoc IMPL %left OR @@ -67,12 +67,10 @@ expr_function { $$ = ATmake("Function(, , )", $2, $5, CUR_POS); } | ID ':' expr_function { $$ = ATmake("Function1(, , )", $1, $3, CUR_POS); } - | expr_assert - ; - -expr_assert - : ASSERT expr ';' expr_assert + | ASSERT expr ';' expr_function { $$ = ATmake("Assert(, , )", $2, $4, CUR_POS); } + | WITH expr ';' expr_function + { $$ = ATmake("With(, , )", $2, $4, CUR_POS); } | expr_if ; -- cgit 1.4.1