Browse Source

Merge branch 'fix-parser-bool' of LInE/iVProg into master

GitAdmin 3 years ago
parent
commit
272f5b353a
1 changed files with 16 additions and 5 deletions
  1. 16 5
      js/util/parseFromVisual.js

+ 16 - 5
js/util/parseFromVisual.js

@@ -1,6 +1,7 @@
 import { IVProgParser } from "../ast/ivprogParser";
 import * as Expressions from "../ast/expressions";
 import { Types } from "../typeSystem/types";
+import { convertBoolToString } from "../typeSystem/parsers";
 
 const TYPES = {
   VARIABLE: "var",
@@ -67,6 +68,11 @@ function expressionWalker (expression) {
     //const params = Array.prototype.concat.apply([], paramsList);
     funcObj.params = paramsList;
     result = [funcObj];
+  } else if (expression instanceof Expressions.UnaryApp) {
+    const left = expressionWalker(expression.left);
+    const opType = getOpType(expression.op);
+    const opValue = translateOp(opType, expression.op);
+    result = [{ instance: "operator", type: opType, value: opValue }, ...left];
   } else if (expression instanceof Expressions.InfixApp) {
     const left = expressionWalker(expression.left);
     const right = expressionWalker(expression.right);
@@ -77,11 +83,6 @@ function expressionWalker (expression) {
       { instance: "operator", type: opType, value: opValue },
       ...right,
     ];
-  } else if (expression instanceof Expressions.UnaryApp) {
-    const left = expressionWalker(expression.left);
-    const opType = getOpType(expression.op);
-    const opValue = translateOp(opType, expression.op);
-    result = [{ instance: "operator", type: opType, value: opValue }, ...left];
   } else if (expression instanceof Expressions.ArrayAccess) {
     const line = expressionWalker(expression.line);
     let arrayClass = "vector";
@@ -100,6 +101,16 @@ function expressionWalker (expression) {
         value: expression.id,
       },
     ];
+  } else if (expression instanceof Expressions.BoolLiteral) {
+    const value = expression.value;
+    result = [
+      {
+        instance: "expression",
+        class: "simple",
+        type: TYPES.CONST,
+        value: convertBoolToString(value),
+      },
+    ];
   } else {
     let value = expression.value;
     if (expression.value.toNumber) {