syntaxErrorFactory.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import * as LocalizedStringsService from './../../services/localizedStringsService';
  2. import { SyntaxError } from './syntaxError';
  3. const LocalizedStrings = LocalizedStringsService.getInstance();
  4. export const SyntaxErrorFactory = Object.freeze({
  5. extra_lines: () => new SyntaxError(LocalizedStrings.getError("extra_lines")),
  6. token_missing_one: (expected, token) => {
  7. const context = [expected, token.text, token.line, token.column];
  8. return new SyntaxError(LocalizedStrings.getError("token_missing_one", context));
  9. },
  10. token_missing_list: (expectedList, token) => {
  11. const line = expectedList.join(LocalizedStrings.getOR());
  12. return SyntaxErrorFactory.token_missing_one(line, token);
  13. },
  14. id_missing: (token) => {
  15. const context = [token.text, token.line, token.column];
  16. return new SyntaxError(LocalizedStrings.getError("id_missing", context));
  17. },
  18. eos_missing: (token) => {
  19. const context = [token.line, token.column];
  20. return new SyntaxError(LocalizedStrings.getError("eos_missing", context));
  21. },
  22. invalid_array_dimension: (typeName, token) => {
  23. const context = [token.line, token.column, typeName];
  24. return new SyntaxError(LocalizedStrings.getError("invalid_array_dimension", context));
  25. },
  26. invalid_array_size: (token) => {
  27. const context = [token.line];
  28. return new SyntaxError(LocalizedStrings.getError("invalid_array_size", context));
  29. },
  30. invalid_main_return: (name, typeName, token) => {
  31. const context = [name, typeName, token.line];
  32. return new SyntaxError(LocalizedStrings.getError("invalid_main_return", context));
  33. },
  34. invalid_var_declaration: (token) => {
  35. const context = [token.line];
  36. return new SyntaxError(LocalizedStrings.getError("invalid_var_declaration", context));
  37. },
  38. invalid_break_command: (cmdName, token) => {
  39. const context = [token.line, cmdName];
  40. return new SyntaxError(LocalizedStrings.getError("invalid_break_command", context));
  41. },
  42. invalid_terminal: (token) => {
  43. const context = [token.text, token.line, token.column];
  44. return new SyntaxError(LocalizedStrings.getError('invalid_terminal', context));
  45. },
  46. invalid_type: (list, token) => {
  47. const line = list.join(LocalizedStrings.getOR());
  48. const context = [token.text, token.line, token.column, line]
  49. return new SyntaxError(LocalizedStrings.getError("invalid_type", context));
  50. },
  51. const_not_init: (token) => {
  52. const context = [token.line, token.column];
  53. return new SyntaxError(LocalizedStrings.getError("const_not_init", context));
  54. },
  55. invalid_id_format: (token) => {
  56. const context = [token.text, token.line, token.column];
  57. return new SyntaxError(LocalizedStrings.getError("invalid_id_format", context));
  58. },
  59. duplicate_function: (token) => {
  60. const context = [token.text, token.line, token.column];
  61. return new SyntaxError(LocalizedStrings.getError("duplicate_function", context));
  62. },
  63. main_parameters: () => {
  64. return new SyntaxError(LocalizedStrings.getError("main_parameters"));
  65. },
  66. duplicate_variable: (token) => {
  67. const context = [token.text, token.line, token.column];
  68. return new SyntaxError(LocalizedStrings.getError("duplicate_variable", context));
  69. }
  70. });