blob: e117b7cb0ef50bf89f1d862716170cf11f19c442 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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 'E':
return D.explode(interpret(tree.left), interpret(tree.right))
case 'K':
return D.keepHigh(interpret(tree.left), interpret(tree.right))
case 'k':
return D.keepLow(interpret(tree.left), interpret(tree.right))
case 'A':
return D.again(interpret(tree.left), interpret(tree.right))
case 'T':
return D.threshold(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))
case 'bonusAdd':
return D.bonusAdd(interpret(tree.left), interpret(tree.right))
case 'bonusSubtract':
return D.bonusSubtract(interpret(tree.left), interpret(tree.right))
}
}
const parse = expressionString => {
const tree = P.parse(expressionString)
return interpret(tree)
}
exports.parse = parse
exports.roll = D.roll
exports.pool = D.pool
|