Jelajahi Sumber

Fix for parsing from text to visual UI

Lucas de Souza 2 tahun lalu
induk
melakukan
61a15352a0
2 mengubah file dengan 15 tambahan dan 4 penghapusan
  1. 2 1
      js/util/codeParser.js
  2. 13 3
      js/util/parseFromVisual.js

+ 2 - 1
js/util/codeParser.js

@@ -198,7 +198,7 @@ function parseReturn (command, function_obj) {
 
 function parseWriter (command, function_obj) {
 
-  var temp = CodeParser.expressionParserCodeVisual(command.content[0], function_obj);
+  var temp = CodeParser.expressionParserCodeVisual(command.content, function_obj);
 
   return new Models.Writer(
     temp,
@@ -271,6 +271,7 @@ function parseRepeatNTimes(command, function_obj) {
 
   var expression1 = CodeParser.expressionParserCodeVisual(command.var_initial, function_obj);
   expression1 = expression1[0];
+  expression1.content = "" + expression1.content;
 
   var expression2 = CodeParser.expressionParserCodeVisual(command.condition, function_obj);
 

+ 13 - 3
js/util/parseFromVisual.js

@@ -104,9 +104,15 @@ function forWalker (forLoop) {
   const var_attribution = expressionWalker(forLoop.for_id);
   const var_initial = expressionWalker(forLoop.for_from);
   const condition = expressionWalker(forLoop.for_to);
+  const defaultStep = [{ instance: "operator", type: TYPES.ARITHMETIC, value: '+' }, {
+    instance: "expression",
+    class: "simple",
+    type: TYPES.CONST,
+    value: 1,
+  }]
   const step_expression = forLoop.for_pass
     ? expressionWalker(forLoop.for_pass)
-    : [];
+    : defaultStep;
   const commands = forLoop.commands.map(commandWalker);
   return {
     type: "repeatNtimes",
@@ -231,10 +237,13 @@ function functionCallWalker (functionCall) {
   if (name === "$write") {
     const lastInput = parameters[parameters.length - 1][0];
     // if lastInput is an object with value === '\n', newLine is true
-    const newLine = lastInput.value && lastInput.value.match(/^\n$/) !== null;
-    const content = newLine
+    const newLine = lastInput.value && lastInput.value.match && lastInput.value.match(/^\n$/) !== null;
+    let content = newLine
       ? parameters.slice(0, parameters.length - 1)
       : parameters;
+    console.log("cont");
+    console.log([].concat(...parameters));
+    content = [].concat(...content);
     return {
       type: "writer",
       newLine,
@@ -484,6 +493,7 @@ export function parseExpression (text) {
  * @param {string} text
  * */
 export function parseCode (text) {
+  console.log(text);
   const parser = IVProgParser.createParser(text, false);
   const codeLinesMap = new Map();
   const tokens = Array.from(parser.lexer.reset(text));