Add haskell's $ operator to the nix language

This commit is contained in:
Mewp 2021-11-16 21:58:54 +01:00
parent 9a9afca712
commit 91e1b2e75c
4 changed files with 18 additions and 0 deletions

View file

@ -309,6 +309,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
%token IND_STRING_OPEN IND_STRING_CLOSE
%token ELLIPSIS
%right '$'
%right IMPL
%left OR
%left AND
@ -377,6 +378,7 @@ expr_op
| expr_op '*' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__mul")), {$1, $3}); }
| expr_op '/' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__div")), {$1, $3}); }
| expr_op CONCAT expr_op { $$ = new ExprOpConcatLists(CUR_POS, $1, $3); }
| expr_op '$' expr_op { $$ = new ExprCall(CUR_POS, $1, {$3}); }
| expr_app { $$ = $1.e; }
;

View file

@ -0,0 +1,6 @@
let
a = 5;
b = 1;
add = a: b: a + b;
in add a $ a $ b

View file

@ -0,0 +1 @@
18

View file

@ -0,0 +1,9 @@
let
a = 5;
b = 1;
c = 2;
concat = a: b: "${a}${b}";
nested.attr.ab = 10;
add = a: b: a + b;
in add nested.attr.${concat "a" "b"} $ add b $ add a c