Browse Source

work in progress

Igor 2 years ago
parent
commit
dfc90dd5b1
2 changed files with 68 additions and 8 deletions
  1. 63 8
      js/util/codeParser.js
  2. 5 0
      js/visualUI/commands/generic_expression.js

+ 63 - 8
js/util/codeParser.js

@@ -154,6 +154,13 @@ function parseCommands (commands_block, function_obj) {
 
       case Models.COMMAND_TYPES.functioncall:
         return parseFunctionCall(commands_block, function_obj);
+
+      case Models.COMMAND_TYPES.iftrue:
+        return parseIfTrue(commands_block, function_obj);
+
+      //case Models.COMMAND_TYPES.repeatNtimes:
+      default:
+        return parseRepeatNTimes(commands_block, function_obj);
     }
     return null;
   }
@@ -218,21 +225,69 @@ function parseComment(command, function_obj) {
 
 function parseFunctionCall (command, function_obj) {
 
-  var parameters = CodeParser.expressionParserCodeVisual(command.parameters_list[0], function_obj);
-  var function_called = CodeParser.searchFunction(command.name);
+  var parameters = [];
+  if (command.parameters_list) {
+    command.parameters_list.forEach(function(el) {
+      var temp = CodeParser.expressionParserCodeVisual(el, function_obj);
+      if (temp.content === 0) temp.content = "0";
+      parameters.push(temp[0]);
+    });
+  }
 
-  //function_called.parameters_list = parameters;
+  var function_called = CodeParser.searchFunction(command.name);
 
-  console.log('atenção: ', parameters, command.parameters_list);
-  
   var temp = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false);
   temp.function_called = function_called;
   temp.parameters_list = parameters;
   
   return new Models.FunctionCall(
     temp, 
-    parameters
+    null
   );
+}
+
+function parseIfTrue(command, function_obj) {
+
+  var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
+  var ifTrueBlock = parseCommands(command.ifTrue, function_obj);
+  var ifFalseBlock = parseCommands(command.ifFalse, function_obj);
+
+  return new Models.IfTrue(expression, ifTrueBlock, ifFalseBlock);
+
+}
+
+function parseRepeatNTimes(command, function_obj) {
+
+  var var_attribution = CodeParser.expressionParserCodeVisual(command.var_attribution, function_obj);
+  var_attribution = var_attribution[0];
+
+  var expression1 = CodeParser.expressionParserCodeVisual(command.var_initial, function_obj);
+  expression1 = expression1[0];
+
+  var expression2 = CodeParser.expressionParserCodeVisual(command.condition, function_obj);
+  expression2 = expression2[0];
+
+  var expression3 = CodeParser.expressionParserCodeVisual(command.step_expression, function_obj);
+
+  console.log('expression3', expression3);
+
+  var commands_block = parseCommands(command.commands, function_obj);
+
+  // var_attribution,
+  //   var_incrementation,
+  //   expression1,
+  //   expression2,
+  //   expression3,
+  //   commands_block
+
+  return new Models.RepeatNTimes(
+    var_attribution,
+    new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),
+    expression1,
+    expression2,
+    null, 
+    commands_block);
+
+}
 
-  //new Models.FunctionCall(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false), null
-}
+			

+ 5 - 0
js/visualUI/commands/generic_expression.js

@@ -1654,6 +1654,11 @@ export function searchFunction (function_name) {
 
 export function expressionParserCodeVisual (parsed, function_obj) {
 
+  console.log('\nparsed')
+  console.log(parsed)
+  console.log('\n\n')
+  
+
   if (!parsed) return null;
 
   var var_not_found = [];