Added functions and ensured the context was being passed around correctly

This commit is contained in:
Stefan Zermatten
2020-09-18 11:52:44 +02:00
parent 06f17a6d33
commit 6570665c1e
12 changed files with 209 additions and 53 deletions

View File

@@ -8,9 +8,9 @@ export default class RollNode extends ParseNode {
this.left = left;
this.right = right;
}
compile(scope){
let left = this.left.compile(scope);
let right = this.right.compile(scope);
compile(scope, context){
let left = this.left.compile(scope, context);
let right = this.right.compile(scope, context);
return new RollNode({left, right, previousNodes: [this]});
}
toString(){
@@ -23,8 +23,8 @@ export default class RollNode extends ParseNode {
}
}
roll(scope, context){
let left = this.left.reduce(scope);
let right = this.right.reduce(scope);
let left = this.left.reduce(scope, context);
let right = this.right.reduce(scope, context);
if (!left.isInteger){
return new ErrorNode({
node: this,
@@ -56,7 +56,7 @@ export default class RollNode extends ParseNode {
}
return new RollArrayNode({values});
}
reduce(scope){
return this.roll(scope).reduce(scope);
reduce(scope, context){
return this.roll(scope, context).reduce(scope, context);
}
}