diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 23:55:05 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 23:55:05 -0400 |
commit | 8ce258c105a514d6bcdc12d5e779ac1b68edd381 (patch) | |
tree | b81fa9b30775a87a5040ac9c047d8f28f68fe7b9 | |
parent | 31307362fac9a6d75a373463495aa688cfbc3cd1 (diff) |
Update index.js
-rw-r--r-- | index.js | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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 |