about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libexpr/lexer.l2
-rw-r--r--src/libexpr/parser.y5
-rw-r--r--tests/lang/eval-okay-arithmetic.exp2
-rw-r--r--tests/lang/eval-okay-arithmetic.nix23
4 files changed, 31 insertions, 1 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l
index fe2ff75d0d1c..3b7c6bb57a06 100644
--- a/src/libexpr/lexer.l
+++ b/src/libexpr/lexer.l
@@ -101,6 +101,8 @@ or          { return OR_KW; }
 
 \=\=        { return EQ; }
 \!\=        { return NEQ; }
+\<\=        { return LEQ; }
+\>\=        { return GEQ; }
 \&\&        { return AND; }
 \|\|        { return OR; }
 \-\>        { return IMPL; }
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index d998c840e151..cd1b0e21fa7c 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -269,6 +269,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
 %left OR
 %left AND
 %nonassoc EQ NEQ
+%left '<' '>' LEQ GEQ
 %right UPDATE
 %left NOT
 %left '+' '-'
@@ -312,6 +313,10 @@ expr_op
   | '-' expr_op %prec NEGATE { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__sub")), new ExprInt(0)), $2); }
   | expr_op EQ expr_op { $$ = new ExprOpEq($1, $3); }
   | expr_op NEQ expr_op { $$ = new ExprOpNEq($1, $3); }
+  | expr_op '<' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__lessThan")), $1), $3); }
+  | expr_op LEQ expr_op { $$ = new ExprOpNot(new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__lessThan")), $3), $1)); }
+  | expr_op '>' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__lessThan")), $3), $1); }
+  | expr_op GEQ expr_op { $$ = new ExprOpNot(new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__lessThan")), $1), $3)); }
   | expr_op AND expr_op { $$ = new ExprOpAnd($1, $3); }
   | expr_op OR expr_op { $$ = new ExprOpOr($1, $3); }
   | expr_op IMPL expr_op { $$ = new ExprOpImpl($1, $3); }
diff --git a/tests/lang/eval-okay-arithmetic.exp b/tests/lang/eval-okay-arithmetic.exp
index d03b13697b27..d73ac3eb700d 100644
--- a/tests/lang/eval-okay-arithmetic.exp
+++ b/tests/lang/eval-okay-arithmetic.exp
@@ -1 +1 @@
-2170
+2185
diff --git a/tests/lang/eval-okay-arithmetic.nix b/tests/lang/eval-okay-arithmetic.nix
index 70179c5d15b2..62a0ada0653e 100644
--- a/tests/lang/eval-okay-arithmetic.nix
+++ b/tests/lang/eval-okay-arithmetic.nix
@@ -18,6 +18,8 @@ let {
 
   x = 12;
 
+  err = abort "urgh";
+
   body = sum
     [ (sum (range 1 50))
       (123 + 456)
@@ -28,5 +30,26 @@ let {
       (3 * 4 * 5)
       (56088 / 123 / 2)
       (3 + 4 * const 5 0 - 6 / id 2)
+
+      (if 3 < 7 then 1 else err)
+      (if 7 < 3 then err else 1)
+      (if 3 < 3 then err else 1)
+
+      (if 3 <= 7 then 1 else err)
+      (if 7 <= 3 then err else 1)
+      (if 3 <= 3 then 1 else err)
+
+      (if 3 > 7 then err else 1)
+      (if 7 > 3 then 1 else err)
+      (if 3 > 3 then err else 1)
+
+      (if 3 >= 7 then err else 1)
+      (if 7 >= 3 then 1 else err)
+      (if 3 >= 3 then 1 else err)
+
+      (if 2 > 1 == 1 < 2 then 1 else err)
+      (if 1 + 2 * 3 >= 7 then 1 else err)
+      (if 1 + 2 * 3 < 7 then err else 1)
     ];
+
 }