Browse Source

Merge branch 'enhance-errorClasses' of LInE/iVProg into master

GitAdmin 3 years ago
parent
commit
e9fa728ef8

+ 12 - 4
js/ast/error/syntaxError.js

@@ -1,8 +1,16 @@
 export class SyntaxError extends Error {
-
-  constructor (...msg) {
+  constructor (msg, id) {
     super(...msg);
-    if(Error.captureStackTrace)
-      Error.captureStackTrace(this, SyntaxError);
+    this.id = id;
+    this._context = {};
+    if (Error.captureStackTrace) Error.captureStackTrace(this, SyntaxError);
+  }
+
+  get context () {
+    return this._context;
+  }
+
+  set context (contextObj) {
+    this._context = contextObj;
   }
 }

+ 93 - 34
js/ast/error/syntaxErrorFactory.js

@@ -1,128 +1,187 @@
-import * as LocalizedStringsService from './../../services/localizedStringsService';
-import { SyntaxError } from './syntaxError';
+import * as LocalizedStringsService from "./../../services/localizedStringsService";
+import { SyntaxError } from "./syntaxError";
 
 const LocalizedStrings = LocalizedStringsService.getInstance();
 
 function createError (message_id, context = []) {
-  return new SyntaxError(LocalizedStrings.getError(message_id, context));
+  return new SyntaxError(
+    LocalizedStrings.getError(message_id, context),
+    message_id
+  );
 }
 
 export const SyntaxErrorFactory = Object.freeze({
   extra_lines: () => new SyntaxError(LocalizedStrings.getError("extra_lines")),
   token_missing_one: (expected, token) => {
     const context = [expected, token.text, token.line, token.column];
-    return createError("token_missing_one", context);
+    const error = createError("token_missing_one", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   token_missing_list: (expectedList, token) => {
     const line = expectedList.join(LocalizedStrings.getOR());
-    return SyntaxErrorFactory.token_missing_one(line, token);
+    const error = SyntaxErrorFactory.token_missing_one(line, token);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   id_missing: (token) => {
     const context = [token.text, token.line, token.column];
-    return createError("id_missing", context);
+    const error = createError("id_missing", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   eos_missing: (token) => {
     const context = [token.line, token.column];
-    return createError("eos_missing", context);
+    const error = createError("eos_missing", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_array_dimension: (typeName, token) => {
     const context = [token.line, token.column, typeName];
-    return createError("invalid_array_dimension", context);
+    const error = createError("invalid_array_dimension", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_array_size: (token) => {
     const context = [token.line];
-    return createError("invalid_array_size", context);
+    const error = createError("invalid_array_size", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_main_return: (name, typeName, token) => {
     const context = [name, typeName, token.line];
-    return createError("invalid_main_return", context);
+    const error = createError("invalid_main_return", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_var_declaration: (token) => {
     const context = [token.line];
-    return createError("invalid_var_declaration", context);
+    const error = createError("invalid_var_declaration", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_break_command: (cmdName, token) => {
     const context = [token.line, cmdName];
-    return createError("invalid_break_command", context);
+    const error = createError("invalid_break_command", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_terminal: (token) => {
     const context = [token.text, token.line, token.column];
-    return createError('invalid_terminal', context);
+    const error = createError("invalid_terminal", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_type: (list, token) => {
     const line = list.join(LocalizedStrings.getOR());
-    const context = [token.text, token.line, token.column, line]
-    return createError("invalid_type", context);
+    const context = [token.text, token.line, token.column, line];
+    const error = createError("invalid_type", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   const_not_init: (token) => {
     const context = [token.line, token.column];
-    return createError("const_not_init", context);
+    const error = createError("const_not_init", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_id_format: (token) => {
     const context = [token.text, token.line, token.column];
-    return createError("invalid_id_format", context);
+    const error = createError("invalid_id_format", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   duplicate_function: (token) => {
     const context = [token.text, token.line, token.column];
-    return createError("duplicate_function", context);
+    const error = createError("duplicate_function", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   main_parameters: () => {
     return createError("main_parameters");
   },
   duplicate_variable: (token) => {
     const context = [token.text, token.line, token.column];
-    return createError("duplicate_variable", context);
+    const error = createError("duplicate_variable", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
-  invalid_character: (text, line, _column) => {
+  invalid_character: (text, line, column) => {
     const context = [text, line];
-    return createError("invalid_character", context);
+    const error = createError("invalid_character", context);
+    error.context = { line: line, column: column };
+    return error;
   },
   annonymous_array_literal: (token) => {
     const context = [token.line];
-    return createError("annonymous_array_literal", context);
+    const error = createError("annonymous_array_literal", context);
+    error.context = { line: token.line, column: token.column };
+    return error;
   },
   invalid_matrix_literal_line: (exp, sourceInfo) => {
     const context = [exp, sourceInfo.line];
-    return createError("invalid_matrix_literal_line", context);
+    const error = createError("invalid_matrix_literal_line", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   cannot_infer_matrix_line: (name, sourceInfo) => {
     const context = [name, sourceInfo.line];
-    return createError("cannot_infer_matrix_line", context);
+    const error = createError("cannot_infer_matrix_line", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   cannot_infer_matrix_column: (name, sourceInfo) => {
     const context = [name, sourceInfo.line];
-    return createError("cannot_infer_matrix_column", context);
+    const error = createError("cannot_infer_matrix_column", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   cannot_infer_vector_size: (name, sourceInfo) => {
     const context = [name, sourceInfo.line];
-    return createError("cannot_infer_vector_size", context);
+    const error = createError("cannot_infer_vector_size", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   matrix_to_vector_literal_attr: (name, exp, sourceInfo) => {
     const context = [sourceInfo.line, exp, name];
-    return createError("matrix_to_vector_literal_attr", context);
+    const error = createError("matrix_to_vector_literal_attr", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   vector_to_matrix_literal_attr: (name, exp, sourceInfo) => {
     const context = [sourceInfo.line, exp, name];
-    return createError("vector_to_matrix_literal_attr", context);
+    const error = createError("vector_to_matrix_literal_attr", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   array_init_not_literal: (sourceInfo) => {
     const context = [sourceInfo.line];
-    return createError("array_init_not_literal", context);
+    const error = createError("array_init_not_literal", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   array_exceeds_2d: (sourceInfo) => {
     const context = [sourceInfo.line];
-    return createError("array_exceeds_2d", context);
+    const error = createError("array_exceeds_2d", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   invalid_matrix_id_dimension: (sourceInfo) => {
     const context = [sourceInfo.line];
-    return createError("invalid_matrix_id_dimension", context);
+    const error = createError("invalid_matrix_id_dimension", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   invalid_vector_init: (sourceInfo) => {
     const context = [sourceInfo.line];
-    return createError("invalid_vector_init", context);
+    const error = createError("invalid_vector_init", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
   },
   invalid_matrix_init: (sourceInfo) => {
     const context = [sourceInfo.line];
-    return createError("invalid_matrix_init", context);
-  }
+    const error = createError("invalid_matrix_init", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
+  },
 });

+ 495 - 157
js/processor/error/processorErrorFactory.js

@@ -1,23 +1,28 @@
-import { RuntimeError } from './runtimeError';
-import { SemanticError } from './semanticError';
-import * as  LocalizedStringsService from './../../services/localizedStringsService';
-import { LanguageDefinedFunction } from '../definedFunctions';
+import { RuntimeError } from "./runtimeError";
+import { SemanticError } from "./semanticError";
+import * as LocalizedStringsService from "./../../services/localizedStringsService";
+import { LanguageDefinedFunction } from "../definedFunctions";
 
 const LocalizedStrings = LocalizedStringsService.getInstance();
 
 function createRuntimeError (i18n_id, context = []) {
-  return new RuntimeError(LocalizedStrings.getError(i18n_id, context))
+  return new RuntimeError(LocalizedStrings.getError(i18n_id, context), i18n_id);
 }
 
 function createSemanticError (i18n_id, context = []) {
-  return new SemanticError(LocalizedStrings.getError(i18n_id, context))
+  return new SemanticError(
+    LocalizedStrings.getError(i18n_id, context),
+    i18n_id
+  );
 }
 
-export const ProcessorErrorFactory  = Object.freeze({
+export const ProcessorErrorFactory = Object.freeze({
   symbol_not_found_full: (id, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [id, sourceInfo.line, sourceInfo.column];
-      return createSemanticError("symbol_not_found_full", context);
+      const error = createSemanticError("symbol_not_found_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.symbol_not_found(id);
     }
@@ -27,9 +32,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("symbol_not_found", context);
   },
   function_missing_full: (id, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [id, sourceInfo.line, sourceInfo.column];
-      return createSemanticError("function_missing_full", context);
+      const error = createSemanticError("function_missing_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.function_missing(id);
     }
@@ -42,9 +49,14 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("main_missing");
   },
   array_dimension_not_int_full: (sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line];
-      return createSemanticError("array_dimension_not_int_full", context);
+      const error = createSemanticError(
+        "array_dimension_not_int_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.array_dimension_not_int();
     }
@@ -52,36 +64,69 @@ export const ProcessorErrorFactory  = Object.freeze({
   array_dimension_not_int: () => {
     return createSemanticError("array_dimension_not_int");
   },
-  unknown_command_full: (sourceInfo)=> {
-    if(sourceInfo) {
+  unknown_command_full: (sourceInfo) => {
+    if (sourceInfo) {
       const context = [sourceInfo.line];
-      return createRuntimeError("unknown_command_full", context);
+      const error = createRuntimeError("unknown_command_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.unknown_command();
     }
-    
   },
-  unknown_command: ()=> {
+  unknown_command: () => {
     return createRuntimeError("unknown_command");
   },
-  incompatible_types_full: (left_type, left_dim, right_type, right_dim, exp, source_info) => {
-    if(source_info) {
-      const context = [LocalizedStrings.translateType(left_type, left_dim), exp, source_info.line,
-        LocalizedStrings.translateType(right_type, right_dim)];
-      return createSemanticError("incompatible_types_full", context);
-    } else {
-      return ProcessorErrorFactory.incompatible_types(left_type, left_dim, right_type, right_dim, exp);
+  incompatible_types_full: (
+    left_type,
+    left_dim,
+    right_type,
+    right_dim,
+    exp,
+    source_info
+  ) => {
+    if (source_info) {
+      const context = [
+        LocalizedStrings.translateType(left_type, left_dim),
+        exp,
+        source_info.line,
+        LocalizedStrings.translateType(right_type, right_dim),
+      ];
+      const error = createSemanticError("incompatible_types_full", context);
+      error.context = { line: source_info.line, column: source_info.column };
+      return error;
+    } else {
+      return ProcessorErrorFactory.incompatible_types(
+        left_type,
+        left_dim,
+        right_type,
+        right_dim,
+        exp
+      );
     }
   },
   incompatible_types: (left_type, left_dim, right_type, right_dim, exp) => {
-    const context = [LocalizedStrings.translateType(left_type, left_dim), exp,
-      LocalizedStrings.translateType(right_type, right_dim)];
+    const context = [
+      LocalizedStrings.translateType(left_type, left_dim),
+      exp,
+      LocalizedStrings.translateType(right_type, right_dim),
+    ];
     return createSemanticError("incompatible_types", context);
   },
   incompatible_types_array_full: (exp, type, dim, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [exp, LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];
-      return createSemanticError("incompatible_types_array_full", context);
+    if (sourceInfo) {
+      const context = [
+        exp,
+        LocalizedStrings.translateType(type, dim),
+        sourceInfo.line,
+        sourceInfo.column,
+      ];
+      const error = createSemanticError(
+        "incompatible_types_array_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.incompatible_types_array(exp, type, dim);
     }
@@ -91,9 +136,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("incompatible_types_array", context);
   },
   loop_condition_type_full: (exp, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, sourceInfo.column, exp];
-      return createSemanticError("loop_condition_type_full", context);
+      const error = createSemanticError("loop_condition_type_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.loop_condition_type(exp);
     }
@@ -106,9 +153,11 @@ export const ProcessorErrorFactory  = Object.freeze({
    * @deprecated 01/10/2019
    */
   endless_loop_full: (sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line];
-      return createSemanticError("endless_loop_full", context);
+      const error = createSemanticError("endless_loop_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.endless_loop();
     }
@@ -117,9 +166,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("endless_loop");
   },
   if_condition_type_full: (exp, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, sourceInfo.column, exp];
-      return createSemanticError("if_condition_type_full", context);
+      const error = createSemanticError("if_condition_type_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.if_condition_type(exp);
     }
@@ -129,16 +180,23 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("if_condition_type", context);
   },
   invalid_global_var: () => {
-    return createRuntimeError("invalid_global_var")
+    return createRuntimeError("invalid_global_var");
   },
   not_implemented: (id) => {
-    const context  = [id]
-    return createRuntimeError("not_implemented", context)
+    const context = [id];
+    return createRuntimeError("not_implemented", context);
   },
   invalid_case_type_full: (exp, type, dim, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [exp, LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];
-      return createSemanticError("invalid_case_type_full", context);
+    if (sourceInfo) {
+      const context = [
+        exp,
+        LocalizedStrings.translateType(type, dim),
+        sourceInfo.line,
+        sourceInfo.column,
+      ];
+      const error = createSemanticError("invalid_case_type_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_case_type(exp, type, dim);
     }
@@ -148,9 +206,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_case_type", context);
   },
   void_in_expression_full: (id, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, sourceInfo.column, id];
-      return createSemanticError("void_in_expression_full", context);
+      const error = createSemanticError("void_in_expression_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.void_in_expression(id);
     }
@@ -160,9 +220,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("void_in_expression", context);
   },
   invalid_array_access_full: (id, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [id, sourceInfo.line, sourceInfo.column];
-      return createSemanticError("invalid_array_access_full", context);
+      const error = createSemanticError("invalid_array_access_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_array_access(id);
     }
@@ -172,9 +234,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_array_access", context);
   },
   invalid_matrix_access_full: (id, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [id, sourceInfo.line, sourceInfo.column];
-      return createSemanticError("invalid_matrix_access_full", context);
+      const error = createSemanticError("invalid_matrix_access_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_matrix_access(id);
     }
@@ -184,9 +248,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_matrix_access", context);
   },
   matrix_column_outbounds_full: (id, value, columns, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, value, id, columns];
-      return createRuntimeError("matrix_column_outbounds_full", context);
+      const error = createRuntimeError("matrix_column_outbounds_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.matrix_column_outbounds(id, value, columns);
     }
@@ -196,9 +262,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("matrix_column_outbounds", context);
   },
   matrix_line_outbounds_full: (id, value, lines, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, value, id, lines];
-      return createRuntimeError("matrix_line_outbounds_full", context);
+      const error = createRuntimeError("matrix_line_outbounds_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.matrix_line_outbounds(id, value, lines);
     }
@@ -208,9 +276,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("matrix_line_outbounds", context);
   },
   vector_line_outbounds_full: (id, value, lines, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, value, id, lines];
-      return createRuntimeError("vector_line_outbounds_full", context);
+      const error = createRuntimeError("vector_line_outbounds_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.vector_line_outbounds(id, value, lines);
     }
@@ -220,9 +290,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("vector_line_outbounds", context);
   },
   vector_not_matrix_full: (id, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, id];
-      return createRuntimeError("vector_not_matrix_full", context);
+      const error = createRuntimeError("vector_not_matrix_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.vector_not_matrix(id);
     }
@@ -236,9 +308,15 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("function_no_return", context);
   },
   invalid_void_return_full: (id, type, dim, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [sourceInfo.line, id, LocalizedStrings.translateType(type, dim)];
-      return createSemanticError("invalid_void_return_full", context);
+    if (sourceInfo) {
+      const context = [
+        sourceInfo.line,
+        id,
+        LocalizedStrings.translateType(type, dim),
+      ];
+      const error = createSemanticError("invalid_void_return_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_void_return(id, type, dim);
     }
@@ -248,9 +326,15 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_void_return_full", context);
   },
   invalid_return_type_full: (id, type, dim, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [sourceInfo.line, id, LocalizedStrings.translateType(type, dim)];
-      return createSemanticError("invalid_return_type_full", context);
+    if (sourceInfo) {
+      const context = [
+        sourceInfo.line,
+        id,
+        LocalizedStrings.translateType(type, dim),
+      ];
+      const error = createSemanticError("invalid_return_type_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_return_type(id, type, dim);
     }
@@ -260,11 +344,20 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_return_type", context);
   },
   invalid_parameters_size_full: (id, expected, actual, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, id, expected, actual];
-      return createSemanticError("invalid_parameters_size_full", context);
+      const error = createSemanticError(
+        "invalid_parameters_size_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
-      return ProcessorErrorFactory.invalid_parameters_size(id, expected, actual);
+      return ProcessorErrorFactory.invalid_parameters_size(
+        id,
+        expected,
+        actual
+      );
     }
   },
   invalid_parameters_size: (id, expected, actual) => {
@@ -272,9 +365,15 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_parameters_size", context);
   },
   invalid_parameter_type_full: (fun_name, exp, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [exp, LanguageDefinedFunction.getLocalName(fun_name), sourceInfo.line];
-      return createSemanticError("invalid_parameter_type_full", context);
+    if (sourceInfo) {
+      const context = [
+        exp,
+        LanguageDefinedFunction.getLocalName(fun_name),
+        sourceInfo.line,
+      ];
+      const error = createSemanticError("invalid_parameter_type_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_parameter_type(fun_name, exp);
     }
@@ -284,9 +383,11 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_parameter_type_full", context);
   },
   invalid_ref_full: (id, exp, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [exp, id , sourceInfo.line];
-      return createSemanticError("invalid_ref_full", context);
+    if (sourceInfo) {
+      const context = [exp, id, sourceInfo.line];
+      const error = createSemanticError("invalid_ref_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_ref(id, exp);
     }
@@ -296,9 +397,14 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createSemanticError("invalid_ref", context);
   },
   unexpected_break_command_full: (sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line];
-      return createRuntimeError("unexpected_break_command_full", context);
+      const error = createRuntimeError(
+        "unexpected_break_command_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.unexpected_break_command();
     }
@@ -307,9 +413,14 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("unexpected_break_command");
   },
   invalid_array_literal_type_full: (exp, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, exp];
-      return createRuntimeError("invalid_array_literal_type_full", context);
+      const error = createRuntimeError(
+        "invalid_array_literal_type_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_array_literal_type(exp);
     }
@@ -319,9 +430,14 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("invalid_array_literal_type", context);
   },
   invalid_array_literal_line_full: (expected, actual, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, expected, actual];
-      return createRuntimeError("invalid_array_literal_line_full", context);
+      const error = createRuntimeError(
+        "invalid_array_literal_line_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_array_literal_type(expected, actual);
     }
@@ -331,11 +447,19 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("invalid_array_literal_line", context);
   },
   invalid_array_literal_column_full: (expected, actual, sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line, expected, actual];
-      return createRuntimeError("invalid_array_literal_column_full", context);
+      const error = createRuntimeError(
+        "invalid_array_literal_column_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
-      return ProcessorErrorFactory.invalid_array_literal_column(expected, actual);
+      return ProcessorErrorFactory.invalid_array_literal_column(
+        expected,
+        actual
+      );
     }
   },
   invalid_array_literal_column: (expected, actual) => {
@@ -343,33 +467,83 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("invalid_array_literal_column", context);
   },
   invalid_unary_op_full: (expString, opName, type, dim, sourceInfo) => {
-    if(sourceInfo) {
-      const context = [sourceInfo.line, expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
-      return createRuntimeError("invalid_unary_op_full", context);
+    if (sourceInfo) {
+      const context = [
+        sourceInfo.line,
+        expString,
+        LocalizedStrings.translateOp(opName),
+        LocalizedStrings.translateType(type, dim),
+      ];
+      const error = createRuntimeError("invalid_unary_op_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_unary_op(opName, type, dim);
     }
   },
   invalid_unary_op: (expString, opName, type, dim) => {
-    const context = [expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
+    const context = [
+      expString,
+      LocalizedStrings.translateOp(opName),
+      LocalizedStrings.translateType(type, dim),
+    ];
     return createRuntimeError("invalid_unary_op", context);
   },
-  invalid_infix_op_full: (expString, opName, typeLeft, dimLeft, typeRight, dimRight,  sourceInfo) => {
-    if(sourceInfo) {
-      const context = [sourceInfo.line, expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
-      return createRuntimeError("invalid_infix_op_full", context);
-    } else {
-      return ProcessorErrorFactory.invalid_infix_op(opName, typeLeft, dimLeft, typeRight, dimRight);
-    }
-  },
-  invalid_infix_op: (expString, opName, typeLeft, dimLeft, typeRight, dimRight) => {
-    const context = [expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
+  invalid_infix_op_full: (
+    expString,
+    opName,
+    typeLeft,
+    dimLeft,
+    typeRight,
+    dimRight,
+    sourceInfo
+  ) => {
+    if (sourceInfo) {
+      const context = [
+        sourceInfo.line,
+        expString,
+        LocalizedStrings.translateOp(opName),
+        LocalizedStrings.translateType(typeLeft, dimLeft),
+        LocalizedStrings.translateType(typeRight, dimRight),
+      ];
+      const error = createRuntimeError("invalid_infix_op_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
+    } else {
+      return ProcessorErrorFactory.invalid_infix_op(
+        opName,
+        typeLeft,
+        dimLeft,
+        typeRight,
+        dimRight
+      );
+    }
+  },
+  invalid_infix_op: (
+    expString,
+    opName,
+    typeLeft,
+    dimLeft,
+    typeRight,
+    dimRight
+  ) => {
+    const context = [
+      expString,
+      LocalizedStrings.translateOp(opName),
+      LocalizedStrings.translateType(typeLeft, dimLeft),
+      LocalizedStrings.translateType(typeRight, dimRight),
+    ];
     return createRuntimeError("invalid_infix_op", context);
   },
   array_dimension_not_positive_full: (sourceInfo) => {
-    if(sourceInfo) {
+    if (sourceInfo) {
       const context = [sourceInfo.line];
-      return createSemanticError("array_dimension_not_positive_full", context);
+      const error = createSemanticError(
+        "array_dimension_not_positive_full",
+        context
+      );
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.array_dimension_not_positive();
     }
@@ -382,29 +556,64 @@ export const ProcessorErrorFactory  = Object.freeze({
     return createRuntimeError("invalid_type_conversion", context);
   },
   invalid_read_type: (exp, type, dim, name, source_info) => {
-    const context = [source_info.line, exp, LocalizedStrings.translateType(type, dim), name];
-    return createRuntimeError("invalid_read_type", context)
-  },
-  invalid_read_type_array: (exp, typePos, dimPos, name, typeArray, dimArray, sourceInfo) => {
-    const context = [sourceInfo.line, exp, LocalizedStrings.translateType(typePos, dimPos), name,LocalizedStrings.translateType(typeArray, dimArray)];
-    return createRuntimeError("invalid_read_type_array", context)
-  },
-  invalid_const_ref_full: (fun_name, exp, sourceInfo)=> {
-    if(sourceInfo) {
-      const context = [exp, LanguageDefinedFunction.getLocalName(fun_name), sourceInfo.line];
-      return createSemanticError("invalid_const_ref_full", context);
+    const context = [
+      source_info.line,
+      exp,
+      LocalizedStrings.translateType(type, dim),
+      name,
+    ];
+    const error = createRuntimeError("invalid_read_type", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
+  },
+  invalid_read_type_array: (
+    exp,
+    typePos,
+    dimPos,
+    name,
+    typeArray,
+    dimArray,
+    sourceInfo
+  ) => {
+    const context = [
+      sourceInfo.line,
+      exp,
+      LocalizedStrings.translateType(typePos, dimPos),
+      name,
+      LocalizedStrings.translateType(typeArray, dimArray),
+    ];
+    const error = createRuntimeError("invalid_read_type_array", context);
+    error.context = { line: sourceInfo.line, column: sourceInfo.column };
+    return error;
+  },
+  invalid_const_ref_full: (fun_name, exp, sourceInfo) => {
+    if (sourceInfo) {
+      const context = [
+        exp,
+        LanguageDefinedFunction.getLocalName(fun_name),
+        sourceInfo.line,
+      ];
+      const error = createSemanticError("invalid_const_ref_full", context);
+      error.context = { line: sourceInfo.line, column: sourceInfo.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_const_ref(fun_name, exp);
     }
   },
   invalid_const_ref: (fun_name, exp) => {
     const context = [exp, LanguageDefinedFunction.getLocalName(fun_name)];
-    return createSemanticError("invalid_const_ref", context);
+    const error = createSemanticError("invalid_const_ref", context);
+    return error;
   },
   invalid_const_assignment_full: (var_id, source_info) => {
-    if(source_info) {
+    if (source_info) {
       const context = [source_info.line, var_id];
-      return createSemanticError("invalid_const_assignment_full", context);
+      const error = createSemanticError(
+        "invalid_const_assignment_full",
+        context
+      );
+      error.context = { line: source_info.line, column: source_info.column };
+      return error;
     } else {
       return ProcessorErrorFactory.invalid_const_assignment(var_id);
     }
@@ -413,66 +622,170 @@ export const ProcessorErrorFactory  = Object.freeze({
     const context = [var_id];
     return createSemanticError("invalid_const_assignment", context);
   },
-  invalid_vector_assignment_full: (left_id, left_size, right_id, right_size, source_info) => {
-    if(source_info)  {
-      const context = [source_info.line, left_id, left_size, right_id, right_size]
-      return createRuntimeError("invalid_vector_assignment_full", context);
-    } else {
-      return ProcessorErrorFactory.invalid_vector_assignment(left_id, left_size, right_id, right_size);
+  invalid_vector_assignment_full: (
+    left_id,
+    left_size,
+    right_id,
+    right_size,
+    source_info
+  ) => {
+    if (source_info) {
+      const context = [
+        source_info.line,
+        left_id,
+        left_size,
+        right_id,
+        right_size,
+      ];
+      const error = createRuntimeError(
+        "invalid_vector_assignment_full",
+        context
+      );
+      error.context = { line: source_info.line, column: source_info.column };
+      return error;
+    } else {
+      return ProcessorErrorFactory.invalid_vector_assignment(
+        left_id,
+        left_size,
+        right_id,
+        right_size
+      );
     }
   },
   invalid_vector_assignment: (left_id, left_size, right_id, right_size) => {
-    const context = [left_id, left_size, right_id, right_size]
+    const context = [left_id, left_size, right_id, right_size];
     return createRuntimeError("invalid_vector_assignment", context);
   },
-  invalid_matrix_assignment_full: (left_id, left_line, left_column, right_id, right_line, right_column, source_info) => {
-    if(source_info)  {
-      const context = [source_info.line, left_id, left_line, left_column, right_id, right_line, right_column]
-      return createRuntimeError("invalid_matrix_assignment_full", context);
-    } else {
-      return ProcessorErrorFactory.invalid_matrix_assignment(left_id, left_line, left_column, right_id, right_line, right_column);
-    }
-  },
-  invalid_matrix_assignment: (left_id, left_line, left_column, right_id, right_line, right_column) => {
-    const context = [left_id, left_line, left_column, right_id, right_line, right_column]
+  invalid_matrix_assignment_full: (
+    left_id,
+    left_line,
+    left_column,
+    right_id,
+    right_line,
+    right_column,
+    source_info
+  ) => {
+    if (source_info) {
+      const context = [
+        source_info.line,
+        left_id,
+        left_line,
+        left_column,
+        right_id,
+        right_line,
+        right_column,
+      ];
+      const error = createRuntimeError(
+        "invalid_matrix_assignment_full",
+        context
+      );
+      error.context = { line: source_info.line, column: source_info.column };
+      return error;
+    } else {
+      return ProcessorErrorFactory.invalid_matrix_assignment(
+        left_id,
+        left_line,
+        left_column,
+        right_id,
+        right_line,
+        right_column
+      );
+    }
+  },
+  invalid_matrix_assignment: (
+    left_id,
+    left_line,
+    left_column,
+    right_id,
+    right_line,
+    right_column
+  ) => {
+    const context = [
+      left_id,
+      left_line,
+      left_column,
+      right_id,
+      right_line,
+      right_column,
+    ];
     return createRuntimeError("invalid_matrix_assignment", context);
   },
   matrix_to_vector_attr: (left_id, right_id, source_info) => {
     // SourceInfo have to be valid...
     const context = [source_info.line, right_id, left_id];
-    return createSemanticError("matrix_to_vector_attr", context);
+    const error = createSemanticError("matrix_to_vector_attr", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   vector_to_matrix_attr: (left_id, right_id, source_info) => {
     // SourceInfo have to be valid...
     const context = [source_info.line, right_id, left_id];
-    return createSemanticError("vector_to_matrix_attr", context);
-  },
-  invalid_matrix_index_assign_full: (mat_id, mat_line, mat_size, exp, exp_size, source_info) => {
-    if(source_info){
-      const context = [source_info.line, mat_line, mat_id, mat_size, exp, exp_size];
-      return createRuntimeError("invalid_matrix_index_assign_full", context);
-    } else {
-      return ProcessorErrorFactory.invalid_matrix_index_assign(mat_id, mat_line, mat_size, exp, exp_size)
-    }
-  },
-  invalid_matrix_index_assign: (mat_id, mat_line, mat_size, exp, exp_size) =>{
+    const error = createSemanticError("vector_to_matrix_attr", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
+  },
+  invalid_matrix_index_assign_full: (
+    mat_id,
+    mat_line,
+    mat_size,
+    exp,
+    exp_size,
+    source_info
+  ) => {
+    if (source_info) {
+      const context = [
+        source_info.line,
+        mat_line,
+        mat_id,
+        mat_size,
+        exp,
+        exp_size,
+      ];
+      const error = createRuntimeError(
+        "invalid_matrix_index_assign_full",
+        context
+      );
+      error.context = { line: source_info.line, column: source_info.column };
+      return error;
+    } else {
+      return ProcessorErrorFactory.invalid_matrix_index_assign(
+        mat_id,
+        mat_line,
+        mat_size,
+        exp,
+        exp_size
+      );
+    }
+  },
+  invalid_matrix_index_assign: (mat_id, mat_line, mat_size, exp, exp_size) => {
     const context = [mat_line, mat_id, mat_size, exp, exp_size];
     return createRuntimeError("invalid_matrix_index_assign", context);
   },
-  invalid_number_elements_vector: (expected_num, exp, actual_num, source_info) => {
+  invalid_number_elements_vector: (
+    expected_num,
+    exp,
+    actual_num,
+    source_info
+  ) => {
     // SourceInfo have to be valid...
     const context = [expected_num, source_info.line, exp, actual_num];
-    return createRuntimeError("invalid_number_elements_vector", context);
+    const error = createRuntimeError("invalid_number_elements_vector", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   invalid_number_lines_matrix: (expected_num, exp, actual_num, source_info) => {
     // SourceInfo have to be valid...
     const context = [expected_num, source_info.line, exp, actual_num];
-    return createRuntimeError("invalid_number_lines_matrix", context);
+    const error = createRuntimeError("invalid_number_lines_matrix", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   divsion_by_zero_full: (exp, source_info) => {
-    if(source_info) {
+    if (source_info) {
       const context = [source_info.line, exp];
-      return createRuntimeError("divsion_by_zero_full", context);
+      const error = createRuntimeError("divsion_by_zero_full", context);
+      error.context = { line: source_info.line, column: source_info.column };
+      return error;
     } else {
       return ProcessorErrorFactory.divsion_by_zero(exp);
     }
@@ -483,43 +796,68 @@ export const ProcessorErrorFactory  = Object.freeze({
   },
   undefined_tanget_value: (value, source_info) => {
     const context = [source_info.line, value];
-    return createRuntimeError("undefined_tanget_value", context);
+    const error = createRuntimeError("undefined_tanget_value", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   negative_log_value: (source_info) => {
-    return createRuntimeError("negative_log_value",[source_info.line]);
+    const error = createRuntimeError("negative_log_value", [source_info.line]);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   invalid_string_index: (index, str, source_info) => {
     const local_fun_name = LanguageDefinedFunction.getLocalName("$charAt");
-    const context = [source_info.line, local_fun_name, index, str, str.length - 1];
-    return createRuntimeError("invalid_string_index", context);
+    const context = [
+      source_info.line,
+      local_fun_name,
+      index,
+      str,
+      str.length - 1,
+    ];
+    const error = createRuntimeError("invalid_string_index", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   negative_sqrt_value: (source_info) => {
-    return createRuntimeError("negative_sqrt_value",[source_info.line]);
+    const error = createRuntimeError("negative_sqrt_value", [source_info.line]);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   /**
    * @deprecated 01/10/2019
    */
   exceeded_recursive_calls: (source_info) => {
     const context = [source_info.line];
-    return createRuntimeError("exceeded_recursive_calls", context);
+    const error = createRuntimeError("exceeded_recursive_calls", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   invalid_for_variable: (id, source_info) => {
     const context = [source_info.line, id];
-    return createSemanticError("invalid_for_variable", context);
+    const error = createSemanticError("invalid_for_variable", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   invalid_for_from: (exp, source_info) => {
     const context = [source_info.line, exp];
-    return createSemanticError("invalid_for_from", context);
+    const error = createSemanticError("invalid_for_from", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   invalid_for_to: (exp, source_info) => {
     const context = [source_info.line, exp];
-    return createSemanticError("invalid_for_to", context);
+    const error = createSemanticError("invalid_for_to", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   invalid_for_pass: (exp, source_info) => {
     const context = [source_info.line, exp];
-    return createSemanticError("invalid_for_pass", context);
+    const error = createSemanticError("invalid_for_pass", context);
+    error.context = { line: source_info.line, column: source_info.column };
+    return error;
   },
   exceed_max_instructions: () => {
-    return createRuntimeError('exceed_max_instructions');
-  }
-});
+    return createRuntimeError("exceed_max_instructions");
+  },
+});
+

+ 13 - 5
js/processor/error/runtimeError.js

@@ -1,8 +1,16 @@
 export class RuntimeError extends Error {
-
-  constructor (...msg) {
+  constructor (msg, id) {
     super(...msg);
-    if(Error.captureStackTrace)
-      Error.captureStackTrace(this, RuntimeError);
+    this.id = id;
+    if (Error.captureStackTrace) Error.captureStackTrace(this, RuntimeError);
+  }
+
+  get context () {
+    return this._context;
   }
-}
+
+  set context (contextObj) {
+    this._context = contextObj;
+  }
+}
+

+ 13 - 5
js/processor/error/semanticError.js

@@ -1,8 +1,16 @@
 export class SemanticError extends Error {
-
-  constructor (...msg) {
+  constructor (msg, id) {
     super(...msg);
-    if(Error.captureStackTrace)
-      Error.captureStackTrace(this, SemanticError);
+    this.id = id;
+    if (Error.captureStackTrace) Error.captureStackTrace(this, SemanticError);
+  }
+
+  get context () {
+    return this._context;
   }
-}
+
+  set context (contextObj) {
+    this._context = contextObj;
+  }
+}
+