Parser now uses context to store details of the computation
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
export default class ParseNode {
|
||||
constructor({previousNodes, detail}){
|
||||
this.inheritDetails(previousNodes);
|
||||
if (detail) this.pushDetails([detail]);
|
||||
}
|
||||
inheritDetails(nodes){
|
||||
if (!nodes || !nodes.length) return;
|
||||
nodes.forEach(node => this.pushDetails(node.details));
|
||||
}
|
||||
pushDetails(details){
|
||||
if (!details || !details.length) return;
|
||||
if (!this.details) this.details = [];
|
||||
details.forEach(detail => this.details.push(detail));
|
||||
}
|
||||
compile(){
|
||||
// Returns a ParseNode, a ConstantNode if possible
|
||||
throw new Meteor.Error('Compile not implemented on ' + this.constructor.name);
|
||||
}
|
||||
toString(){
|
||||
throw new Meteor.Error('toString not implemented on ' + this.constructor.name);
|
||||
}
|
||||
compile(scope, context){
|
||||
// Returns a ParseNode, a ConstantNode if possible
|
||||
if(this.resolve) {
|
||||
return this.resolve('compile', scope, context);
|
||||
} else {
|
||||
throw new Meteor.Error('Compile not implemented on ' + this.constructor.name);
|
||||
}
|
||||
}
|
||||
// Compile, but turn rolls into arrays
|
||||
roll(scope){
|
||||
return this.compile(scope);
|
||||
roll(scope, context){
|
||||
if (this.resolve){
|
||||
return this.resolve('roll', scope, context);
|
||||
} else {
|
||||
return this.compile(scope, context);
|
||||
}
|
||||
}
|
||||
// Compile, turn rolls into arrays, and reduce those arrays into single values
|
||||
reduce(scope){
|
||||
return this.roll(scope);
|
||||
reduce(scope, context){
|
||||
if (this.resolve){
|
||||
return this.resolve('reduce', scope, context);
|
||||
} else {
|
||||
return this.roll(scope, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user