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

@@ -2,15 +2,24 @@ import ParseNode from '/imports/parser/parseTree/ParseNode.js';
export default class ParenthesisNode extends ParseNode {
constructor({content}) {
super();
super(...arguments);
this.content = content;
}
compile(){
let content = this.content.compile();
compile(scope){
return this.resolve('compile', scope);
}
roll(scope){
return this.resolve('roll', scope);
}
reduce(scope){
return this.resolve('reduce', scope);
}
resolve(fn, scope){
let content = this.content[fn](scope);
if (content.constructor.name === 'ConstantNode'){
return content;
} else {
return new ParenthesisNode({content});
return new ParenthesisNode({content, previousNodes: [this]});
}
}
toString(){