@data7expressions/3xpr 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/LICENSE +201 -0
  3. package/README.md +144 -0
  4. package/expression/application/expressions.d.ts +69 -0
  5. package/expression/application/expressions.d.ts.map +1 -0
  6. package/expression/application/expressions.js +157 -0
  7. package/expression/application/expressions.js.map +1 -0
  8. package/expression/application/index.d.ts +4 -0
  9. package/expression/application/index.d.ts.map +1 -0
  10. package/expression/application/index.js +20 -0
  11. package/expression/application/index.js.map +1 -0
  12. package/expression/application/useCases/convert.d.ts +8 -0
  13. package/expression/application/useCases/convert.d.ts.map +1 -0
  14. package/expression/application/useCases/convert.js +25 -0
  15. package/expression/application/useCases/convert.js.map +1 -0
  16. package/expression/application/useCases/executor.d.ts +11 -0
  17. package/expression/application/useCases/executor.d.ts.map +1 -0
  18. package/expression/application/useCases/executor.js +23 -0
  19. package/expression/application/useCases/executor.js.map +1 -0
  20. package/expression/application/useCases/executorObserveDecorator.d.ts +16 -0
  21. package/expression/application/useCases/executorObserveDecorator.d.ts.map +1 -0
  22. package/expression/application/useCases/executorObserveDecorator.js +98 -0
  23. package/expression/application/useCases/executorObserveDecorator.js.map +1 -0
  24. package/expression/domain/expressions.d.ts +29 -0
  25. package/expression/domain/expressions.d.ts.map +1 -0
  26. package/expression/domain/expressions.js +3 -0
  27. package/expression/domain/expressions.js.map +1 -0
  28. package/expression/domain/index.d.ts +2 -0
  29. package/expression/domain/index.d.ts.map +1 -0
  30. package/expression/domain/index.js +18 -0
  31. package/expression/domain/index.js.map +1 -0
  32. package/expression/infrastructure/convertFrom/convertFromFunction.d.ts +15 -0
  33. package/expression/infrastructure/convertFrom/convertFromFunction.d.ts.map +1 -0
  34. package/expression/infrastructure/convertFrom/convertFromFunction.js +45 -0
  35. package/expression/infrastructure/convertFrom/convertFromFunction.js.map +1 -0
  36. package/expression/infrastructure/convertFrom/convertFromGraphql.d.ts +5 -0
  37. package/expression/infrastructure/convertFrom/convertFromGraphql.d.ts.map +1 -0
  38. package/expression/infrastructure/convertFrom/convertFromGraphql.js +96 -0
  39. package/expression/infrastructure/convertFrom/convertFromGraphql.js.map +1 -0
  40. package/expression/infrastructure/expressionsBuilder.d.ts +8 -0
  41. package/expression/infrastructure/expressionsBuilder.d.ts.map +1 -0
  42. package/expression/infrastructure/expressionsBuilder.js +28 -0
  43. package/expression/infrastructure/expressionsBuilder.js.map +1 -0
  44. package/expression/infrastructure/helper.d.ts +7 -0
  45. package/expression/infrastructure/helper.d.ts.map +1 -0
  46. package/expression/infrastructure/helper.js +34 -0
  47. package/expression/infrastructure/helper.js.map +1 -0
  48. package/expression/infrastructure/index.d.ts +2 -0
  49. package/expression/infrastructure/index.d.ts.map +1 -0
  50. package/expression/infrastructure/index.js +18 -0
  51. package/expression/infrastructure/index.js.map +1 -0
  52. package/expression/infrastructure/library.d.ts +30 -0
  53. package/expression/infrastructure/library.d.ts.map +1 -0
  54. package/expression/infrastructure/library.js +1813 -0
  55. package/expression/infrastructure/library.js.map +1 -0
  56. package/index.d.ts +31 -0
  57. package/index.d.ts.map +1 -0
  58. package/index.js +64 -0
  59. package/index.js.map +1 -0
  60. package/jest-unit-config.json +15 -0
  61. package/model/application/index.d.ts +2 -0
  62. package/model/application/index.d.ts.map +1 -0
  63. package/model/application/index.js +18 -0
  64. package/model/application/index.js.map +1 -0
  65. package/model/application/modelService.d.ts +42 -0
  66. package/model/application/modelService.d.ts.map +1 -0
  67. package/model/application/modelService.js +329 -0
  68. package/model/application/modelService.js.map +1 -0
  69. package/model/domain/index.d.ts +3 -0
  70. package/model/domain/index.d.ts.map +1 -0
  71. package/model/domain/index.js +19 -0
  72. package/model/domain/index.js.map +1 -0
  73. package/model/domain/library.d.ts +5 -0
  74. package/model/domain/library.d.ts.map +1 -0
  75. package/model/domain/library.js +3 -0
  76. package/model/domain/library.js.map +1 -0
  77. package/model/domain/services.d.ts +32 -0
  78. package/model/domain/services.d.ts.map +1 -0
  79. package/model/domain/services.js +3 -0
  80. package/model/domain/services.js.map +1 -0
  81. package/operand/application/facade.d.ts +27 -0
  82. package/operand/application/facade.d.ts.map +1 -0
  83. package/operand/application/facade.js +42 -0
  84. package/operand/application/facade.js.map +1 -0
  85. package/operand/application/index.d.ts +15 -0
  86. package/operand/application/index.d.ts.map +1 -0
  87. package/operand/application/index.js +31 -0
  88. package/operand/application/index.js.map +1 -0
  89. package/operand/application/services/builder.d.ts +17 -0
  90. package/operand/application/services/builder.d.ts.map +1 -0
  91. package/operand/application/services/builder.js +30 -0
  92. package/operand/application/services/builder.js.map +1 -0
  93. package/operand/application/services/builderCacheDecorator.d.ts +14 -0
  94. package/operand/application/services/builderCacheDecorator.d.ts.map +1 -0
  95. package/operand/application/services/builderCacheDecorator.js +29 -0
  96. package/operand/application/services/builderCacheDecorator.js.map +1 -0
  97. package/operand/application/services/factory.d.ts +10 -0
  98. package/operand/application/services/factory.d.ts.map +1 -0
  99. package/operand/application/services/factory.js +24 -0
  100. package/operand/application/services/factory.js.map +1 -0
  101. package/operand/application/services/normalizer.d.ts +4 -0
  102. package/operand/application/services/normalizer.d.ts.map +1 -0
  103. package/operand/application/services/normalizer.js +51 -0
  104. package/operand/application/services/normalizer.js.map +1 -0
  105. package/operand/application/services/parameterService.d.ts +6 -0
  106. package/operand/application/services/parameterService.d.ts.map +1 -0
  107. package/operand/application/services/parameterService.js +23 -0
  108. package/operand/application/services/parameterService.js.map +1 -0
  109. package/operand/application/services/parser.d.ts +49 -0
  110. package/operand/application/services/parser.d.ts.map +1 -0
  111. package/operand/application/services/parser.js +751 -0
  112. package/operand/application/services/parser.js.map +1 -0
  113. package/operand/application/services/serializer.d.ts +10 -0
  114. package/operand/application/services/serializer.d.ts.map +1 -0
  115. package/operand/application/services/serializer.js +40 -0
  116. package/operand/application/services/serializer.js.map +1 -0
  117. package/operand/application/services/typeService.d.ts +37 -0
  118. package/operand/application/services/typeService.d.ts.map +1 -0
  119. package/operand/application/services/typeService.js +392 -0
  120. package/operand/application/services/typeService.js.map +1 -0
  121. package/operand/application/useCases/build.d.ts +10 -0
  122. package/operand/application/useCases/build.d.ts.map +1 -0
  123. package/operand/application/useCases/build.js +25 -0
  124. package/operand/application/useCases/build.js.map +1 -0
  125. package/operand/application/useCases/clone.d.ts +10 -0
  126. package/operand/application/useCases/clone.d.ts.map +1 -0
  127. package/operand/application/useCases/clone.js +34 -0
  128. package/operand/application/useCases/clone.js.map +1 -0
  129. package/operand/application/useCases/complete.d.ts +9 -0
  130. package/operand/application/useCases/complete.d.ts.map +1 -0
  131. package/operand/application/useCases/complete.js +26 -0
  132. package/operand/application/useCases/complete.js.map +1 -0
  133. package/operand/application/useCases/normalize.d.ts +9 -0
  134. package/operand/application/useCases/normalize.d.ts.map +1 -0
  135. package/operand/application/useCases/normalize.js +43 -0
  136. package/operand/application/useCases/normalize.js.map +1 -0
  137. package/operand/application/useCases/reduce.d.ts +11 -0
  138. package/operand/application/useCases/reduce.d.ts.map +1 -0
  139. package/operand/application/useCases/reduce.js +57 -0
  140. package/operand/application/useCases/reduce.js.map +1 -0
  141. package/operand/domain/constBuilder.d.ts +5 -0
  142. package/operand/domain/constBuilder.d.ts.map +1 -0
  143. package/operand/domain/constBuilder.js +3 -0
  144. package/operand/domain/constBuilder.js.map +1 -0
  145. package/operand/domain/entities.d.ts +60 -0
  146. package/operand/domain/entities.d.ts.map +1 -0
  147. package/operand/domain/entities.js +38 -0
  148. package/operand/domain/entities.js.map +1 -0
  149. package/operand/domain/index.d.ts +4 -0
  150. package/operand/domain/index.d.ts.map +1 -0
  151. package/operand/domain/index.js +20 -0
  152. package/operand/domain/index.js.map +1 -0
  153. package/operand/domain/services.d.ts +39 -0
  154. package/operand/domain/services.d.ts.map +1 -0
  155. package/operand/domain/services.js +3 -0
  156. package/operand/domain/services.js.map +1 -0
  157. package/operand/infrastructure/constBuilder.d.ts +6 -0
  158. package/operand/infrastructure/constBuilder.d.ts.map +1 -0
  159. package/operand/infrastructure/constBuilder.js +15 -0
  160. package/operand/infrastructure/constBuilder.js.map +1 -0
  161. package/operand/infrastructure/executors/expression.d.ts +34 -0
  162. package/operand/infrastructure/executors/expression.d.ts.map +1 -0
  163. package/operand/infrastructure/executors/expression.js +534 -0
  164. package/operand/infrastructure/executors/expression.js.map +1 -0
  165. package/operand/infrastructure/executors/task.d.ts +8 -0
  166. package/operand/infrastructure/executors/task.d.ts.map +1 -0
  167. package/operand/infrastructure/executors/task.js +492 -0
  168. package/operand/infrastructure/executors/task.js.map +1 -0
  169. package/operand/infrastructure/facadeBuilder.d.ts +10 -0
  170. package/operand/infrastructure/facadeBuilder.d.ts.map +1 -0
  171. package/operand/infrastructure/facadeBuilder.js +35 -0
  172. package/operand/infrastructure/facadeBuilder.js.map +1 -0
  173. package/operand/infrastructure/helper.d.ts +20 -0
  174. package/operand/infrastructure/helper.d.ts.map +1 -0
  175. package/operand/infrastructure/helper.js +272 -0
  176. package/operand/infrastructure/helper.js.map +1 -0
  177. package/operand/infrastructure/index.d.ts +4 -0
  178. package/operand/infrastructure/index.d.ts.map +1 -0
  179. package/operand/infrastructure/index.js +20 -0
  180. package/operand/infrastructure/index.js.map +1 -0
  181. package/package.json +39 -0
  182. package/shared/domain/base.d.ts +32 -0
  183. package/shared/domain/base.d.ts.map +1 -0
  184. package/shared/domain/base.js +12 -0
  185. package/shared/domain/base.js.map +1 -0
  186. package/shared/domain/context.d.ts +37 -0
  187. package/shared/domain/context.d.ts.map +1 -0
  188. package/shared/domain/context.js +93 -0
  189. package/shared/domain/context.js.map +1 -0
  190. package/shared/domain/index.d.ts +6 -0
  191. package/shared/domain/index.d.ts.map +1 -0
  192. package/shared/domain/index.js +22 -0
  193. package/shared/domain/index.js.map +1 -0
  194. package/shared/domain/observer.d.ts +15 -0
  195. package/shared/domain/observer.d.ts.map +1 -0
  196. package/shared/domain/observer.js +11 -0
  197. package/shared/domain/observer.js.map +1 -0
  198. package/shared/domain/operand.d.ts +55 -0
  199. package/shared/domain/operand.d.ts.map +1 -0
  200. package/shared/domain/operand.js +69 -0
  201. package/shared/domain/operand.js.map +1 -0
  202. package/shared/domain/signals.d.ts +8 -0
  203. package/shared/domain/signals.d.ts.map +1 -0
  204. package/shared/domain/signals.js +3 -0
  205. package/shared/domain/signals.js.map +1 -0
  206. package/shared/infrastructure/helper.d.ts +9 -0
  207. package/shared/infrastructure/helper.d.ts.map +1 -0
  208. package/shared/infrastructure/helper.js +16 -0
  209. package/shared/infrastructure/helper.js.map +1 -0
  210. package/shared/infrastructure/index.d.ts +2 -0
  211. package/shared/infrastructure/index.d.ts.map +1 -0
  212. package/shared/infrastructure/index.js +18 -0
  213. package/shared/infrastructure/index.js.map +1 -0
@@ -0,0 +1,751 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpressionParse = exports.Parser = void 0;
4
+ const h3lp_1 = require("@data7expressions/h3lp");
5
+ const domain_1 = require("../../../shared/domain");
6
+ const typ3s_1 = require("@data7expressions/typ3s");
7
+ class Parser {
8
+ constructor(model, expression) {
9
+ this.model = model;
10
+ this.expression = expression;
11
+ // this.model = model
12
+ // this.positions = this.normalize(expression)
13
+ this.buffer = this.expression.map(p => p[0]);
14
+ this.length = this.buffer.length;
15
+ this.index = 0;
16
+ this.singleOperators = [];
17
+ this.doubleOperators = [];
18
+ this.tripleOperators = [];
19
+ this.assignmentOperators = [];
20
+ for (const entry of this.model.operators) {
21
+ const name = entry[0];
22
+ const metadata = entry[1];
23
+ if (name.length === 1) {
24
+ this.singleOperators.push(name);
25
+ }
26
+ else if (name.length === 2) {
27
+ this.doubleOperators.push(name);
28
+ if (metadata.priority === 1) {
29
+ this.assignmentOperators.push(name);
30
+ }
31
+ }
32
+ else if (name.length === 3) {
33
+ this.tripleOperators.push(name);
34
+ }
35
+ }
36
+ }
37
+ parse() {
38
+ const operands = [];
39
+ while (!this.end) {
40
+ const operand = this.getExpression(undefined, undefined, ';');
41
+ if (!operand)
42
+ break;
43
+ operands.push(operand);
44
+ }
45
+ return operands.length === 1 ? operands[0] : new domain_1.Operand(new domain_1.Position(0, 0), 'block', domain_1.OperandType.Block, operands);
46
+ }
47
+ getExpression(operand1, operator, _break = '') {
48
+ let expression;
49
+ let operand2;
50
+ let isBreak = false;
51
+ const pos = this.pos();
52
+ while (!this.end) {
53
+ if (!operand1 && !operator) {
54
+ operand1 = this.getOperand();
55
+ operator = this.getOperator();
56
+ if (!operator || _break.includes(this.current)) {
57
+ if (_break.includes(this.current)) {
58
+ this.index += 1;
59
+ }
60
+ expression = operand1;
61
+ isBreak = true;
62
+ break;
63
+ }
64
+ }
65
+ operand2 = this.getOperand();
66
+ const nextOperator = this.getOperator();
67
+ if (operator && operand1) {
68
+ if (!nextOperator || _break.includes(this.current)) {
69
+ if (_break.includes(this.current)) {
70
+ this.index += 1;
71
+ }
72
+ expression = new domain_1.Operand(this.pos(operator.length), operator, domain_1.OperandType.Operator, [operand1, operand2]);
73
+ isBreak = true;
74
+ break;
75
+ }
76
+ else if (this.model.priority(operator) >= this.model.priority(nextOperator)) {
77
+ operand1 = new domain_1.Operand(this.pos(operator.length), operator, domain_1.OperandType.Operator, [operand1, operand2]);
78
+ operator = nextOperator;
79
+ }
80
+ else {
81
+ operand2 = this.getExpression(operand2, nextOperator, _break);
82
+ expression = new domain_1.Operand(this.pos(operator.length), operator, domain_1.OperandType.Operator, [operand1, operand2]);
83
+ isBreak = true;
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ if (!isBreak && operand1 && operand2) {
89
+ expression = new domain_1.Operand(pos, operator, domain_1.OperandType.Operator, [operand1, operand2]);
90
+ }
91
+ return expression;
92
+ }
93
+ getOperand() {
94
+ let isNegative = false;
95
+ let isNot = false;
96
+ let isBitNot = false;
97
+ let operand = null;
98
+ let char = this.current;
99
+ if (char === '-') {
100
+ isNegative = true;
101
+ this.index += 1;
102
+ char = this.current;
103
+ }
104
+ else if (char === '~') {
105
+ isBitNot = true;
106
+ this.index += 1;
107
+ char = this.current;
108
+ }
109
+ else if (char === '!') {
110
+ isNot = true;
111
+ this.index += 1;
112
+ char = this.current;
113
+ }
114
+ const pos = this.pos();
115
+ if (h3lp_1.h3lp.val.isAlphanumeric(char)) {
116
+ let value = this.getValue();
117
+ if (value === 'function' && this.current === '(') {
118
+ this.index += 1;
119
+ operand = this.getFunctionBlock(pos);
120
+ }
121
+ else if (value === 'if' && this.current === '(') {
122
+ this.index += 1;
123
+ operand = this.getIfBlock(pos);
124
+ }
125
+ else if (value === 'for' && this.current === '(') {
126
+ this.index += 1;
127
+ operand = this.getForBlock(pos);
128
+ }
129
+ else if (value === 'while' && this.current === '(') {
130
+ this.index += 1;
131
+ operand = this.getWhileBlock(pos);
132
+ }
133
+ else if (value === 'switch' && this.current === '(') {
134
+ this.index += 1;
135
+ operand = this.getSwitchBlock(pos);
136
+ }
137
+ else if (!this.end && this.current === '(') {
138
+ this.index += 1;
139
+ if (value.includes('.') && !this.model.isFunction(value)) {
140
+ const names = h3lp_1.h3lp.obj.names(value);
141
+ const childName = names.pop();
142
+ const parentName = names.join('.');
143
+ const variable = new domain_1.Operand(pos, parentName, domain_1.OperandType.Var);
144
+ operand = this.getChildFunc(childName, variable);
145
+ }
146
+ else {
147
+ if (this.current === ')') {
148
+ this.index++;
149
+ operand = new domain_1.Operand(pos, value, domain_1.OperandType.CallFunc, []);
150
+ }
151
+ else {
152
+ const args = this.getArgs(')');
153
+ operand = new domain_1.Operand(pos, value, domain_1.OperandType.CallFunc, args);
154
+ }
155
+ }
156
+ }
157
+ else if (value === 'try' && this.current === '{') {
158
+ operand = this.getTryCatchBlock(pos);
159
+ }
160
+ else if (value === 'throw') {
161
+ operand = this.getThrow(pos);
162
+ }
163
+ else if (value === 'return') {
164
+ operand = this.getReturn(pos);
165
+ }
166
+ else if (value === 'break') {
167
+ operand = new domain_1.Operand(pos, 'break', domain_1.OperandType.Break);
168
+ }
169
+ else if (value === 'continue') {
170
+ operand = new domain_1.Operand(pos, 'continue', domain_1.OperandType.Continue);
171
+ }
172
+ else if (!this.end && this.current === '[') {
173
+ this.index += 1;
174
+ operand = this.getIndexOperand(value, pos);
175
+ }
176
+ else if (h3lp_1.h3lp.val.isIntegerFormat(value)) {
177
+ if (isNegative) {
178
+ value = parseInt(value) * -1;
179
+ isNegative = false;
180
+ }
181
+ else if (isBitNot) {
182
+ value = ~parseInt(value);
183
+ isBitNot = false;
184
+ }
185
+ else {
186
+ value = parseInt(value);
187
+ }
188
+ operand = new domain_1.Operand(pos, value, domain_1.OperandType.Const, [], typ3s_1.Type.integer);
189
+ }
190
+ else if (h3lp_1.h3lp.val.isDecimalFormat(value)) {
191
+ if (isNegative) {
192
+ value = parseFloat(value) * -1;
193
+ isNegative = false;
194
+ }
195
+ else if (isBitNot) {
196
+ value = ~parseFloat(value);
197
+ isBitNot = false;
198
+ }
199
+ else {
200
+ value = parseFloat(value);
201
+ }
202
+ operand = new domain_1.Operand(pos, value, domain_1.OperandType.Const, [], typ3s_1.Type.decimal);
203
+ }
204
+ else if (this.model.isConstant(value)) {
205
+ const constantValue = this.model.getConstantValue(value);
206
+ operand = new domain_1.Operand(pos, constantValue, domain_1.OperandType.Const, [], typ3s_1.Type.get(constantValue));
207
+ }
208
+ else if (this.model.isEnum(value)) {
209
+ operand = this.getEnum(value, pos);
210
+ }
211
+ else {
212
+ operand = new domain_1.Operand(pos, value, domain_1.OperandType.Var);
213
+ }
214
+ }
215
+ else if (char === '\'' || char === '"') {
216
+ this.index += 1;
217
+ const result = this.getString(char);
218
+ operand = new domain_1.Operand(pos, result, domain_1.OperandType.Const, [], typ3s_1.Type.string);
219
+ }
220
+ else if (char === '`') {
221
+ this.index += 1;
222
+ const result = this.getTemplate();
223
+ operand = new domain_1.Operand(pos, result, domain_1.OperandType.Template, [], typ3s_1.Type.string);
224
+ }
225
+ else if (char === '(') {
226
+ this.index += 1;
227
+ operand = this.getExpression(undefined, undefined, ')');
228
+ }
229
+ else if (char === '{') {
230
+ this.index += 1;
231
+ operand = this.getObject(pos);
232
+ }
233
+ else if (char === '[') {
234
+ this.index += 1;
235
+ const elements = this.getArgs(']');
236
+ operand = new domain_1.Operand(pos, 'array', domain_1.OperandType.List, elements);
237
+ }
238
+ else if (char === '$') {
239
+ let variableName;
240
+ if (this.offset(1) === '{') {
241
+ this.index += 2;
242
+ variableName = this.getValue();
243
+ if (!this.end && this.nextIs('}')) {
244
+ this.index += 1;
245
+ }
246
+ else {
247
+ throw new Error(`Not found character "}" in Environment variable ${variableName}`);
248
+ }
249
+ }
250
+ else {
251
+ this.index += 1;
252
+ variableName = this.getValue();
253
+ }
254
+ operand = new domain_1.Operand(pos, variableName, domain_1.OperandType.Env);
255
+ }
256
+ if (operand === null) {
257
+ throw new Error('Operand undefined');
258
+ }
259
+ operand = this.solveChain(operand, pos);
260
+ if (isNegative)
261
+ operand = new domain_1.Operand(new domain_1.Position(pos.ln, pos.col - 1), '-', domain_1.OperandType.Operator, [operand]);
262
+ if (isNot)
263
+ operand = new domain_1.Operand(new domain_1.Position(pos.ln, pos.col - 1), '!', domain_1.OperandType.Operator, [operand]);
264
+ if (isBitNot)
265
+ operand = new domain_1.Operand(new domain_1.Position(pos.ln, pos.col - 1), '~', domain_1.OperandType.Operator, [operand]);
266
+ return operand;
267
+ }
268
+ solveChain(operand, pos) {
269
+ if (this.end) {
270
+ return operand;
271
+ }
272
+ if (this.current === '.') {
273
+ this.index += 1;
274
+ const name = this.getValue();
275
+ if (this.current === '(') {
276
+ this.index += 1;
277
+ if (name.includes('.') && !this.model.isFunction(name)) {
278
+ // .xxx.xxx(p=> p.xxx)
279
+ const names = h3lp_1.h3lp.obj.names(name);
280
+ const propertyName = names.slice(0, -1).join('.');
281
+ const functionName = names.slice(-1)[0];
282
+ const property = new domain_1.Operand(pos, propertyName, domain_1.OperandType.Property, [operand]);
283
+ return this.solveChain(this.getChildFunc(functionName, property), pos);
284
+ }
285
+ else {
286
+ // .xxx(p=> p.xxx)
287
+ return this.solveChain(this.getChildFunc(name, operand), pos);
288
+ }
289
+ }
290
+ else if (this.current === '[') {
291
+ this.index += 1;
292
+ if (name.includes('.')) {
293
+ // .xxx.xxx[x]
294
+ const property = new domain_1.Operand(pos, name, domain_1.OperandType.Property, [operand]);
295
+ const idx = this.getExpression(undefined, undefined, ']');
296
+ return new domain_1.Operand(pos, '[]', domain_1.OperandType.Operator, [property, idx]);
297
+ }
298
+ else {
299
+ // .xxx[x]
300
+ const property = new domain_1.Operand(pos, name, domain_1.OperandType.Property, [operand]);
301
+ const idx = this.getExpression(undefined, undefined, ']');
302
+ return new domain_1.Operand(pos, '[]', domain_1.OperandType.Operator, [property, idx]);
303
+ }
304
+ }
305
+ else {
306
+ // .xxx
307
+ return new domain_1.Operand(pos, name, domain_1.OperandType.Property, [operand]);
308
+ }
309
+ }
310
+ else if (this.current === '[') {
311
+ // xxx[x][x] or xxx[x].xxx[x]
312
+ this.index += 1;
313
+ const idx = this.getExpression(undefined, undefined, ']');
314
+ return new domain_1.Operand(pos, '[]', domain_1.OperandType.Operator, [operand, idx]);
315
+ }
316
+ else {
317
+ return operand;
318
+ }
319
+ }
320
+ getOperator() {
321
+ if (this.end) {
322
+ return undefined;
323
+ }
324
+ let op = null;
325
+ if (this.index + 2 < this.length) {
326
+ const triple = this.current + this.offset(1) + this.offset(2);
327
+ if (this.tripleOperators.includes(triple)) {
328
+ op = triple;
329
+ }
330
+ }
331
+ if (op === null && this.index + 1 < this.length) {
332
+ const double = this.current + this.offset(1);
333
+ if (this.doubleOperators.includes(double)) {
334
+ op = double;
335
+ }
336
+ }
337
+ if (op === null) {
338
+ if (!this.model.isOperator(this.current)) {
339
+ return undefined;
340
+ }
341
+ op = this.current;
342
+ }
343
+ this.index += op.length;
344
+ return op;
345
+ }
346
+ normalize(expression) {
347
+ let isString = false;
348
+ let quotes = '';
349
+ const buffer = expression.split('');
350
+ const length = buffer.length;
351
+ const result = [];
352
+ let line = 0;
353
+ let col = 0;
354
+ let i = 0;
355
+ while (i < length) {
356
+ const p = buffer[i];
357
+ if (isString && p === quotes) {
358
+ isString = false;
359
+ }
360
+ else if (!isString && (p === '\'' || p === '"' || p === '`')) {
361
+ isString = true;
362
+ quotes = p;
363
+ }
364
+ if (isString) {
365
+ result.push([p, line, col]);
366
+ }
367
+ else if (p === ' ') {
368
+ // Only leave spaces when it's between alphanumeric characters.
369
+ // for example in the case of "} if" there should not be a space
370
+ if (i + 1 < length && i - 1 >= 0 && h3lp_1.h3lp.val.isAlphanumeric(buffer[i - 1]) && h3lp_1.h3lp.val.isAlphanumeric(buffer[i + 1])) {
371
+ result.push([p, line, col]);
372
+ }
373
+ // when there is a block that ends with "}" and then there is an enter , replace the enter with ";"
374
+ // TODO: si estamos dentro de un objecto NO debería agregar ; luego de } sino rompe el obj
375
+ // } else if (p === '\n' && result.length > 0 && result[result.length - 1] === '}') {
376
+ // result.push(';')
377
+ }
378
+ else if (p === '\n') {
379
+ line++;
380
+ col = 0;
381
+ }
382
+ else if (p !== '\r' && p !== '\t') {
383
+ result.push([p, line, col]);
384
+ }
385
+ i++;
386
+ col++;
387
+ }
388
+ if (result[result.length - 1][0] === ';') {
389
+ result.splice(-1);
390
+ }
391
+ return result;
392
+ }
393
+ get end() {
394
+ return this.index >= this.length;
395
+ }
396
+ get current() {
397
+ return this.buffer[this.index];
398
+ }
399
+ offset(offset = 0) {
400
+ return this.buffer[this.index + offset];
401
+ }
402
+ pos(offset = 0) {
403
+ const position = this.expression[this.index - offset];
404
+ return new domain_1.Position(position[1], position[2]);
405
+ }
406
+ nextIs(key) {
407
+ const array = key.split('');
408
+ for (let i = 0; i < array.length; i++) {
409
+ if (this.buffer[this.index + i] !== array[i]) {
410
+ return false;
411
+ }
412
+ }
413
+ return true;
414
+ }
415
+ getValue(increment = true) {
416
+ const buff = [];
417
+ if (increment) {
418
+ while (!this.end && h3lp_1.h3lp.val.isAlphanumeric(this.current)) {
419
+ buff.push(this.current);
420
+ this.index += 1;
421
+ }
422
+ }
423
+ else {
424
+ let index = this.index;
425
+ while (!this.end && h3lp_1.h3lp.val.isAlphanumeric(this.buffer[index])) {
426
+ buff.push(this.buffer[index]);
427
+ index += 1;
428
+ }
429
+ }
430
+ return buff.join('');
431
+ }
432
+ getString(char) {
433
+ const buff = [];
434
+ while (!this.end) {
435
+ if (this.current === char) {
436
+ if (!((this.index + 1 < this.length && this.offset(1) === char) || (this.offset(-1) === char))) {
437
+ break;
438
+ }
439
+ }
440
+ buff.push(this.current);
441
+ this.index += 1;
442
+ }
443
+ this.index += 1;
444
+ return buff.join('');
445
+ }
446
+ getTemplate() {
447
+ const buff = [];
448
+ while (!this.end) {
449
+ if (this.current === '`') {
450
+ break;
451
+ }
452
+ buff.push(this.current);
453
+ this.index += 1;
454
+ }
455
+ this.index += 1;
456
+ return buff.join('');
457
+ }
458
+ getArgs(end = ')') {
459
+ const args = [];
460
+ while (true) {
461
+ const arg = this.getExpression(undefined, undefined, ',' + end);
462
+ if (arg != null)
463
+ args.push(arg);
464
+ if (this.offset(-1) === end)
465
+ break;
466
+ }
467
+ return args;
468
+ }
469
+ getObject(pos) {
470
+ const attributes = [];
471
+ while (true) {
472
+ let name = null;
473
+ if (this.current === '"' || this.current === '\'') {
474
+ const char = this.current;
475
+ this.index += 1;
476
+ name = this.getString(char);
477
+ }
478
+ else {
479
+ name = this.getValue();
480
+ }
481
+ if (this.current === ':')
482
+ this.index += 1;
483
+ else
484
+ throw new Error('attribute ' + name + ' without value');
485
+ const keyValPos = this.pos();
486
+ const value = this.getExpression(undefined, undefined, ',}');
487
+ const attribute = new domain_1.Operand(keyValPos, name, domain_1.OperandType.KeyVal, [value]);
488
+ attributes.push(attribute);
489
+ if (this.offset(-1) === '}')
490
+ break;
491
+ }
492
+ return new domain_1.Operand(pos, 'obj', domain_1.OperandType.Obj, attributes);
493
+ }
494
+ getBlock() {
495
+ const blockPos = this.pos();
496
+ const lines = [];
497
+ while (true) {
498
+ const line = this.getExpression(undefined, undefined, ';}');
499
+ if (line != null) {
500
+ lines.push(line);
501
+ }
502
+ if (this.offset(-1) === ';' && this.current === '}') {
503
+ this.index += 1;
504
+ break;
505
+ }
506
+ if (this.offset(-1) === '}') {
507
+ break;
508
+ }
509
+ }
510
+ return new domain_1.Operand(blockPos, 'block', domain_1.OperandType.Block, lines);
511
+ }
512
+ getControlBlock() {
513
+ if (this.current === '{') {
514
+ this.index += 1;
515
+ return this.getBlock();
516
+ }
517
+ else {
518
+ return this.getExpression(undefined, undefined, ';');
519
+ }
520
+ }
521
+ getReturn(pos) {
522
+ const value = this.getExpression(undefined, undefined, ';');
523
+ return new domain_1.Operand(pos, 'return', domain_1.OperandType.Return, [value]);
524
+ }
525
+ getTryCatchBlock(pos) {
526
+ const children = [];
527
+ const tryBlock = this.getControlBlock();
528
+ children.push(tryBlock);
529
+ if (this.nextIs('catch')) {
530
+ const catchChildren = [];
531
+ const catchPos = this.pos('catch'.length);
532
+ this.index += 'catch'.length;
533
+ if (this.current === '(') {
534
+ this.index += 1;
535
+ const variable = this.getExpression(undefined, undefined, ')');
536
+ catchChildren.push(variable);
537
+ }
538
+ const catchBlock = this.getControlBlock();
539
+ catchChildren.push(catchBlock);
540
+ const catchNode = new domain_1.Operand(catchPos, 'catch', domain_1.OperandType.Catch, catchChildren);
541
+ children.push(catchNode);
542
+ }
543
+ if (this.current === ';')
544
+ this.index += 1;
545
+ return new domain_1.Operand(pos, 'try', domain_1.OperandType.Try, children);
546
+ }
547
+ getThrow(pos) {
548
+ const exception = this.getExpression(undefined, undefined, ';');
549
+ return new domain_1.Operand(pos, 'throw', domain_1.OperandType.Throw, [exception]);
550
+ }
551
+ getIfBlock(pos) {
552
+ const children = [];
553
+ const condition = this.getExpression(undefined, undefined, ')');
554
+ children.push(condition);
555
+ const block = this.getControlBlock();
556
+ children.push(block);
557
+ while (this.nextIs('elseif(')) {
558
+ const elseIfPos = this.pos();
559
+ this.index += 'elseif('.length;
560
+ const condition = this.getExpression(undefined, undefined, ')');
561
+ const elseIfBlock = this.getControlBlock();
562
+ const elseIfNode = new domain_1.Operand(elseIfPos, 'elseif', domain_1.OperandType.ElseIf, [condition, elseIfBlock]);
563
+ children.push(elseIfNode);
564
+ }
565
+ if (this.nextIs('else')) {
566
+ this.index += 'else'.length;
567
+ const elseBlock = this.getControlBlock();
568
+ children.push(elseBlock);
569
+ }
570
+ return new domain_1.Operand(pos, 'if', domain_1.OperandType.If, children);
571
+ }
572
+ getSwitchBlock(pos) {
573
+ const children = [];
574
+ const value = this.getExpression(undefined, undefined, ')');
575
+ children.push(value);
576
+ if (this.current === '{')
577
+ this.index += 1;
578
+ let next = this.nextIs('case') ? 'case' : this.nextIs('default:') ? 'default:' : '';
579
+ while (next === 'case') {
580
+ this.index += 'case'.length;
581
+ let compare;
582
+ if (this.current === '\'' || this.current === '"') {
583
+ const char = this.current;
584
+ this.index += 1;
585
+ compare = this.getString(char);
586
+ }
587
+ else {
588
+ compare = this.getValue();
589
+ }
590
+ const caseNode = new domain_1.Operand(this.pos(), compare, domain_1.OperandType.Case);
591
+ const block = new domain_1.Operand(this.pos(), 'block', domain_1.OperandType.Block);
592
+ caseNode.children = [block];
593
+ if (this.current === ':')
594
+ this.index += 1;
595
+ const lines = [];
596
+ while (true) {
597
+ const line = this.getExpression(undefined, undefined, ';}');
598
+ if (line !== undefined)
599
+ lines.push(line);
600
+ if (this.nextIs('case')) {
601
+ next = 'case';
602
+ break;
603
+ }
604
+ else if (this.nextIs('default:')) {
605
+ next = 'default:';
606
+ break;
607
+ }
608
+ else if (this.current === '}' || this.offset(-1) === '}') {
609
+ next = 'end';
610
+ break;
611
+ }
612
+ }
613
+ block.children = lines;
614
+ children.push(caseNode);
615
+ }
616
+ if (next === 'default:') {
617
+ this.index += 'default:'.length;
618
+ const defaultNode = new domain_1.Operand(this.pos(), 'default', domain_1.OperandType.Default);
619
+ const block = new domain_1.Operand(this.pos(), 'block', domain_1.OperandType.Block);
620
+ defaultNode.children = [block];
621
+ const lines = [];
622
+ while (true) {
623
+ const line = this.getExpression(undefined, undefined, ';}');
624
+ if (line !== undefined)
625
+ lines.push(line);
626
+ if (this.current === '}' || this.offset(-1) === '}')
627
+ break;
628
+ }
629
+ block.children = lines;
630
+ children.push(defaultNode);
631
+ }
632
+ if (this.current === '}')
633
+ this.index += 1;
634
+ return new domain_1.Operand(pos, 'switch', domain_1.OperandType.Switch, children);
635
+ }
636
+ getWhileBlock(pos) {
637
+ const condition = this.getExpression(undefined, undefined, ')');
638
+ const block = this.getControlBlock();
639
+ return new domain_1.Operand(pos, 'while', domain_1.OperandType.While, [condition, block]);
640
+ }
641
+ getForBlock(pos) {
642
+ const first = this.getExpression(undefined, undefined, '; ');
643
+ if (this.offset(-1) === ';') {
644
+ const condition = this.getExpression(undefined, undefined, ';');
645
+ const increment = this.getExpression(undefined, undefined, ')');
646
+ const block = this.getControlBlock();
647
+ return new domain_1.Operand(pos, 'for', domain_1.OperandType.For, [first, condition, increment, block]);
648
+ }
649
+ else if (this.nextIs('in')) {
650
+ this.index += 2;
651
+ // si hay espacios luego del in debe eliminarlos
652
+ while (this.current === ' ') {
653
+ this.index += 1;
654
+ }
655
+ const list = this.getExpression(undefined, undefined, ')');
656
+ const block = this.getControlBlock();
657
+ return new domain_1.Operand(pos, 'forIn', domain_1.OperandType.ForIn, [first, list, block]);
658
+ }
659
+ throw new Error('expression for error');
660
+ }
661
+ getFunctionBlock(pos) {
662
+ const name = this.getValue();
663
+ if (this.current === '(')
664
+ this.index += 1;
665
+ const argsPos = this.pos();
666
+ const args = this.getArgs();
667
+ const block = this.getBlock();
668
+ const argsOperand = new domain_1.Operand(argsPos, 'args', domain_1.OperandType.Args, args);
669
+ return new domain_1.Operand(pos, name, domain_1.OperandType.Func, [argsOperand, block]);
670
+ }
671
+ getChildFunc(name, parent) {
672
+ let isArrow = false;
673
+ const pos = this.pos();
674
+ const variableName = this.getValue(false);
675
+ if (variableName !== '') {
676
+ // example: p => {name:p.name}
677
+ // example: p -> {name:p.name}
678
+ const i = variableName.length;
679
+ if ((this.offset(i) === '=' || this.offset(i) === '-') && this.offset(i + 1) === '>') {
680
+ isArrow = true;
681
+ this.index += (variableName.length + 2); // [VARIABLE+NAME] + [=>]
682
+ }
683
+ }
684
+ else if (this.current + this.offset(1) === '()') {
685
+ // example: ()=> {name:name}
686
+ // example: ()-> {name:name}
687
+ if ((this.offset(2) === '=' || this.offset(2) === '-') && this.offset(3) === '>') {
688
+ isArrow = true;
689
+ this.index += 4; // [()=>]
690
+ }
691
+ }
692
+ else if (this.current + this.offset(1) === '=>' || this.current + this.offset(1) === '->') {
693
+ // example: => {name:name}
694
+ // example: -> {name:name}
695
+ isArrow = true;
696
+ this.index += 2; // [=>]
697
+ }
698
+ if (isArrow) {
699
+ const variable = new domain_1.Operand(pos, variableName, domain_1.OperandType.Var);
700
+ const body = this.getExpression(undefined, undefined, ')');
701
+ return new domain_1.Operand(pos, name, domain_1.OperandType.Arrow, [parent, variable, body]);
702
+ }
703
+ else {
704
+ if (this.current === ')') {
705
+ this.index += 1;
706
+ // Example: xxx.xxx()
707
+ return new domain_1.Operand(pos, name, domain_1.OperandType.ChildFunc, [parent]);
708
+ }
709
+ // Example: xxx.xxx(x)
710
+ const args = this.getArgs(')');
711
+ args.splice(0, 0, parent);
712
+ return new domain_1.Operand(pos, name, domain_1.OperandType.ChildFunc, args);
713
+ }
714
+ }
715
+ getIndexOperand(name, pos) {
716
+ const idx = this.getExpression(undefined, undefined, ']');
717
+ const operand = new domain_1.Operand(pos, name, domain_1.OperandType.Var);
718
+ return new domain_1.Operand(pos, '[]', domain_1.OperandType.Operator, [operand, idx]);
719
+ }
720
+ getEnum(value, pos) {
721
+ if (value.includes('.') && this.model.isEnum(value)) {
722
+ const names = value.split('.');
723
+ const enumName = names[0];
724
+ const enumOption = names[1];
725
+ const enumValue = this.model.getEnumValue(enumName, enumOption);
726
+ return new domain_1.Operand(pos, enumValue, domain_1.OperandType.Const, [], typ3s_1.Type.get(value));
727
+ }
728
+ else {
729
+ const values = this.model.getEnum(value);
730
+ const attributes = [];
731
+ for (const name in values) {
732
+ const _value = values[name];
733
+ const attribute = new domain_1.Operand(pos, name, domain_1.OperandType.KeyVal, [new domain_1.Operand(pos, _value, domain_1.OperandType.Const, [], typ3s_1.Type.get(_value))]);
734
+ attributes.push(attribute);
735
+ }
736
+ return new domain_1.Operand(pos, 'obj', domain_1.OperandType.Obj, attributes);
737
+ }
738
+ }
739
+ }
740
+ exports.Parser = Parser;
741
+ class ExpressionParse {
742
+ // eslint-disable-next-line no-useless-constructor
743
+ constructor(model) {
744
+ this.model = model;
745
+ }
746
+ parse(expression) {
747
+ return new Parser(this.model, expression).parse();
748
+ }
749
+ }
750
+ exports.ExpressionParse = ExpressionParse;
751
+ //# sourceMappingURL=parser.js.map