Finished migrating parser to be object orientation free. All tests pass
This commit is contained in:
35
app/imports/parser/parseTree/rollArray.js
Normal file
35
app/imports/parser/parseTree/rollArray.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import constant from './constant.js';
|
||||
|
||||
const rollArray = {
|
||||
constructor({values, diceSize, diceNum}) {
|
||||
return {
|
||||
parseType: 'rollArray',
|
||||
values,
|
||||
diceSize,
|
||||
diceNum,
|
||||
};
|
||||
},
|
||||
compile(node, scope, context){
|
||||
return {
|
||||
result: node,
|
||||
context
|
||||
};
|
||||
},
|
||||
toString(node){
|
||||
return `[${node.values.join(', ')}]`;
|
||||
},
|
||||
reduce(node, scope, context){
|
||||
const total = node.values.reduce((a, b) => a + b, 0);
|
||||
return {
|
||||
result: constant.create({
|
||||
value: total,
|
||||
}),
|
||||
context,
|
||||
};
|
||||
},
|
||||
traverse(node, fn){
|
||||
return fn(node);
|
||||
}
|
||||
}
|
||||
|
||||
export default rollArray;
|
||||
Reference in New Issue
Block a user