m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js7
-rw-r--r--src/lexer.js1
-rw-r--r--src/parser.js1
3 files changed, 9 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index abe3c4b..d47455e 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -50,6 +50,12 @@ const multiply = (die1, die2) => {
}
}
+const divide = (die1, die2) => {
+ return () => {
+ return [() => Math.floor(roll(die1) / roll(die2))]
+ }
+}
+
const bonusAdd = (die1, die2) => {
return () => {
return die1().map(die => {
@@ -194,6 +200,7 @@ exports.d = d
exports.add = add
exports.subtract = subtract
exports.multiply = multiply
+exports.divide = divide
exports.bonusAdd = bonusAdd
exports.bonusSubtract = bonusSubtract
exports.negative = negative
diff --git a/src/lexer.js b/src/lexer.js
index c3eec8a..59fba16 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -19,6 +19,7 @@ newLexemeType('d', 'd')
newLexemeType('bigPlus', ' \\+ ' )
newLexemeType('bigMinus', ' - ')
newLexemeType('bigTimes', ' \\* ')
+newLexemeType('bigDivide', ' / ')
newLexemeType('plus', '\\+')
newLexemeType('minus', '-')
newLexemeType('(', '\\(')
diff --git a/src/parser.js b/src/parser.js
index 1a1e5d4..fd0fd59 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -72,6 +72,7 @@ newDieOperation('t')
newInfix('bigPlus', 20, { type: 'add' })
newInfix('bigMinus', 20, { type: 'subtract' })
newInfix('bigTimes', 23, { type: 'multiply' })
+newInfix('bigDivide', 23, { type: 'divide' })
newInfix('plus', 25, { type: 'bonusAdd' })
newInfix('minus', 25, { type: 'bonusSubtract' })
newSymbol('minus', (parser) => {