m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-14 23:55:05 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-14 23:55:05 -0400
commit8ce258c105a514d6bcdc12d5e779ac1b68edd381 (patch)
treeb81fa9b30775a87a5040ac9c047d8f28f68fe7b9
parent31307362fac9a6d75a373463495aa688cfbc3cd1 (diff)
Update index.js
-rw-r--r--index.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/index.js b/index.js
index e69de29..8cdfe1e 100644
--- a/index.js
+++ b/index.js
@@ -0,0 +1,26 @@
+const P = require('./src/parser.js')
+const D = require('./src/dice.js')
+
+const interpret = tree => {
+ switch(tree.type) {
+ case 'constant':
+ return D.constant(tree.value)
+ case 'd':
+ return D.d(interpret(tree.left), interpret(tree.right))
+ case 'add':
+ return D.add(interpret(tree.left), interpret(tree.right))
+ case 'subtract':
+ return D.subtract(interpret(tree.left), interpret(tree.right))
+ case 'negative':
+ return D.negative(interpret(tree.value))
+ }
+}
+
+const parse = expressionString => {
+ const tree = P.parse(expressionString)
+ return interpret(tree)
+}
+
+exports.parse = parse
+exports.roll = D.roll
+exports.pool = D.pool