Continued work on parser, now calling functions and rolling correctly

This commit is contained in:
Stefan Zermatten
2020-09-10 00:14:24 +02:00
parent 81645df2a6
commit ede4e1367d
16 changed files with 243 additions and 88 deletions

View File

@@ -1,4 +1,17 @@
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);
@@ -7,11 +20,11 @@ export default class ParseNode {
throw new Meteor.Error('toString not implemented on ' + this.constructor.name);
}
// Compile, but turn rolls into arrays
roll(){
return this.compile();
roll(scope){
return this.compile(scope);
}
// Compile, turn rolls into arrays, and reduce those arrays into single values
reduce(){
return this.roll();
reduce(scope){
return this.roll(scope);
}
}