소스 검색

feat: implement IfThenElse parser for visual UI

Implement IfThenElse text to visual UI parser
Lucas de Souza 2 년 전
부모
커밋
398b4a072d
1개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  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")
 }