Added constants to the UI and Computation Engine

This commit is contained in:
Stefan Zermatten
2021-02-11 13:03:31 +02:00
parent 25fd5c18e8
commit 3313ed0297
21 changed files with 243 additions and 54 deletions

View File

@@ -33,4 +33,7 @@ export default class ArrayNode extends ParseNode {
fn(this);
this.values.forEach(value => value.traverse(fn));
}
replaceChildren(fn){
this.values = this.values.map(node => node.replaceNodes(fn));
}
}

View File

@@ -54,6 +54,9 @@ export default class CallNode extends ParseNode {
fn(this);
this.args.forEach(arg => arg.traverse(fn));
}
replaceChildren(fn){
this.args = this.args.map(arg => arg.replaceNodes(fn));
}
}
function castArgsToType({fn, scope, context, args, type}){

View File

@@ -34,4 +34,9 @@ export default class IfNode extends ParseNode {
this.consequent.traverse(fn);
this.alternative.traverse(fn);
}
replaceChildren(fn){
this.condition = this.condition.replaceNodes(fn);
this.consequent = this.consequent.replaceNodes(fn);
this.alternative = this.alternative.replaceNodes(fn);
}
}

View File

@@ -29,4 +29,8 @@ export default class IndexNode extends ParseNode {
this.array.traverse(fn);
this.index.traverse(fn);
}
replaceChildren(fn){
this.array = this.array.replaceNodes(fn);
this.index = this.index.replaceNodes(fn);
}
}

View File

@@ -28,4 +28,7 @@ export default class NotOperatorNode extends ParseNode {
fn(this);
this.right.traverse(fn);
}
replaceChildren(fn){
this.right = this.right.replaceNodes(fn);
}
}

View File

@@ -60,4 +60,8 @@ export default class OperatorNode extends ParseNode {
this.left.traverse(fn);
this.right.traverse(fn);
}
replaceChildren(fn){
this.left = this.left.replaceNodes(fn);
this.right = this.right.replaceNodes(fn);
}
}

View File

@@ -23,4 +23,7 @@ export default class ParenthesisNode extends ParseNode {
fn(this);
this.content.traverse(fn);
}
replaceChildren(fn){
this.content = this.content.replaceNodes(fn);
}
}

View File

@@ -30,4 +30,14 @@ export default class ParseNode {
traverse(fn){
fn(this);
}
// replace nodes, only replace nodes if fn returns a value
replaceNodes(fn){
let newNode = fn(this);
if (newNode) {
return newNode;
} else {
if (this.replaceChildren) this.replaceChildren(fn)
return this;
}
}
}

View File

@@ -64,4 +64,8 @@ export default class RollNode extends ParseNode {
this.left.traverse(fn);
this.right.traverse(fn);
}
replaceChildren(fn){
this.left = this.left.replaceNodes(fn);
this.right = this.right.replaceNodes(fn);
}
}

View File

@@ -34,4 +34,7 @@ export default class UnaryOperatorNode extends ParseNode {
fn(this);
this.right.traverse(fn);
}
replaceChildren(fn){
this.right = this.right.replaceNodes(fn);
}
}