m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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