Replaced old parser with new parser
This commit is contained in:
@@ -12,4 +12,8 @@ export default class ArrayNode extends ParseNode {
|
||||
toString(){
|
||||
return `[${this.values.map(node => node.toString()).join(', ')}]`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.values.forEach(value => value.traverse(fn));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ export default class CallNode extends ParseNode {
|
||||
toString(){
|
||||
return `${this.functionName}(${this.args.map(node => node.toString()).join(', ')})`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.args.forEach(arg => arg.traverse(fn));
|
||||
}
|
||||
}
|
||||
|
||||
function castArgsToType({fn, scope, context, args, type}){
|
||||
@@ -65,6 +69,5 @@ function castArgsToType({fn, scope, context, args, type}){
|
||||
})
|
||||
}
|
||||
if (resolvedArgs.failed) return resolvedArgs;
|
||||
console.log({result})
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ export default class IfNode extends ParseNode {
|
||||
});
|
||||
}
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.condition.traverse(fn);
|
||||
this.consequent.traverse(fn);
|
||||
this.alternative.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,9 @@ export default class IndexNode extends ParseNode {
|
||||
toString(){
|
||||
return `${this.array.toString()}[${this.index.toString()}]`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.array.traverse(fn);
|
||||
this.index.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,8 @@ export default class NotOperatorNode extends ParseNode {
|
||||
let {right} = this;
|
||||
return `!${right.toString()}`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.right.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +53,9 @@ export default class OperatorNode extends ParseNode {
|
||||
let {left, right, operator} = this;
|
||||
return `${left.toString()} ${operator} ${right.toString()}`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.left.traverse(fn);
|
||||
this.right.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,8 @@ export default class ParenthesisNode extends ParseNode {
|
||||
toString(){
|
||||
return `(${this.content.toString()})`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.content.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,8 @@ export default class ParseNode {
|
||||
return this.roll(scope, context);
|
||||
}
|
||||
}
|
||||
// If traverse isn't implemented, just apply it to the current node
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,9 @@ export default class RollNode extends ParseNode {
|
||||
reduce(scope, context){
|
||||
return this.roll(scope, context).reduce(scope, context);
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.left.traverse(fn);
|
||||
this.right.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,8 @@ export default class UnaryOperatorNode extends ParseNode {
|
||||
let {right, operator} = this;
|
||||
return `${operator}${right.toString()}`;
|
||||
}
|
||||
traverse(fn){
|
||||
fn(this);
|
||||
this.right.traverse(fn);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user