|
@@ -4,6 +4,7 @@ import { LocalizedStrings } from "../../services/localizedStringsService";
|
|
import * as VariableValueMenuManagement from "./variable_value_menu";
|
|
import * as VariableValueMenuManagement from "./variable_value_menu";
|
|
import { registerUserEvent, ActionTypes } from "../../services/userLog";
|
|
import { registerUserEvent, ActionTypes } from "../../services/userLog";
|
|
import WatchJS from "melanke-watchjs";
|
|
import WatchJS from "melanke-watchjs";
|
|
|
|
+import * as Utils from '../utils';
|
|
|
|
|
|
window.timer = false;
|
|
window.timer = false;
|
|
|
|
|
|
@@ -1302,3 +1303,161 @@ function getSeparator () {
|
|
"write_seprator_menu_text"
|
|
"write_seprator_menu_text"
|
|
)}</div>`;
|
|
)}</div>`;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+function getVariable (function_obj, search) {
|
|
|
|
+ if (search == ")" || search == "(") {
|
|
|
|
+ return search;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (search.instance == "operator") {
|
|
|
|
+ var obj;
|
|
|
|
+ switch (search.value) {
|
|
|
|
+ case '+':
|
|
|
|
+ obj = new Models.ExpressionOperator(
|
|
|
|
+ Models.EXPRESSION_TYPES.exp_arithmetic,
|
|
|
|
+ Models.ARITHMETIC_TYPES.plus);
|
|
|
|
+ break;
|
|
|
|
+ case '-':
|
|
|
|
+ obj = new Models.ExpressionOperator(
|
|
|
|
+ Models.EXPRESSION_TYPES.exp_arithmetic,
|
|
|
|
+ Models.ARITHMETIC_TYPES.minus);
|
|
|
|
+ break;
|
|
|
|
+ case '*':
|
|
|
|
+ obj = new Models.ExpressionOperator(
|
|
|
|
+ Models.EXPRESSION_TYPES.exp_arithmetic,
|
|
|
|
+ Models.ARITHMETIC_TYPES.multiplication);
|
|
|
|
+ break;
|
|
|
|
+ case '/':
|
|
|
|
+ obj = new Models.ExpressionOperator(
|
|
|
|
+ Models.EXPRESSION_TYPES.exp_arithmetic,
|
|
|
|
+ Models.ARITHMETIC_TYPES.division);
|
|
|
|
+ break;
|
|
|
|
+ case '%':
|
|
|
|
+ obj = new Models.ExpressionOperator(
|
|
|
|
+ Models.EXPRESSION_TYPES.exp_arithmetic,
|
|
|
|
+ Models.ARITHMETIC_TYPES.module);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ return obj;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (search.instance == "expression"
|
|
|
|
+ && search.type == "const") {
|
|
|
|
+ var obj = new Models.VariableValueMenu(
|
|
|
|
+ VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
|
|
|
|
+ search.value,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ true
|
|
|
|
+ );
|
|
|
|
+ return obj;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var variavel = null;
|
|
|
|
+ if (search.instance == "expression"
|
|
|
|
+ && search.type == "var") {
|
|
|
|
+ // 1. Procurar a variável na função:
|
|
|
|
+ for (var j = 0; j < function_obj.variables_list.length; j++) {
|
|
|
|
+ if (function_obj.variables_list[j].name == search.value) {
|
|
|
|
+ variavel = function_obj.variables_list[j];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2. Procurar a variável nas gloais:
|
|
|
|
+ if (!variavel)
|
|
|
|
+ for (var j = 0; j < program_obj.globals.length; j++) {
|
|
|
|
+ if (program_obj.globals[j].name == search.value) {
|
|
|
|
+ variavel = program_obj.globals[j];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (search.instance == "expression"
|
|
|
|
+ && search.type == "var"
|
|
|
|
+ && !search.line) {
|
|
|
|
+
|
|
|
|
+ var obj = new Models.VariableValueMenu(
|
|
|
|
+ VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
|
|
|
|
+ variavel,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ true
|
|
|
|
+ );
|
|
|
|
+ return obj;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (search.instance == "expression"
|
|
|
|
+ && search.type == "var"
|
|
|
|
+ && search.class == "vector") {
|
|
|
|
+ /*
|
|
|
|
+ variable_and_value = 7,
|
|
|
|
+ content = null,
|
|
|
|
+ row = null,
|
|
|
|
+ column = null,
|
|
|
|
+ include_constant = true,
|
|
|
|
+ dimensions = 0
|
|
|
|
+ */
|
|
|
|
+ var obj = new Models.VariableValueMenu(
|
|
|
|
+ VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
|
|
|
|
+ variavel,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ true
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function expressionParserToVisual (text, function_obj, input_field) {
|
|
|
|
+ var var_not_found = [];
|
|
|
|
+ var parsed;
|
|
|
|
+ try {
|
|
|
|
+ parsed = ivprogCore.parseExpression(text);
|
|
|
|
+ } catch (ex) {
|
|
|
|
+ Utils.renderErrorMessage(input_field, LocalizedStrings.getUI('expression_invalid'));
|
|
|
|
+ }
|
|
|
|
+ if (!parsed) return null;
|
|
|
|
+
|
|
|
|
+ for (var i = 0; i < parsed.length; i++) {
|
|
|
|
+ var variavel = null;
|
|
|
|
+ if (parsed[i].instance == "expression"
|
|
|
|
+ && parsed[i].type == "var") {
|
|
|
|
+ // 1. Procurar a variável na função:
|
|
|
|
+ for (var j = 0; j < function_obj.variables_list.length; j++) {
|
|
|
|
+ if (function_obj.variables_list[j].name == parsed[i].value) {
|
|
|
|
+ variavel = function_obj.variables_list[j];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2. Procurar a variável nas gloais:
|
|
|
|
+ if (!variavel)
|
|
|
|
+ for (var j = 0; j < program_obj.globals.length; j++) {
|
|
|
|
+ if (program_obj.globals[j].name == parsed[i].value) {
|
|
|
|
+ variavel = program_obj.globals[j];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!variavel)
|
|
|
|
+ var_not_found.push(parsed[i].value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (var_not_found.length > 0) {
|
|
|
|
+ let uniqueWords = [...new Set(var_not_found)];
|
|
|
|
+ Utils.renderErrorMessage(input_field, LocalizedStrings.getUI('expression_undelcared_variable') + " " + uniqueWords.join(", "));
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var exp_obj = [];
|
|
|
|
+ for (var i = 0; i < parsed.length; i++) {
|
|
|
|
+ exp_obj.push(getVariable(function_obj, parsed[i]));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return exp_obj;
|
|
|
|
+}
|