Sfoglia il codice sorgente

Globals: parsing - in progress

Igor 2 anni fa
parent
commit
8e75a3625a
3 ha cambiato i file con 79 aggiunte e 10 eliminazioni
  1. 31 7
      js/iassign-integration-functions.js
  2. 34 0
      js/util/codeParser.js
  3. 14 3
      js/util/iassignHelpers.js

+ 31 - 7
js/iassign-integration-functions.js

@@ -80,13 +80,24 @@ function getAnswer () {
     objAnswer.code = generator();
     objAnswer.test_cases = ivprogCore.getTestCases();
     objAnswer.logs = ivprogCore.getLogs();
-    objAnswer.settings = {
-      "programming": ivprogCore.Config.activity_programming_type,
-      "functions": ivprogCore.Config.activity_functions,
-      "datatypes": ivprogCore.Config.activity_datatypes,
-      "commands": ivprogCore.Config.activity_commands,
-      "filter": ivprogCore.Config.activity_filter
-    };
+    try {
+      objAnswer.settings = {
+        "programming": Object.fromEntries(ivprogCore.Config.activity_programming_type),
+        "functions": Object.fromEntries(ivprogCore.Config.activity_functions),
+        "datatypes": Object.fromEntries(ivprogCore.Config.activity_datatypes),
+        "commands": Object.fromEntries(ivprogCore.Config.activity_commands),
+        "filter": Object.fromEntries(ivprogCore.Config.activity_filter)
+      };
+    }
+    catch(e) {
+      objAnswer.settings = {
+        "programming": [],
+        "functions": [],
+        "datatypes": [],
+        "commands": [],
+        "filter": []
+      };
+    }
 
     return JSON.stringify(objAnswer, null, 4);
 
@@ -812,6 +823,19 @@ function showInvalidData () {
   })
 }
 
+function showMessageDialog (msg = "") {
+  $('.ui.height_100.add_accordion').dimmer({
+    closable: false
+  });
+  $('.dimmer_content_message h3').html(msg);
+  $('.dimmer_content_message button').text("OK");
+  $('.dimmer_content_message').css('display', 'block');
+  $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
+  $('.ui.height_100.add_accordion').dimmer('show');
+  $('.dimmer_content_message button').on('click', function(e) {
+    $('.ui.height_100.add_accordion').dimmer('hide');
+  })
+}
 
 function showInvalidFile () {
   $('.ui.height_100.add_accordion').dimmer({

+ 34 - 0
js/util/codeParser.js

@@ -0,0 +1,34 @@
+
+import * as Models from '../visualUI/ivprog_elements';
+
+function parseGlobal (global_obj) {
+
+  var new_global = new Models.Variable(
+    global_obj.type, 
+    global_obj.name, 
+    global_obj.value);
+  
+  new_global.is_constant = global_obj.is_const;
+  new_global.columns = global_obj.columns;
+  new_global.dimension = global_obj.dimension;
+  new_global.rows = global_obj.rows;
+	
+	window.program_obj.addGlobal(new_global);
+}
+
+function parseFunction (function_obj) {
+  
+}
+
+export function parserCodeVisual (code_obj = null) {
+
+  console.log('chegou!', code_obj)
+  window.conteudo = code_obj
+
+  // Globals:
+  code_obj.globals.forEach(parseGlobal);
+
+  // Functions:
+  code_obj.functions.forEach(parseFunction);
+
+}

+ 14 - 3
js/util/iassignHelpers.js

@@ -5,6 +5,7 @@ import { TestConsole } from "./testConsole";
 import { parseLogs } from "./../services/userLog";
 import { SemanticAnalyser } from "../processor/semantic/semanticAnalyser";
 import { Maybe } from "./maybe";
+import { parserCodeVisual } from "./codeParser";
 
 function parseActivityData (data) {
   let algorithm_in_ilm = null;
@@ -29,13 +30,12 @@ function parseActivityData (data) {
 function configAuxiliar (obj_config) {
 
   return new Map(
-    Object
+      Object
         .keys(obj_config)
         .map(
             key => [key, obj_config[key]]
         )
-  )
-
+    )
 }
     
 function setActivityConfig (config_json) {
@@ -51,6 +51,17 @@ function setActivityConfig (config_json) {
 function setPreviousAlgorithm (code) {
   console.log('conteúdo: ')
   console.log(code)
+  
+  var code_obj = null;
+  try {
+    code_obj = ivprogCore.parseCode(code)
+    parserCodeVisual(code_obj)
+  }
+  catch(e) {
+    showInvalidData()
+    console.log(e)
+    return
+  }
 }
 
 export function prepareActivityToStudentHelperJSON (ilm_cont) {