Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat($parse): support the integer division operator
Browse files Browse the repository at this point in the history
Closes #233
  • Loading branch information
chirayuk committed Nov 21, 2013
1 parent 056a734 commit b29dff9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/core/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Map<String, Operator> 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,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/core/parser/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit b29dff9

Please sign in to comment.