syntaxErrorFactory.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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: () => {
  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. });