Browse Source

feat: implement IfThenElse parser for visual UI

Implement IfThenElse text to visual UI parser
Lucas de Souza 2 years ago
parent
commit
398b4a072d
1 changed files with 26 additions and 0 deletions
  1. 26 0
      js/util/parseFromVisual.js

+ 26 - 0
js/util/parseFromVisual.js

@@ -52,6 +52,30 @@ function getOpType (op) {
       return TYPES.LOGIC;
   }
 }
+
+/**
+  * @param {Commands.IfThenElse} ifthenelse
+  * */
+function ifThenElseWalker (ifthenelse) {
+  //ifthenelse.
+  const expression = expressionWalker(ifthenelse.condition);
+  const ifTrue = ifthenelse.ifTrue.commands.map(commandWalker)
+  let ifFalse = [];
+  if (ifthenelse.ifFalse) {
+    if (ifthenelse.ifFalse instanceof Commands.CommandBlock) {
+      ifFalse = ifthenelse.ifFalse.commands.map(commandWalker)
+    } else {
+      ifFalse = [ifThenElseWalker(ifthenelse.ifFalse)]
+    }
+  }
+  return {
+    type: "iftrue",
+    expression,
+    ifTrue,
+    ifFalse
+  }
+}
+
 /**
   * @param {Commands.Assign} assingment
   * */
@@ -96,6 +120,8 @@ function commandWalker (command) {
     return functionCallWalker(command)
   } else if (command instanceof Commands.Assign) {
     return assignmentWalker(command)
+  } else if (command instanceof Commands.IfThenElse) {
+    return ifThenElseWalker(command)
   }
   throw new Error("not implemented")
 }