Lots of progress testing and fixing computation engine

This commit is contained in:
Stefan Zermatten
2021-09-16 14:31:28 +02:00
parent dfd7ad4af5
commit a660ccc458
34 changed files with 775 additions and 90 deletions

View File

@@ -1,5 +1,6 @@
import { CompilationContext } from '/imports/parser/parser.js';
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
export default function computeCalculations(node, scope){
if (!node.data) return;
@@ -17,7 +18,12 @@ function evaluateCalculation(calculation, scope){
const parseNode = calculation._parsedCalculation;
const fn = calculation._parseLevel;
const calculationScope = {...calculation._localScope, ...scope};
calculation.value = parseNode[fn](calculationScope, context);
const resultNode = parseNode[fn](calculationScope, context);
if (resultNode instanceof ConstantNode){
calculation.value = resultNode.value;
} else {
calculation.value = NaN;
}
calculation.errors = context.errors;
}