Sfoglia il codice sorgente

feat: implement for parser for visual UI

Implement for loop text parser for visual UI
Lucas de Souza 2 anni fa
parent
commit
d67b13ea85
1 ha cambiato i file con 13 aggiunte e 14 eliminazioni
  1. 13 14
      js/util/parseFromVisual.js

+ 13 - 14
js/util/parseFromVisual.js

@@ -99,19 +99,16 @@ function breakWalker (_) {
 /**
  * @param {Commands.For} forLoop
  * */
-// function forWalker (forLoop) {
-//
-//   const var_attribution = forLoop.for_id;
-//   const commands = forLoop.commands.map(commandWalker)
-//
-//     return {var_attribution,
-//  var_incrementation,
-//  expression1,
-//  expression2,
-//  expression3,
-//  commands,
-//     }
-// }
+function forWalker (forLoop) {
+  const var_attribution = expressionWalker(forLoop.for_id);
+  const var_initial = expressionWalker(forLoop.for_from);
+  const condition = expressionWalker(forLoop.for_to);
+  const step_expression = forLoop.for_pass
+    ? expressionWalker(forLoop.for_pass)
+    : [];
+  const commands = forLoop.commands.map(commandWalker);
+  return { var_attribution, var_initial, condition, step_expression, commands };
+}
 
 /**
  * @param {Commands.While} whileLoop
@@ -205,6 +202,8 @@ function commandWalker (command) {
     parsedCommand = returnWalker(command);
   } else if (command instanceof Commands.Switch) {
     parsedCommand = switchWalker(command);
+  } else if (command instanceof Commands.For) {
+    parsedCommand = forWalker(command);
   } else {
     throw new Error("not implemented");
   }
@@ -507,7 +506,7 @@ export function parseCode (text) {
     const functions = program.functions.map(functionWalker);
     return { globals, functions };
   } catch (e) {
-    console.error(e)
+    console.error(e);
     return null;
   }
 }