Skip to content

Instantly share code, notes, and snippets.

@cafkafk
Created August 3, 2023 12:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cafkafk/210926e24f4e18d1a0c28b9458b36c1a to your computer and use it in GitHub Desktop.
Add __dollar so you can haskell your nix even more!
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 201370b90..4b26af623 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -353,6 +353,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
%left AND
%nonassoc EQ NEQ
%nonassoc '<' '>' LEQ GEQ
+%nonassoc '$' DOL
%right UPDATE
%left NOT
%left '+' '-'
@@ -411,6 +412,8 @@ expr_op
| expr_op LEQ expr_op { $$ = new ExprOpNot(new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__lessThan")), {$3, $1})); }
| expr_op '>' expr_op { $$ = new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__lessThan")), {$3, $1}); }
| expr_op GEQ expr_op { $$ = new ExprOpNot(new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__lessThan")), {$1, $3})); }
+ | expr_op '$' expr_op { $$ = new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__dollar")), {$1, $3}); }
+ | expr_op DOL expr_op { $$ = new ExprOpNot(new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__dollar")), {$3, $1})); }
| expr_op AND expr_op { $$ = new ExprOpAnd(makeCurPos(@2, data), $1, $3); }
| expr_op OR expr_op { $$ = new ExprOpOr(makeCurPos(@2, data), $1, $3); }
| expr_op IMPL expr_op { $$ = new ExprOpImpl(makeCurPos(@2, data), $1, $3); }
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index ddf529b9e..00622a142 100644
--- a/src/libexpr/primops.cc
...skipping...
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 201370b90..4b26af623 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -353,6 +353,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
%left AND
%nonassoc EQ NEQ
%nonassoc '<' '>' LEQ GEQ
+%nonassoc '$' DOL
%right UPDATE
%left NOT
%left '+' '-'
@@ -411,6 +412,8 @@ expr_op
| expr_op LEQ expr_op { $$ = new ExprOpNot(new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__lessThan")), {$3, $1})); }
| expr_op '>' expr_op { $$ = new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__lessThan")), {$3, $1}); }
| expr_op GEQ expr_op { $$ = new ExprOpNot(new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__lessThan")), {$1, $3})); }
+ | expr_op '$' expr_op { $$ = new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__dollar")), {$1, $3}); }
+ | expr_op DOL expr_op { $$ = new ExprOpNot(new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__dollar")), {$3, $1})); }
| expr_op AND expr_op { $$ = new ExprOpAnd(makeCurPos(@2, data), $1, $3); }
| expr_op OR expr_op { $$ = new ExprOpOr(makeCurPos(@2, data), $1, $3); }
| expr_op IMPL expr_op { $$ = new ExprOpImpl(makeCurPos(@2, data), $1, $3); }
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index ddf529b9e..00622a142 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -3583,6 +3583,24 @@ static RegisterPrimOp primop_lessThan({
.fun = prim_lessThan,
});
+static void prim_dollar(EvalState & state, const PosIdx pos, Value * * args, Value & v)
+{
+ state.forceValue(*args[0], pos);
+ state.forceValue(*args[1], pos);
+ // pos is exact here, no need for a message.
+ CompareValues comp(state, noPos, "");
+ v.mkBool(comp(args[0], args[1]));
+}
+
+static RegisterPrimOp primop_dollar({
+ .name = "__dollar",
+ .args = {"e1", "e2"},
+ .doc = R"(
+ Just like haskell :)
+ )",
+ .fun = prim_dollar,
+});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment