about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-08-02T16·03+0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-08-02T16·03+0000
commit47701677e88230abf7d9106c55f46aa660643ce7 (patch)
treea63fb4fde15c85de24b3d04a3346cd72c6e009ca
parent5d147e125cea69e9a3b12f0ef64c64f42985c65e (diff)
Add integer ‘-’, ‘*’ and ‘/’ operators
-rw-r--r--src/libexpr/parser.y6
-rw-r--r--tests/lang/eval-okay-arithmetic.exp2
-rw-r--r--tests/lang/eval-okay-arithmetic.nix6
-rw-r--r--tests/lang/lib.nix4
4 files changed, 16 insertions, 2 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 4a59a0875eb8..d998c840e151 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -271,7 +271,8 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
 %nonassoc EQ NEQ
 %right UPDATE
 %left NOT
-%left '+'
+%left '+' '-'
+%left '*' '/'
 %right CONCAT
 %nonassoc '?'
 %nonassoc '~'
@@ -322,6 +323,9 @@ expr_op
       l->push_back($3);
       $$ = new ExprConcatStrings(false, l);
     }
+  | expr_op '-' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__sub")), $1), $3); }
+  | expr_op '*' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__mul")), $1), $3); }
+  | expr_op '/' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__div")), $1), $3); }
   | expr_op CONCAT expr_op { $$ = new ExprOpConcatLists($1, $3); }
   | expr_app
   ;
diff --git a/tests/lang/eval-okay-arithmetic.exp b/tests/lang/eval-okay-arithmetic.exp
index f625eb6ab6ab..d03b13697b27 100644
--- a/tests/lang/eval-okay-arithmetic.exp
+++ b/tests/lang/eval-okay-arithmetic.exp
@@ -1 +1 @@
-1843
+2170
diff --git a/tests/lang/eval-okay-arithmetic.nix b/tests/lang/eval-okay-arithmetic.nix
index 76bef919bdab..70179c5d15b2 100644
--- a/tests/lang/eval-okay-arithmetic.nix
+++ b/tests/lang/eval-okay-arithmetic.nix
@@ -22,5 +22,11 @@ let {
     [ (sum (range 1 50))
       (123 + 456)
       (0 + -10 + -(-11) + -x)
+      (10 - 7 - -2)
+      (10 - (6 - -1))
+      (10 - 1 + 2)
+      (3 * 4 * 5)
+      (56088 / 123 / 2)
+      (3 + 4 * const 5 0 - 6 / id 2)
     ];
 }
diff --git a/tests/lang/lib.nix b/tests/lang/lib.nix
index 551b67aed350..cdba2b947793 100644
--- a/tests/lang/lib.nix
+++ b/tests/lang/lib.nix
@@ -49,4 +49,8 @@ rec {
     if comp (head list2) (head list1) then [(head list2)] ++ mergeLists comp list1 (tail list2) else
     [(head list1)] ++ mergeLists comp (tail list1) list2;
 
+  id = x: x;
+
+  const = x: y: x;
+
 }