123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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));
- }
- 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);
- },
- token_missing_list: (expectedList, token) => {
- const line = expectedList.join(LocalizedStrings.getOR());
- return SyntaxErrorFactory.token_missing_one(line, token);
- },
- id_missing: (token) => {
- const context = [token.text, token.line, token.column];
- return createError("id_missing", context);
- },
- eos_missing: (token) => {
- const context = [token.line, token.column];
- return createError("eos_missing", context);
- },
- invalid_array_dimension: (typeName, token) => {
- const context = [token.line, token.column, typeName];
- return createError("invalid_array_dimension", context);
- },
- invalid_array_size: (token) => {
- const context = [token.line];
- return createError("invalid_array_size", context);
- },
- invalid_main_return: (name, typeName, token) => {
- const context = [name, typeName, token.line];
- return createError("invalid_main_return", context);
- },
- invalid_var_declaration: (token) => {
- const context = [token.line];
- return createError("invalid_var_declaration", context);
- },
- invalid_break_command: (cmdName, token) => {
- const context = [token.line, cmdName];
- return createError("invalid_break_command", context);
- },
- invalid_terminal: (token) => {
- const context = [token.text, token.line, token.column];
- return createError('invalid_terminal', context);
- },
- 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_not_init: (token) => {
- const context = [token.line, token.column];
- return createError("const_not_init", context);
- },
- invalid_id_format: (token) => {
- const context = [token.text, token.line, token.column];
- return createError("invalid_id_format", context);
- },
- duplicate_function: (token) => {
- const context = [token.text, token.line, token.column];
- return createError("duplicate_function", context);
- },
- main_parameters: () => {
- return createError("main_parameters");
- },
- duplicate_variable: (token) => {
- const context = [token.text, token.line, token.column];
- return createError("duplicate_variable", context);
- },
- invalid_character: (text, line, _column) => {
- const context = [text, line];
- return createError("invalid_character", context);
- },
- annonymous_array_literal: (token) => {
- const context = [token.line];
- 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);
- },
- matrix_to_vector_literal_attr: (name, exp, sourceInfo) => {
- const context = [sourceInfo.line, exp, name];
- return createError("matrix_to_vector_literal_attr", context);
- },
- vector_to_matrix_literal_attr: (name, exp, sourceInfo) => {
- const context = [sourceInfo.line, exp, name];
- return createError("vector_to_matrix_literal_attr", context);
- },
- array_init_not_literal: (sourceInfo) => {
- const context = [sourceInfo.line];
- return createError("array_init_not_literal", context);
- },
- array_exceeds_2d: (sourceInfo) => {
- const context = [sourceInfo.line];
- return createError("array_exceeds_2d", context);
- },
- invalid_matrix_id_dimension: (sourceInfo) => {
- const context = [sourceInfo.line];
- return createError("invalid_matrix_id_dimension", context);
- },
- invalid_vector_init: (sourceInfo) => {
- const context = [sourceInfo.line];
- return createError("invalid_vector_init", context);
- },
- invalid_matrix_init: (sourceInfo) => {
- const context = [sourceInfo.line];
- return createError("invalid_matrix_init", context);
- }
- });
|