Skip to content

Commit 2066c33

Browse files
committed
7.0.3 -- make counting operations have lowest priority in order of operations
1 parent 2b933ca commit 2066c33

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 7.0.3
2+
3+
## 🛠️ Bug fixes
4+
- Previously, `4d6 + 3d6 #s #f` would only count success/failures of the 3d6 rolls, since counting
5+
had higher priority than the plus operation. You could workaround that with parens `(4d6 + 3d6) #s #f`
6+
In 7.0.3 and later, the counting operations now have the lowest priority.
7+
18
# 7.0.2
29
- remove demo code accidentally added
310

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void main() {
129129
If that's not the behavior you want, move the counts prior to the drop (`2d20 #cf #cs kh`).
130130

131131
* arithmetic operations
132-
* parenthesis for order of operations
132+
* parenthesis to force a certain order of operations
133133
* addition is a little special -- could be a sum of ints, or it can be used to aggregate results of multiple dice rolls
134134
* Addition of integers is the usual sum
135135
* `4+5`

lib/src/parser.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,23 @@ Parser<DiceExpression> parserBuilder(DiceRoller roller) {
8989
..left(
9090
(pattern('Kk') & pattern('LlHh').optional()).flatten().trim(),
9191
(a, op, b) => DropHighLowOp(op.toLowerCase(), a, b),
92-
)
93-
// count >=, <=, <, >, =,
94-
// #s, #cs, #f, #cf -- count (critical) successes / failures
95-
..left(
96-
(char('#') &
97-
char('c').optional() &
98-
pattern('sf').optional() &
99-
pattern('<>').optional() &
100-
char('=').optional())
101-
.flatten()
102-
.trim(),
103-
(a, op, b) => CountOp(op.toLowerCase(), a, b),
10492
);
10593

10694
builder.group().left(char('*').trim(), (a, op, b) => MultiplyOp(op, a, b));
10795
builder.group()
10896
..left(char('+').trim(), (a, op, b) => AddOp(op, a, b))
10997
..left(char('-').trim(), (a, op, b) => SubOp(op, a, b));
98+
// count >=, <=, <, >, =,
99+
// #s, #cs, #f, #cf -- count (critical) successes / failures
100+
builder.group().left(
101+
(char('#') &
102+
char('c').optional() &
103+
pattern('sf').optional() &
104+
pattern('<>').optional() &
105+
char('=').optional())
106+
.flatten()
107+
.trim(),
108+
(a, op, b) => CountOp(op.toLowerCase(), a, b),
109+
);
110110
return builder.build().end();
111111
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dart_dice_parser
22
description: A dart library for parsing dice notation (`2d6+4`). Supports advantage/disadvantage, exploding die, and other variations.
3-
version: 7.0.2
3+
version: 7.0.3
44
homepage: https://github.com/Adventuresmith/dart-dice-parser
55
repository: https://github.com/Adventuresmith/dart-dice-parser
66

test/dart_dice_parser_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void main() {
628628

629629
test('string method returns expr', () {
630630
final dice = DiceExpression.create('2d6# + 5d6!>=5 + 5D66', seededRandom);
631-
expect(dice.toString(), '((((2d6) # ) + ((5d6) !>= 5)) + (5D66))');
631+
expect(dice.toString(), '((2d6) # (( + ((5d6) !>= 5)) + (5D66)))');
632632
});
633633

634634
test('invalid dice str', () {

0 commit comments

Comments
 (0)