syntaxErrorFactory.js 3.1 KB

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