Browse Source

Implement char type into the visual UI

Add ui strings charvar_default_value and type_char

Change  function name in lang pt to a more appropriate since its return type was changed to char
Lucas de Souza 4 years ago
parent
commit
3bbd21ccb9

+ 1 - 1
grammar/pt/langFunctions.js

@@ -11,7 +11,7 @@ export default {
   $length: "comprimento",
   $uppercase: "caixa_alta",
   $lowercase: "caixa_baixa",
-  $charAt: "texto_na_posicao",
+  $charAt: "caractere_na_posicao",
   $isReal: "e_real",
   $isInt: "e_inteiro",
   $isBool: "e_logico",

+ 3 - 1
i18n/ui.csv

@@ -137,4 +137,6 @@ text_for_from,de,from,
 text_for_to,até,to,
 text_for_pass,passo,pass,
 text_relational_expression,Relacionais,Relational,
-initial_program_code,"programa {\n\n\t\tfuncao vazio inicio () {\n\t\t\t// Inicie seu codigo aqui!\n\t\t}\n}","program {\n\n\t\tfunction void main () {\n\t\t\t// Start your code here!\n\t\t}\n}",
+initial_program_code,programa {\n\n\t\tfuncao vazio inicio () {\n\t\t\t// Inicie seu codigo aqui!\n\t\t}\n},program {\n\n\t\tfunction void main () {\n\t\t\t// Start your code here!\n\t\t}\n},
+type_char,caractere,char,""
+charvar_default_value,A,A,A

+ 79 - 0
js/visualUI/code_generator.js

@@ -52,6 +52,8 @@ function functionsCode (function_obj) {
 		case Types.BOOLEAN:
 			ret += LocalizedStrings.getUI('type_boolean');
 			break;
+		case Types.CHAR:
+			ret += LocalizedStrings.getUI('type_char');
 		case Types.VOID:
 			ret += LocalizedStrings.getUI('type_void');
 			break;
@@ -771,6 +773,9 @@ function parametersCode (parameter_obj) {
 		case Types.BOOLEAN:
 			ret += ' '+LocalizedStrings.getUI('type_boolean')+' ';
 			break;
+		case Types.CHAR:
+			ret += ' '+LocalizedStrings.getUI('type_char')+' ';
+			break;
 	}
 	ret += parameter_obj.name + '';
 
@@ -805,6 +810,9 @@ function variablesCode (variable_obj) {
 		case Types.BOOLEAN:
 			ret += LocalizedStrings.getUI('type_boolean')+' ';
 			break;
+		case Types.CHAR:
+			ret += ' '+LocalizedStrings.getUI('type_char')+' ';
+			break;
 	}
 	ret += temp.name + ' ';
 
@@ -856,6 +864,16 @@ function variablesCode (variable_obj) {
 				}
 				ret += '}';
 				break;
+			case Types.CHAR:
+				ret += '<- {';
+				for (var j = 0; j < temp.value.length; j++) {
+					ret += '\''+temp.value[j]+'\'';
+					if ((j + 1) < temp.value.length) {
+						ret += ', ';
+					}
+				}
+				ret += '}';
+				break;
 		}
 
 	} else if (temp.dimensions == 2) {
@@ -952,6 +970,27 @@ function variablesCode (variable_obj) {
 				}
 				ret += '}';
 				break;
+			case Types.CHAR:
+				ret += '<- {';
+
+				for (var j = 0; j < temp.rows; j++) {
+					ret += '{';
+
+					for (var k = 0; k < temp.columns; k++) {
+						ret += '\'' + temp.value[j][k] + '\'';
+
+						if ((k + 1) < temp.columns) {
+							ret += ', ';
+						}
+					}
+
+					ret += '}';
+					if ((j + 1) < temp.rows) {
+						ret += ', ';
+					}
+				}
+				ret += '}';
+				break;
 		}
 	} else {
 
@@ -973,6 +1012,9 @@ function variablesCode (variable_obj) {
 					ret += LocalizedStrings.getUI('logic_value_false');
 				}
 				break;
+			case Types.CHAR:
+				ret += '<- \'' + temp.value + '\'';
+				break;
 		}
 
 	}
@@ -1006,6 +1048,9 @@ function globalsCode () {
 				case Types.BOOLEAN:
 					ret += LocalizedStrings.getUI('type_boolean');
 					break;
+				case Types.CHAR:
+					ret += LocalizedStrings.getUI('type_char');
+					break;
 			}
 			ret += ' ' + temp.name + ' ';
 
@@ -1057,6 +1102,16 @@ function globalsCode () {
 						}
 						ret += '}';
 						break;
+					case Types.CHAR:
+						ret += '<- {';
+						for (var j = 0; j < temp.value.length; j++) {
+							ret += '\''+temp.value[j]+'\'';
+							if ((j + 1) < temp.value.length) {
+								ret += ', ';
+							}
+						}
+						ret += '}';
+						break;
 				}
 
 			} else if (temp.dimensions == 2) {
@@ -1153,6 +1208,27 @@ function globalsCode () {
 						}
 						ret += '}';
 						break;
+					case Types.CHAR:
+						ret += '<- {';
+
+						for (var j = 0; j < temp.rows; j++) {
+							ret += '{';
+
+							for (var k = 0; k < temp.columns; k++) {
+								ret += '\'' + temp.value[j][k] + '\'';
+
+								if ((k + 1) < temp.columns) {
+									ret += ', ';
+								}
+							}
+
+							ret += '}';
+							if ((j + 1) < temp.rows) {
+								ret += ', ';
+							}
+						}
+						ret += '}';
+						break;
 				}
 			} else {
 
@@ -1174,6 +1250,9 @@ function globalsCode () {
 							ret += LocalizedStrings.getUI('logic_value_false');;
 						}
 						break;
+					case Types.CHAR:
+						ret += '<- \'' + temp.value + '\'';
+						break;
 				}
 
 			}

File diff suppressed because it is too large
+ 3 - 1
js/visualUI/functions.js


+ 34 - 1
js/visualUI/globals.js

@@ -133,7 +133,19 @@ function updateInitialValues (global_var) {
 			global_var.value = [[true, true], [true, true]];
 		}
 	}
-	registerSystemEvent(function_name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.name,
+
+	if (global_var.type == Types.CHAR) {
+		if (global_var.dimensions == 0) {
+			global_var.value = 'A';
+		}
+		if (global_var.dimensions == 1) {
+			global_var.value = ['A', 'A'];
+		}
+		if (global_var.dimensions == 2) {
+			global_var.value = [['A', 'A'], ['A', 'A']];
+		}
+	}
+	registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.name,
 		global_var.value);
 }
 
@@ -171,6 +183,10 @@ function addGlobalColumnVector (global_var) {
 	if (global_var.type == Types.BOOLEAN) {
 		global_var.value.push(true);
 	}
+
+	if (global_var.type == Types.CHAR) {
+		global_var.value.push(LocalizedStrings.getUI('charvar_default_value'));
+	}
 }
 
 function removeColumnGlobalMatrix (global_var) {
@@ -208,6 +224,11 @@ function addColumnGlobalMatrix (global_var) {
 			global_var.value[i].push(true);
 		}
 	}
+	if (global_var.type == Types.CHAR) {
+		for (var i = 0; i < global_var.rows; i++) {
+			global_var.value[i].push(LocalizedStrings.getUI('charvar_default_value'));
+		}
+	}
 }
 
 function removeLineGlobalMatrix (global_var) {
@@ -252,6 +273,14 @@ function addLineGlobalMatrix (global_var) {
 		}
 		global_var.value.push(n_l);
 	}
+
+	if (global_var.type == Types.CHAR) {
+		var n_l = [];
+		for (i = 0; i < global_var.columns; i++) {
+			n_l.push(LocalizedStrings.getUI('charvar_default_value'));
+		}
+		global_var.value.push(n_l);
+	}
 }
 
 function alternateBooleanGlobalMatrixValue (global_var, row, index, value_container) {
@@ -734,6 +763,8 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 			} else{
 				if (global_var.type == Types.INTEGER) {
 					global_var.value = parseInt(input_field.val().trim());
+				} else if (var_obj.type == Types.CHAR) {
+					var_obj.value = input_field.val().charAt(0);
 				} else {
 					global_var.value = input_field.val().trim();
 				}
@@ -776,6 +807,8 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 				} else {
 					if (global_var.type == Types.INTEGER) {
 						global_var.value = parseInt(input_field.val().trim());
+					} else if (var_obj.type == Types.CHAR) {
+						var_obj.value = input_field.val().charAt(0);
 					} else {
 						global_var.value = input_field.val().trim();
 					}

+ 1 - 0
js/visualUI/types.js

@@ -2,6 +2,7 @@ export const Types = Object.freeze({
   INTEGER: "integer",
   REAL: "real",
   TEXT: "text",
+  CHAR: 'char',
   BOOLEAN: "boolean",
   VOID: "void"
 });

+ 32 - 0
js/visualUI/variables.js

@@ -415,6 +415,14 @@ function addLineMatrix (var_obj) {
 		}
 		var_obj.value.push(n_l);
 	}
+
+	if (var_obj.type == Types.CHAR) {
+		var n_l = [];
+		for (i = 0; i < var_obj.columns; i++) {
+			n_l.push(LocalizedStrings.getUI('charvar_default_value'));
+		}
+		var_obj.value.push(n_l);
+	}
 }
 
 function removeLineMatrix (var_obj) {
@@ -449,6 +457,11 @@ function addColumnMatrix (var_obj) {
 			var_obj.value[i].push(true);
 		}
 	}
+	if (var_obj.type == Types.CHAR) {
+		for (var i = 0; i < var_obj.rows; i++) {
+			var_obj.value[i].push(LocalizedStrings.getUI('charvar_default_value'));
+		}
+	}
 }
 
 function removeColumnMatrix (var_obj) {
@@ -478,6 +491,9 @@ function addColumnVector (var_obj) {
 	if (var_obj.type == Types.BOOLEAN) {
 		var_obj.value.push(true);
 	}
+	if (var_obj.type == Types.CHAR) {
+		var_obj.value.push(LocalizedStrings.getUI('charvar_default_value'));
+	}
 }
 
 function removeColumnVector (var_obj) {
@@ -548,6 +564,18 @@ function updateInitialValues (variable_obj, function_name) {
 			variable_obj.value = [[true, true], [true, true]];
 		}
 	}
+
+	if (variable_obj.type == Types.CHAR) {
+		if (variable_obj.dimensions == 0) {
+			variable_obj.value = 'A';
+		}
+		if (variable_obj.dimensions == 1) {
+			variable_obj.value = ['A', 'A'];
+		}
+		if (variable_obj.dimensions == 2) {
+			variable_obj.value = [['A', 'A'], ['A', 'A']];
+		}
+	}
 	registerSystemEvent(function_name, ActionTypes.CHANGE_VAR_VALUE, variable_obj.name, variable_obj.value);
 }
 
@@ -742,6 +770,8 @@ function enableValueUpdate (var_obj, parent_node, function_name) {
 			} else{
 				if (var_obj.type == Types.INTEGER) {
 					var_obj.value = parseInt(input_field.val().trim());
+				} else if (var_obj.type == Types.CHAR) {
+					var_obj.value = input_field.val().charAt(0);
 				} else {
 					var_obj.value = input_field.val().trim();
 				}
@@ -785,6 +815,8 @@ function enableValueUpdate (var_obj, parent_node, function_name) {
 				} else{
 					if (var_obj.type == Types.INTEGER) {
 						var_obj.value = parseInt(input_field.val().trim());
+					} else if (var_obj.type == Types.CHAR) {
+						var_obj.value = input_field.val().charAt(0);
 					} else {
 						var_obj.value = input_field.val().trim();
 					}