processorErrorFactory.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { RuntimeError } from './runtimeError';
  2. import { SemanticError } from './semanticError';
  3. import { LocalizedStrings } from './../../services/localizedStringsService';
  4. function translateType (type, dim) {
  5. switch (dim) {
  6. case 0:
  7. return LocalizedStrings.getUI(type);
  8. default:
  9. const transType = LocalizedStrings.getUI(type);
  10. if(dim === 1)
  11. return LocalizedStrings.getUI("vector_string", [transType])
  12. else
  13. return LocalizedStrings.getUI("matrix_string", [transType])
  14. }
  15. }
  16. export const ProcessorErrorFactory = Object.freeze({
  17. symbol_not_found_full: (id, sourceInfo) => {
  18. if(sourceInfo) {
  19. const context = [id, sourceInfo.line, sourceInfo.column];
  20. return new SemanticError(LocalizedStrings.getError("symbol_not_found_full", context));
  21. } else {
  22. return ProcessorErrorFactory.symbol_not_found(id);
  23. }
  24. },
  25. symbol_not_found: (id) => {
  26. const context = [id];
  27. return new SemanticError(LocalizedStrings.getError("symbol_not_found", context));
  28. },
  29. function_missing_full: (id, sourceInfo) => {
  30. if(sourceInfo) {
  31. const context = [id, sourceInfo.line, sourceInfo.column];
  32. return new SemanticError(LocalizedStrings.getError("function_missing_full", context));
  33. } else {
  34. return ProcessorErrorFactory.function_missing(id);
  35. }
  36. },
  37. function_missing: (id) => {
  38. const context = [id];
  39. return new SemanticError(LocalizedStrings.getError("function_missing", context));
  40. },
  41. main_missing: () => {
  42. return new SemanticError(LocalizedStrings.getError("main_missing"));
  43. },
  44. array_dimension_not_int_full: (sourceInfo) => {
  45. if(sourceInfo) {
  46. const context = [sourceInfo.line];
  47. return new SemanticError(LocalizedStrings.getError("array_dimension_not_int_full", context));
  48. } else {
  49. return ProcessorErrorFactory.array_dimension_not_int();
  50. }
  51. },
  52. array_dimension_not_int: () => {
  53. return new SemanticError(LocalizedStrings.getError("array_dimension_not_int"));
  54. },
  55. unknown_command: (id)=> {
  56. const context = [id];
  57. return new SemanticError(LocalizedStrings.getError("unknown_command", context));
  58. },
  59. incompatible_types_full: (type, dim, sourceInfo) => {
  60. if(sourceInfo) {
  61. const context = [translateType(type, dim), sourceInfo.line, sourceInfo.column];
  62. return new SemanticError(LocalizedStrings.getError("incompatible_types_full", context));
  63. } else {
  64. return ProcessorErrorFactory.incompatible_types(type, dim);
  65. }
  66. },
  67. incompatible_types: (type, dim) => {
  68. const context = [translateType(type, dim)];
  69. return new SemanticError(LocalizedStrings.getError("incompatible_types", context));
  70. },
  71. incompatible_types_array_full: (exp, type, dim, sourceInfo) => {
  72. if(sourceInfo) {
  73. const context = [exp, translateType(type, dim), sourceInfo.line, sourceInfo.column];
  74. return new SemanticError(LocalizedStrings.getError("incompatible_types_array_full", context));
  75. } else {
  76. return ProcessorErrorFactory.incompatible_types_array(exp, type, dim);
  77. }
  78. },
  79. incompatible_types_array: (exp, type, dim) => {
  80. const context = [exp, translateType(type, dim)];
  81. return new SemanticError(LocalizedStrings.getError("incompatible_types_array", context));
  82. },
  83. loop_condition_type_full: (sourceInfo) => {
  84. if(sourceInfo) {
  85. const context = [sourceInfo.line, sourceInfo.column];
  86. return new SemanticError(LocalizedStrings.getError("loop_condition_type_full", context));
  87. } else {
  88. return ProcessorErrorFactory.loop_condition_type();
  89. }
  90. },
  91. loop_condition_type: () => {
  92. return new SemanticError(LocalizedStrings.getError("loop_condition_type"));
  93. },
  94. for_condition_type_full: (sourceInfo) => {
  95. if(sourceInfo) {
  96. const context = [sourceInfo.line, sourceInfo.column];
  97. return new SemanticError(LocalizedStrings.getError("for_condition_type_full", context));
  98. } else {
  99. return ProcessorErrorFactory.for_condition_type();
  100. }
  101. },
  102. for_condition_type: () => {
  103. return new SemanticError(LocalizedStrings.getError("for_condition_type"));
  104. },
  105. if_condition_type_full: (sourceInfo) => {
  106. if(sourceInfo) {
  107. const context = [sourceInfo.line, sourceInfo.column];
  108. return new SemanticError(LocalizedStrings.getError("if_condition_type_full", context));
  109. } else {
  110. return ProcessorErrorFactory.if_condition_type();
  111. }
  112. },
  113. if_condition_type: () => {
  114. return new SemanticError(LocalizedStrings.getError("if_condition_type"));
  115. },
  116. invalid_case_type_full: (exp, type, dim, sourceInfo) => {
  117. if(sourceInfo) {
  118. const context = [exp, translateType(type, dim), sourceInfo.line, sourceInfo.column];
  119. return new SemanticError(LocalizedStrings.getError("invalid_case_type_full", context));
  120. } else {
  121. return ProcessorErrorFactory.invalid_case_type(exp, type, dim);
  122. }
  123. },
  124. invalid_case_type: (exp, type, dim) => {
  125. const context = [exp, translateType(type, dim)];
  126. return new SemanticError(LocalizedStrings.getError("invalid_case_type", context));
  127. }
  128. });