Skip to content

Commit

Permalink
feat: support for the truncating division operator ~/
Browse files Browse the repository at this point in the history
  • Loading branch information
rbellens committed Dec 27, 2022
1 parent 77bd0a1 commit 6956648
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/src/evaluator.dart
Expand Up @@ -179,7 +179,9 @@ class ExpressionEvaluator {
return left / right();
case '%':
return left % right();
case "??":
case '~/':
return left ~/ right();
case '??':
return left ?? right();
}
throw ArgumentError(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/parser.dart
Expand Up @@ -125,7 +125,8 @@ class ExpressionParser {
'-': 9,
'*': 10,
'/': 10,
'%': 10
'%': 10,
'~/': 10,
};

// This function is responsible for gobbling an individual expression,
Expand Down
1 change: 1 addition & 0 deletions test/expressions_test.dart
Expand Up @@ -186,6 +186,7 @@ void main() {
'1+4-5%2*3': 2,
'x*x+y*y==z*z': true,
'n ?? 1': 1,
'5~/2': 2,
};

expressions.forEach((e, r) {
Expand Down

0 comments on commit 6956648

Please sign in to comment.