Added constants to the UI and Computation Engine
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}){
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,7 @@ export default class NotOperatorNode extends ParseNode {
|
||||
fn(this);
|
||||
this.right.traverse(fn);
|
||||
}
|
||||
replaceChildren(fn){
|
||||
this.right = this.right.replaceNodes(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,7 @@ export default class ParenthesisNode extends ParseNode {
|
||||
fn(this);
|
||||
this.content.traverse(fn);
|
||||
}
|
||||
replaceChildren(fn){
|
||||
this.content = this.content.replaceNodes(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,4 +34,7 @@ export default class UnaryOperatorNode extends ParseNode {
|
||||
fn(this);
|
||||
this.right.traverse(fn);
|
||||
}
|
||||
replaceChildren(fn){
|
||||
this.right = this.right.replaceNodes(fn);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user