Replaced old parser with new parser

This commit is contained in:
Stefan Zermatten
2020-11-10 14:07:22 +02:00
parent 1f0678b50b
commit 3024168e95
25 changed files with 117 additions and 426 deletions

View File

@@ -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));
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -24,4 +24,8 @@ export default class NotOperatorNode extends ParseNode {
let {right} = this;
return `!${right.toString()}`;
}
traverse(fn){
fn(this);
this.right.traverse(fn);
}
}

View File

@@ -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);
}
}

View File

@@ -20,4 +20,8 @@ export default class ParenthesisNode extends ParseNode {
toString(){
return `(${this.content.toString()})`;
}
traverse(fn){
fn(this);
this.content.traverse(fn);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}