From b29dff93fd5d2688735e5001e977b2c0cc98a5ea Mon Sep 17 00:00:00 2001 From: Chirayu Krishnappa Date: Thu, 21 Nov 2013 15:01:05 -0800 Subject: [PATCH] feat($parse): support the integer division operator Closes #233 --- lib/core/parser/parser.dart | 3 ++- test/core/parser/parser_spec.dart | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/parser/parser.dart b/lib/core/parser/parser.dart index 1e018351c..01b1c6f8d 100644 --- a/lib/core/parser/parser.dart +++ b/lib/core/parser/parser.dart @@ -115,6 +115,7 @@ Map OPERATORS = { }, '*': (s, l, a, b) => a.eval(s, l) * b.eval(s, l), '/': (s, l, a, b) => a.eval(s, l) / b.eval(s, l), + '~/': (s, l, a, b) => a.eval(s, l) ~/ b.eval(s, l), '%': (s, l, a, b) => a.eval(s, l) % b.eval(s, l), '^': (s, l, a, b) => a.eval(s, l) ^ b.eval(s, l), '=': NULL_OP, @@ -290,7 +291,7 @@ class DynamicParser implements Parser { ParserAST _multiplicative() { var left = _unary(); var token; - while ((token = _expect('*','/','%')) != null) { + while ((token = _expect('*','%','/','~/')) != null) { left = _binaryFn(left, token.opKey, _unary()); } return left; diff --git a/test/core/parser/parser_spec.dart b/test/core/parser/parser_spec.dart index 56d20a298..870432ea1 100644 --- a/test/core/parser/parser_spec.dart +++ b/test/core/parser/parser_spec.dart @@ -72,6 +72,7 @@ main() { it('should parse multiplicative expressions', () { expect(eval("3*4/2%5")).toEqual(3*4/2%5); + expect(eval("3*4~/2%5")).toEqual(3*4~/2%5); }); @@ -539,6 +540,7 @@ main() { scope["taxRate"] = 8; scope["subTotal"] = 100; expect(eval("taxRate / 100 * subTotal")).toEqual(8); + expect(eval("taxRate ~/ 100 * subTotal")).toEqual(0); expect(eval("subTotal * taxRate / 100")).toEqual(8); });