From 5e435ad92cb7ae3d05c54d9e35020580a0459ded Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 22 Aug 2017 18:38:54 -0400 Subject: Increase bonus binding power --- __tests__/parser.test.js | 24 ++++++++++++++++++++++++ src/parser.js | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index 54e1da7..fc47576 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -175,6 +175,30 @@ describe('parse', () => { }) }) + test('bonus binds stronger than addition', () => { + expect(parse('2d6 + 2d6+2d6')).toEqual({ + type: 'add', + left: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + }, + right: { + type: 'bonusAdd', + left: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + }, + right: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + } + } + }) + }) + describe('parsing parentheses', () => { test('(1d6)d6', () => { expect(parse('(1d6)d6')).toEqual({ diff --git a/src/parser.js b/src/parser.js index 244cdd1..344fb7d 100644 --- a/src/parser.js +++ b/src/parser.js @@ -65,8 +65,8 @@ newDieOperation('K') newDieOperation('k') newInfix('bigPlus', 20, { type: 'add' }) -newInfix('plus', 20, { type: 'bonusAdd' }) -newInfix('minus', 20, { type: 'bonusSubtract' }) +newInfix('plus', 25, { type: 'bonusAdd' }) +newInfix('minus', 25, { type: 'bonusSubtract' }) newInfix('bigMinus', 20, { type: 'subtract' }) newSymbol('minus', (parser) => { return { -- cgit v1.2.3