|
@@ -3,11 +3,15 @@ import { SyntaxError } from './syntaxError';
|
|
|
|
|
|
const LocalizedStrings = LocalizedStringsService.getInstance();
|
|
const LocalizedStrings = LocalizedStringsService.getInstance();
|
|
|
|
|
|
|
|
+function createError (message_id, context = []) {
|
|
|
|
+ return new SyntaxError(LocalizedStrings.getError(message_id, context));
|
|
|
|
+}
|
|
|
|
+
|
|
export const SyntaxErrorFactory = Object.freeze({
|
|
export const SyntaxErrorFactory = Object.freeze({
|
|
extra_lines: () => new SyntaxError(LocalizedStrings.getError("extra_lines")),
|
|
extra_lines: () => new SyntaxError(LocalizedStrings.getError("extra_lines")),
|
|
token_missing_one: (expected, token) => {
|
|
token_missing_one: (expected, token) => {
|
|
const context = [expected, token.text, token.line, token.column];
|
|
const context = [expected, token.text, token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("token_missing_one", context));
|
|
|
|
|
|
+ return createError("token_missing_one", context);
|
|
},
|
|
},
|
|
token_missing_list: (expectedList, token) => {
|
|
token_missing_list: (expectedList, token) => {
|
|
const line = expectedList.join(LocalizedStrings.getOR());
|
|
const line = expectedList.join(LocalizedStrings.getOR());
|
|
@@ -15,66 +19,82 @@ export const SyntaxErrorFactory = Object.freeze({
|
|
},
|
|
},
|
|
id_missing: (token) => {
|
|
id_missing: (token) => {
|
|
const context = [token.text, token.line, token.column];
|
|
const context = [token.text, token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("id_missing", context));
|
|
|
|
|
|
+ return createError("id_missing", context);
|
|
},
|
|
},
|
|
eos_missing: (token) => {
|
|
eos_missing: (token) => {
|
|
const context = [token.line, token.column];
|
|
const context = [token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("eos_missing", context));
|
|
|
|
|
|
+ return createError("eos_missing", context);
|
|
},
|
|
},
|
|
invalid_array_dimension: (typeName, token) => {
|
|
invalid_array_dimension: (typeName, token) => {
|
|
const context = [token.line, token.column, typeName];
|
|
const context = [token.line, token.column, typeName];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_array_dimension", context));
|
|
|
|
|
|
+ return createError("invalid_array_dimension", context);
|
|
},
|
|
},
|
|
invalid_array_size: (token) => {
|
|
invalid_array_size: (token) => {
|
|
const context = [token.line];
|
|
const context = [token.line];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_array_size", context));
|
|
|
|
|
|
+ return createError("invalid_array_size", context);
|
|
},
|
|
},
|
|
invalid_main_return: (name, typeName, token) => {
|
|
invalid_main_return: (name, typeName, token) => {
|
|
const context = [name, typeName, token.line];
|
|
const context = [name, typeName, token.line];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_main_return", context));
|
|
|
|
|
|
+ return createError("invalid_main_return", context);
|
|
},
|
|
},
|
|
invalid_var_declaration: (token) => {
|
|
invalid_var_declaration: (token) => {
|
|
const context = [token.line];
|
|
const context = [token.line];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_var_declaration", context));
|
|
|
|
|
|
+ return createError("invalid_var_declaration", context);
|
|
},
|
|
},
|
|
invalid_break_command: (cmdName, token) => {
|
|
invalid_break_command: (cmdName, token) => {
|
|
const context = [token.line, cmdName];
|
|
const context = [token.line, cmdName];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_break_command", context));
|
|
|
|
|
|
+ return createError("invalid_break_command", context);
|
|
},
|
|
},
|
|
invalid_terminal: (token) => {
|
|
invalid_terminal: (token) => {
|
|
const context = [token.text, token.line, token.column];
|
|
const context = [token.text, token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError('invalid_terminal', context));
|
|
|
|
|
|
+ return createError('invalid_terminal', context);
|
|
},
|
|
},
|
|
invalid_type: (list, token) => {
|
|
invalid_type: (list, token) => {
|
|
const line = list.join(LocalizedStrings.getOR());
|
|
const line = list.join(LocalizedStrings.getOR());
|
|
const context = [token.text, token.line, token.column, line]
|
|
const context = [token.text, token.line, token.column, line]
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_type", context));
|
|
|
|
|
|
+ return createError("invalid_type", context);
|
|
},
|
|
},
|
|
const_not_init: (token) => {
|
|
const_not_init: (token) => {
|
|
const context = [token.line, token.column];
|
|
const context = [token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("const_not_init", context));
|
|
|
|
|
|
+ return createError("const_not_init", context);
|
|
},
|
|
},
|
|
invalid_id_format: (token) => {
|
|
invalid_id_format: (token) => {
|
|
const context = [token.text, token.line, token.column];
|
|
const context = [token.text, token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_id_format", context));
|
|
|
|
|
|
+ return createError("invalid_id_format", context);
|
|
},
|
|
},
|
|
duplicate_function: (token) => {
|
|
duplicate_function: (token) => {
|
|
const context = [token.text, token.line, token.column];
|
|
const context = [token.text, token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("duplicate_function", context));
|
|
|
|
|
|
+ return createError("duplicate_function", context);
|
|
},
|
|
},
|
|
main_parameters: () => {
|
|
main_parameters: () => {
|
|
- return new SyntaxError(LocalizedStrings.getError("main_parameters"));
|
|
|
|
|
|
+ return createError("main_parameters");
|
|
},
|
|
},
|
|
duplicate_variable: (token) => {
|
|
duplicate_variable: (token) => {
|
|
const context = [token.text, token.line, token.column];
|
|
const context = [token.text, token.line, token.column];
|
|
- return new SyntaxError(LocalizedStrings.getError("duplicate_variable", context));
|
|
|
|
|
|
+ return createError("duplicate_variable", context);
|
|
},
|
|
},
|
|
invalid_character: (text, line, column) => {
|
|
invalid_character: (text, line, column) => {
|
|
const context = [text, line];
|
|
const context = [text, line];
|
|
- return new SyntaxError(LocalizedStrings.getError("invalid_character", context));
|
|
|
|
|
|
+ return createError("invalid_character", context);
|
|
},
|
|
},
|
|
annonymous_array_literal: (token) => {
|
|
annonymous_array_literal: (token) => {
|
|
const context = [token.line];
|
|
const context = [token.line];
|
|
- return new SyntaxError(LocalizedStrings.getError("annonymous_array_literal", context));
|
|
|
|
|
|
+ return createError("annonymous_array_literal", context);
|
|
|
|
+ },
|
|
|
|
+ invalid_matrix_literal_line: (exp, sourceInfo) => {
|
|
|
|
+ const context = [exp, sourceInfo.line];
|
|
|
|
+ return createError("invalid_matrix_literal_line", context);
|
|
|
|
+ },
|
|
|
|
+ cannot_infer_matrix_line: (name, sourceInfo) => {
|
|
|
|
+ const context = [name, sourceInfo.line];
|
|
|
|
+ return createError("cannot_infer_matrix_line", context);
|
|
|
|
+ },
|
|
|
|
+ cannot_infer_matrix_column: (name, sourceInfo) => {
|
|
|
|
+ const context = [name, sourceInfo.line];
|
|
|
|
+ return createError("cannot_infer_matrix_column", context);
|
|
|
|
+ },
|
|
|
|
+ cannot_infer_vector_size: (name, sourceInfo) => {
|
|
|
|
+ const context = [name, sourceInfo.line];
|
|
|
|
+ return createError("cannot_infer_vector_size", context);
|
|
}
|
|
}
|
|
});
|
|
});
|