|
@@ -1,6 +1,8 @@
|
|
|
|
|
|
import * as Models from '../visualUI/ivprog_elements';
|
|
|
import { LocalizedStrings } from "./../services/localizedStringsService";
|
|
|
+import * as VariableValueMenuManagement from '../visualUI/commands/variable_value_menu';
|
|
|
+import * as CodeParser from '../visualUI/commands/generic_expression';
|
|
|
|
|
|
function parseBoolean (var_value, dimensions) {
|
|
|
if (dimensions == 0)
|
|
@@ -92,15 +94,12 @@ function parseFunction (function_obj) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- new_function.commands = parseCommands(function_obj.commands)
|
|
|
-
|
|
|
window.program_obj.addFunction(new_function);
|
|
|
|
|
|
}
|
|
|
|
|
|
export function parserCodeVisual (code_obj = null) {
|
|
|
|
|
|
- console.log('chegou!', code_obj)
|
|
|
window.conteudo = code_obj
|
|
|
|
|
|
// Globals:
|
|
@@ -111,21 +110,129 @@ export function parserCodeVisual (code_obj = null) {
|
|
|
window.program_obj.functions = [];
|
|
|
code_obj.functions.forEach(parseFunction);
|
|
|
|
|
|
-}
|
|
|
+ // 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"))) {
|
|
|
+ preparedFunction.commands = parseCommands(rawFunction.commands, preparedFunction);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
|
|
|
-function parseCommands (commands_block) {
|
|
|
+}
|
|
|
|
|
|
- console.log('bloco', commands_block)
|
|
|
+function parseCommands (commands_block, function_obj) {
|
|
|
|
|
|
if (Array.isArray(commands_block)) {
|
|
|
var temp = [];
|
|
|
commands_block.forEach(function(command) {
|
|
|
- temp.push(parseCommands(command));
|
|
|
+ temp.push(parseCommands(command, function_obj));
|
|
|
});
|
|
|
return temp;
|
|
|
}
|
|
|
else {
|
|
|
+ switch (commands_block.type) {
|
|
|
+ case Models.COMMAND_TYPES.reader:
|
|
|
+ return parseReader(commands_block, function_obj);
|
|
|
+
|
|
|
+ case Models.COMMAND_TYPES.return:
|
|
|
+ return parseReturn(commands_block, function_obj);
|
|
|
+
|
|
|
+ case Models.COMMAND_TYPES.writer:
|
|
|
+ return parseWriter(commands_block, function_obj);
|
|
|
+
|
|
|
+ case Models.COMMAND_TYPES.break:
|
|
|
+ return parseBreak(commands_block, function_obj);
|
|
|
+
|
|
|
+ case Models.COMMAND_TYPES.comment:
|
|
|
+ return parseComment(commands_block, function_obj);
|
|
|
+
|
|
|
+ case Models.COMMAND_TYPES.attribution:
|
|
|
+ return parseAttribution(commands_block, function_obj);
|
|
|
+
|
|
|
+ case Models.COMMAND_TYPES.functioncall:
|
|
|
+ return parseFunctionCall(commands_block, function_obj);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
+function parseReader (command, function_obj) {
|
|
|
+ var temp = CodeParser.expressionParserCodeVisual(command.variable, function_obj);
|
|
|
+
|
|
|
+ if (Array.isArray(temp) && temp[0])
|
|
|
+ temp = temp[0];
|
|
|
+
|
|
|
+ return new Models.Reader(
|
|
|
+ temp
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function parseReturn (command, function_obj) {
|
|
|
+
|
|
|
+ var temp = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
|
|
|
+
|
|
|
+ return new Models.Return(
|
|
|
+ temp
|
|
|
+ );
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function parseWriter (command, function_obj) {
|
|
|
+
|
|
|
+ var temp = CodeParser.expressionParserCodeVisual(command.content[0], function_obj);
|
|
|
+
|
|
|
+ return new Models.Writer(
|
|
|
+ temp,
|
|
|
+ command.newLine
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function parseBreak (command, function_obj) {
|
|
|
+ return new Models.Break();
|
|
|
+}
|
|
|
+
|
|
|
+function parseAttribution (command, function_obj) {
|
|
|
+
|
|
|
+ var variable = CodeParser.expressionParserCodeVisual(command.variable, function_obj);
|
|
|
+ var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
|
|
|
+
|
|
|
+ if (Array.isArray(variable))
|
|
|
+ variable = variable[0];
|
|
|
+
|
|
|
+ return new Models.Attribution(
|
|
|
+ variable,
|
|
|
+ expression
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function parseComment(command, function_obj) {
|
|
|
+ // TODO
|
|
|
+ return new Models.Comment(
|
|
|
+ null
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function parseFunctionCall (command, function_obj) {
|
|
|
+
|
|
|
+ var parameters = CodeParser.expressionParserCodeVisual(command.parameters_list[0], function_obj);
|
|
|
+ var function_called = CodeParser.searchFunction(command.name);
|
|
|
+
|
|
|
+ //function_called.parameters_list = parameters;
|
|
|
+
|
|
|
+ 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
|
|
|
+ );
|
|
|
+
|
|
|
+ //new Models.FunctionCall(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false), null
|
|
|
}
|