|
@@ -4,7 +4,7 @@
|
|
|
// This is used when is loaded "ivph" file under the button "upload"
|
|
// This is used when is loaded "ivph" file under the button "upload"
|
|
|
|
|
|
|
|
import * as Models from '../visualUI/ivprog_elements';
|
|
import * as Models from '../visualUI/ivprog_elements';
|
|
|
-import { LocalizedStrings } from "./../services/localizedStringsService";
|
|
|
|
|
|
|
+import { LocalizedStrings } from './../services/localizedStringsService';
|
|
|
import * as VariableValueMenuManagement from '../visualUI/commands/variable_value_menu';
|
|
import * as VariableValueMenuManagement from '../visualUI/commands/variable_value_menu';
|
|
|
import * as CodeParser from '../visualUI/commands/generic_expression';
|
|
import * as CodeParser from '../visualUI/commands/generic_expression';
|
|
|
|
|
|
|
@@ -13,16 +13,16 @@ function parseBoolean (var_value, dimensions) {
|
|
|
return var_value == LocalizedStrings.getUI("logic_value_true");
|
|
return var_value == LocalizedStrings.getUI("logic_value_true");
|
|
|
if (dimensions == 1) {
|
|
if (dimensions == 1) {
|
|
|
var final_array = [];
|
|
var final_array = [];
|
|
|
- var_value.forEach(function(el){
|
|
|
|
|
|
|
+ var_value.forEach(function(el) {
|
|
|
final_array.push(el == LocalizedStrings.getUI("logic_value_true"));
|
|
final_array.push(el == LocalizedStrings.getUI("logic_value_true"));
|
|
|
});
|
|
});
|
|
|
return final_array;
|
|
return final_array;
|
|
|
}
|
|
}
|
|
|
if (dimensions == 2) {
|
|
if (dimensions == 2) {
|
|
|
var final_array = [];
|
|
var final_array = [];
|
|
|
- var_value.forEach(function(row){
|
|
|
|
|
|
|
+ var_value.forEach(function(row) {
|
|
|
var temp = [];
|
|
var temp = [];
|
|
|
- row.forEach(function(el){
|
|
|
|
|
|
|
+ row.forEach(function(el) {
|
|
|
temp.push(el == LocalizedStrings.getUI("logic_value_true"));
|
|
temp.push(el == LocalizedStrings.getUI("logic_value_true"));
|
|
|
});
|
|
});
|
|
|
final_array.push(temp);
|
|
final_array.push(temp);
|
|
@@ -77,13 +77,13 @@ function parseFunction (function_obj) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (function_obj.parameters_list) {
|
|
if (function_obj.parameters_list) {
|
|
|
- function_obj.parameters_list.forEach(function(el){
|
|
|
|
|
|
|
+ function_obj.parameters_list.forEach(function(el) {
|
|
|
new_function.parameters_list.push(parseParameter(el));
|
|
new_function.parameters_list.push(parseParameter(el));
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (function_obj.variables_list) {
|
|
if (function_obj.variables_list) {
|
|
|
- function_obj.variables_list.forEach(function(el){
|
|
|
|
|
|
|
+ function_obj.variables_list.forEach(function(el) {
|
|
|
new_function.variables_list.push(parseParameter(el));
|
|
new_function.variables_list.push(parseParameter(el));
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -115,13 +115,14 @@ function printCommandText (code) {
|
|
|
// js/iassign-integration-functions.js!getiLMContent(): prepareActivityToStudent(data);
|
|
// js/iassign-integration-functions.js!getiLMContent(): prepareActivityToStudent(data);
|
|
|
export function parserCodeVisual (code_obj = null) {
|
|
export function parserCodeVisual (code_obj = null) {
|
|
|
console.log("js/util/codeParser.js!parserCodeVisual(.): code_obj has " + printCommandText(code_obj)); // JSON.stringify(code_obj));
|
|
console.log("js/util/codeParser.js!parserCodeVisual(.): code_obj has " + printCommandText(code_obj)); // JSON.stringify(code_obj));
|
|
|
- if (!code_obj || code_obj===null) { // Avoid severe error! parserCodeVisual@http://localhost/ivprog/ivprogh/js/main.ecdd914f315cb1bf2925.js:11054:5...
|
|
|
|
|
|
|
+ if (!code_obj || code_obj===null) {
|
|
|
|
|
+ // Avoid severe error! parserCodeVisual@http://localhost/ivprog/ivprogh/js/main.ecdd914f315cb1bf2925.js:11054:5...
|
|
|
console.log("js/util/codeParser.js!parserCodeVisual(.): code_obj is empty: " + code_obj); // JSON.stringify(code_obj));
|
|
console.log("js/util/codeParser.js!parserCodeVisual(.): code_obj is empty: " + code_obj); // JSON.stringify(code_obj));
|
|
|
//D console.trace();
|
|
//D console.trace();
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
// console.trace();
|
|
// console.trace();
|
|
|
- window.conteudo = code_obj
|
|
|
|
|
|
|
+ window.conteudo = code_obj;
|
|
|
|
|
|
|
|
// Globals:
|
|
// Globals:
|
|
|
window.program_obj.globals = [];
|
|
window.program_obj.globals = [];
|
|
@@ -132,12 +133,34 @@ export function parserCodeVisual (code_obj = null) {
|
|
|
code_obj.functions.forEach(parseFunction);
|
|
code_obj.functions.forEach(parseFunction);
|
|
|
|
|
|
|
|
// Commands:
|
|
// Commands:
|
|
|
- window.program_obj.functions.forEach(function(preparedFunction) {
|
|
|
|
|
- code_obj.functions.forEach(function(rawFunction) {
|
|
|
|
|
- if ((preparedFunction.name == rawFunction.name) || (!rawFunction.name && preparedFunction.name == LocalizedStrings.getUI("start"))) {
|
|
|
|
|
|
|
+ window.program_obj.functions.forEach(function (preparedFunction) {
|
|
|
|
|
+ code_obj.functions.forEach(function (rawFunction) {
|
|
|
|
|
+ if (preparedFunction.name == rawFunction.name || (!rawFunction.name && preparedFunction.name == LocalizedStrings.getUI("start"))) {
|
|
|
|
|
+
|
|
|
|
|
+ //comments: starts
|
|
|
|
|
+ if (rawFunction.variables_list && rawFunction.variables_list.length > 0) {
|
|
|
|
|
+ const newVariablesList = [];
|
|
|
|
|
+ rawFunction.variables_list.forEach(function(varItem) {
|
|
|
|
|
+ if (varItem.type === "comment") {
|
|
|
|
|
+ // This is a comment - create "Comment"
|
|
|
|
|
+ const comment = parseComment(varItem, preparedFunction);
|
|
|
|
|
+ if (comment) {
|
|
|
|
|
+ newVariablesList.push(comment);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // This is a comment - get existing variable
|
|
|
|
|
+ const existingVar = preparedFunction.variables_list.find((v) => v.name === varItem.name);
|
|
|
|
|
+ if (existingVar) {
|
|
|
|
|
+ newVariablesList.push(existingVar);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ preparedFunction.variables_list = newVariablesList;
|
|
|
|
|
+ } //comments: end
|
|
|
|
|
+
|
|
|
preparedFunction.commands = parseCommands(rawFunction.commands, preparedFunction);
|
|
preparedFunction.commands = parseCommands(rawFunction.commands, preparedFunction);
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
console.log("codeParser.js!parserCodeVisual(.): finished!");
|
|
console.log("codeParser.js!parserCodeVisual(.): finished!");
|
|
|
return true; // set to js/util/iassignHelpers.js!setPreviousAlgorithm(code) success
|
|
return true; // set to js/util/iassignHelpers.js!setPreviousAlgorithm(code) success
|
|
@@ -145,51 +168,82 @@ export function parserCodeVisual (code_obj = null) {
|
|
|
|
|
|
|
|
|
|
|
|
|
function parseCommands (commands_block, function_obj) {
|
|
function parseCommands (commands_block, function_obj) {
|
|
|
- console.log("codeParser.js!parseCommands(.): commands_block=" + printCommandText(commands_block)); // JSON.stringify(commands_block));
|
|
|
|
|
- // console.trace();
|
|
|
|
|
|
|
+ console.log("codeParser.js!parseCommands(.): commands_block=" + printCommandText(commands_block)); // "JSON.stringify(commands_block));" is infinity recursive...
|
|
|
|
|
+ //D console.trace();
|
|
|
if (Array.isArray(commands_block)) {
|
|
if (Array.isArray(commands_block)) {
|
|
|
var temp = [];
|
|
var temp = [];
|
|
|
- commands_block.forEach(function(command) {
|
|
|
|
|
- temp.push(parseCommands(command, function_obj));
|
|
|
|
|
|
|
+ commands_block.forEach(function (command) {
|
|
|
|
|
+ //comments: starts
|
|
|
|
|
+ var parsedCommand = parseCommands(command, function_obj);
|
|
|
|
|
+ if (Array.isArray(parsedCommand)) {
|
|
|
|
|
+ parsedCommand.forEach(function (decl) {
|
|
|
|
|
+ temp.push(decl);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (parsedCommand !== null) {
|
|
|
|
|
+ if (command.inlineComment && parsedCommand.type !== "comment") {
|
|
|
|
|
+ parsedCommand.inlineComment = command.inlineComment;
|
|
|
|
|
+ }
|
|
|
|
|
+ temp.push(parsedCommand);
|
|
|
|
|
+ }
|
|
|
|
|
+ //comments: end
|
|
|
});
|
|
});
|
|
|
return temp;
|
|
return temp;
|
|
|
}
|
|
}
|
|
|
- else {
|
|
|
|
|
|
|
+ else { // if (Array.isArray(commands_block))
|
|
|
|
|
+ var parsedCmd = null;
|
|
|
|
|
+
|
|
|
switch (commands_block.type) {
|
|
switch (commands_block.type) {
|
|
|
case Models.COMMAND_TYPES.reader:
|
|
case Models.COMMAND_TYPES.reader:
|
|
|
- return parseReader(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseReader(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.return:
|
|
case Models.COMMAND_TYPES.return:
|
|
|
- return parseReturn(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseReturn(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.writer:
|
|
case Models.COMMAND_TYPES.writer:
|
|
|
- return parseWriter(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseWriter(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.break:
|
|
case Models.COMMAND_TYPES.break:
|
|
|
- return parseBreak(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseBreak(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.comment:
|
|
case Models.COMMAND_TYPES.comment:
|
|
|
- return parseComment(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseComment(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.attribution:
|
|
case Models.COMMAND_TYPES.attribution:
|
|
|
- return parseAttribution(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseAttribution(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.functioncall:
|
|
case Models.COMMAND_TYPES.functioncall:
|
|
|
- return parseFunctionCall(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseFunctionCall(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.iftrue:
|
|
case Models.COMMAND_TYPES.iftrue:
|
|
|
- return parseIfTrue(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseIfTrue(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.repeatNtimes:
|
|
case Models.COMMAND_TYPES.repeatNtimes:
|
|
|
- return parseRepeatNTimes(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseRepeatNTimes(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.whiletrue:
|
|
case Models.COMMAND_TYPES.whiletrue:
|
|
|
- return parseWhileTrue(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseWhileTrue(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.dowhiletrue:
|
|
case Models.COMMAND_TYPES.dowhiletrue:
|
|
|
- return parseDoWhileTrue(commands_block, function_obj);
|
|
|
|
|
|
|
+ parsedCmd = parseDoWhileTrue(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.switch:
|
|
case Models.COMMAND_TYPES.switch:
|
|
|
- return parseSwitch(commands_block, function_obj);
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ parsedCmd = parseSwitch(commands_block, function_obj);
|
|
|
|
|
+ break;
|
|
|
|
|
+ } // switch (commands_block.type)
|
|
|
|
|
+
|
|
|
|
|
+ //comments: preserves "in-line" comments
|
|
|
|
|
+ if (parsedCmd && commands_block.inlineComment) {
|
|
|
|
|
+ parsedCmd.inlineComment = commands_block.inlineComment;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return parsedCmd;
|
|
|
|
|
+ } // else if (Array.isArray(commands_block))
|
|
|
|
|
+ } // function parseCommands(commands_block, function_obj)
|
|
|
|
|
|
|
|
|
|
|
|
|
function parseReader (command, function_obj) {
|
|
function parseReader (command, function_obj) {
|
|
|
var temp = CodeParser.expressionParserCodeVisual(command.variable, function_obj);
|
|
var temp = CodeParser.expressionParserCodeVisual(command.variable, function_obj);
|
|
|
- if (Array.isArray(temp) && temp[0])
|
|
|
|
|
- temp = temp[0];
|
|
|
|
|
|
|
+ if (Array.isArray(temp) && temp[0]) temp = temp[0];
|
|
|
return new Models.Reader(temp);
|
|
return new Models.Reader(temp);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -219,7 +273,7 @@ function parseWriter (command, function_obj) {
|
|
|
|
|
|
|
|
//0 temp = CodeParser.expressionParserCodeVisual(command.content[0], function_obj);
|
|
//0 temp = CodeParser.expressionParserCodeVisual(command.content[0], function_obj);
|
|
|
//D console.log("./ivprog/js/util/codeParser.js: parseWriter(.): #temp=" + temp.length + "; type=" + temp.type + ": temp=" + JSON.stringify(temp));
|
|
//D console.log("./ivprog/js/util/codeParser.js: parseWriter(.): #temp=" + temp.length + "; type=" + temp.type + ": temp=" + JSON.stringify(temp));
|
|
|
- return new Models.Writer(temp,command.newLine);
|
|
|
|
|
|
|
+ return new Models.Writer(temp, command.newLine);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -232,22 +286,30 @@ function parseAttribution (command, function_obj) {
|
|
|
var variable = CodeParser.expressionParserCodeVisual(command.variable, function_obj);
|
|
var variable = CodeParser.expressionParserCodeVisual(command.variable, function_obj);
|
|
|
var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
|
|
var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
|
|
|
|
|
|
|
|
- if (Array.isArray(variable))
|
|
|
|
|
- variable = variable[0];
|
|
|
|
|
|
|
+ if (Array.isArray(variable)) variable = variable[0];
|
|
|
|
|
|
|
|
return new Models.Attribution(variable, expression);
|
|
return new Models.Attribution(variable, expression);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-// By Gleyce 2025/06/23
|
|
|
|
|
|
|
+// By Gleyce 2025/06/23; Edilson 2026/01/30
|
|
|
function parseComment (command, function_obj) {
|
|
function parseComment (command, function_obj) {
|
|
|
- // return new Models.Comment(null);
|
|
|
|
|
- var comment_text = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_value, command.comment_text, null, null, false);
|
|
|
|
|
- console.log("js/util/codeParser.js!parseComment(.): comment_text=" + comment_text);
|
|
|
|
|
- if (!comment_text || comment_text === null) {
|
|
|
|
|
|
|
+ var text = command.comment || command.comment_text || command.value || command.text || "";
|
|
|
|
|
+
|
|
|
|
|
+ if (!text) {
|
|
|
|
|
+ console.warn("Comment without text!", command);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- return new Models.Comment(comment_text);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var commentTextMenu = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_value, text, null, null, false);
|
|
|
|
|
+ var commentObj = new Models.Comment(commentTextMenu);
|
|
|
|
|
+
|
|
|
|
|
+ commentObj.comment = text;
|
|
|
|
|
+ commentObj.value = text;
|
|
|
|
|
+ commentObj._text = text;
|
|
|
|
|
+ commentObj.comment_text = commentTextMenu;
|
|
|
|
|
+
|
|
|
|
|
+ return commentObj;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -266,7 +328,7 @@ function parseFunctionCall (command, function_obj) {
|
|
|
var temp = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false);
|
|
var temp = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false);
|
|
|
temp.function_called = function_called;
|
|
temp.function_called = function_called;
|
|
|
temp.parameters_list = parameters;
|
|
temp.parameters_list = parameters;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return new Models.FunctionCall(temp, null);
|
|
return new Models.FunctionCall(temp, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -293,8 +355,8 @@ function parseRepeatNTimes (command, function_obj) {
|
|
|
if (expression2[0].item == 'minus') {
|
|
if (expression2[0].item == 'minus') {
|
|
|
expression2 = expression2[1];
|
|
expression2 = expression2[1];
|
|
|
expression2.content *= -1;
|
|
expression2.content *= -1;
|
|
|
- } else
|
|
|
|
|
- expression2 = expression2[0];
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else expression2 = expression2[0];
|
|
|
|
|
|
|
|
var var_step = CodeParser.expressionParserCodeVisual(command.step_expression, function_obj);
|
|
var var_step = CodeParser.expressionParserCodeVisual(command.step_expression, function_obj);
|
|
|
|
|
|
|
@@ -302,7 +364,7 @@ function parseRepeatNTimes (command, function_obj) {
|
|
|
|
|
|
|
|
var operator = command.step_expression[0].value == '+' ? Models.ARITHMETIC_TYPES.plus : Models.ARITHMETIC_TYPES.minus;
|
|
var operator = command.step_expression[0].value == '+' ? Models.ARITHMETIC_TYPES.plus : Models.ARITHMETIC_TYPES.minus;
|
|
|
|
|
|
|
|
- var expression3 = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.exp_op_exp, [ null, operator, var_step[1] ]);
|
|
|
|
|
|
|
+ var expression3 = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.exp_op_exp, [null, operator, var_step[1]]);
|
|
|
console.log("codeParser.js!parseRepeatNTimes(.): expression3=" + expression3);
|
|
console.log("codeParser.js!parseRepeatNTimes(.): expression3=" + expression3);
|
|
|
|
|
|
|
|
return new Models.RepeatNTimes(
|
|
return new Models.RepeatNTimes(
|
|
@@ -336,7 +398,7 @@ function parseSwitch (command, function_obj) {
|
|
|
|
|
|
|
|
var sc = [];
|
|
var sc = [];
|
|
|
if (command.cases) {
|
|
if (command.cases) {
|
|
|
- command.cases.forEach(function(case_el) {
|
|
|
|
|
|
|
+ command.cases.forEach(function (case_el) {
|
|
|
var temp_exp = CodeParser.expressionParserCodeVisual(case_el.expression, function_obj);
|
|
var temp_exp = CodeParser.expressionParserCodeVisual(case_el.expression, function_obj);
|
|
|
var temp_commands = parseCommands(case_el.commands, function_obj);
|
|
var temp_commands = parseCommands(case_el.commands, function_obj);
|
|
|
var temp_case = new Models.SwitchCase(temp_exp[0], temp_commands);
|
|
var temp_case = new Models.SwitchCase(temp_exp[0], temp_commands);
|