Merge branch 'version-2' of https://github.com/ThaumRystra/DiceCloud1 into version-2

This commit is contained in:
Stefan Zermatten
2020-09-28 13:58:03 +02:00
9 changed files with 60 additions and 12 deletions

View File

@@ -12,13 +12,12 @@ export default class IndexNode extends ParseNode {
let selection = this.array.values[index.value - 1];
if (selection){
let result = selection[fn](scope, context);
result.inheritDetails([index, this]);
return result;
}
}
return new IndexNode({
index,
array: this.array[fn](scope, context),
index: this.index[fn](scope, context),
previousNodes: [this],
});
}

View File

@@ -19,7 +19,6 @@ export default class OperatorNode extends ParseNode {
right: rightNode,
operator: this.operator,
fn: this.fn,
previousNodes: [this],
});
} else {
left = leftNode.value;
@@ -48,7 +47,6 @@ export default class OperatorNode extends ParseNode {
return new ConstantNode({
value: result,
type: typeof result,
previousNodes: [this, leftNode, rightNode],
});
}
toString(){

View File

@@ -9,7 +9,8 @@ export default class ParenthesisNode extends ParseNode {
let content = this.content[fn](scope, context);
if (
content.constructor.name === 'IfNode' ||
content.constructor.name === 'OperatorNode'
content.constructor.name === 'OperatorNode' ||
content.constructor.name === 'RollNode'
){
return new ParenthesisNode({content, previousNodes: [this]});
} else {

View File

@@ -0,0 +1,33 @@
import ParseNode from '/imports/parser/parseTree/ParseNode.js';
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
export default class UnaryOperatorNode extends ParseNode {
constructor({operator, right}) {
super(...arguments);
this.operator = operator;
this.right = right;
}
resolve(fn, scope, context){
let rightNode = this.right[fn](scope, context);
if (rightNode.type !== 'number'){
return new UnaryOperatorNode({
operator: this.operator,
right: rightNode,
});
}
let right = rightNode.value;
let result;
switch(this.operator){
case '-': result = -right; break;
case '+': result = +right; break;
}
return new ConstantNode({
value: result,
type: typeof result,
});
}
toString(){
let {right, operator} = this;
return `${operator}${right.toString()}`;
}
}