blob: 8cdfe1e674e6bfec01606d81ade6221110cbe20f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
|