vue2-client 1.11.4 → 1.11.6-alpha

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 (57) hide show
  1. package/.babelrc +3 -0
  2. package/babel.config.js +18 -21
  3. package/jest.config.js +22 -21
  4. package/package.json +5 -4
  5. package/src/base-client/components/common/CitySelect/CitySelect.vue +366 -342
  6. package/src/base-client/components/common/Upload/Upload.vue +322 -322
  7. package/src/base-client/components/common/XDescriptions/XDescriptionsGroup.vue +314 -304
  8. package/src/base-client/components/common/XDescriptions/demo.vue +51 -50
  9. package/src/base-client/components/common/XFormGroup/demo.vue +39 -46
  10. package/src/base-client/components/common/XFormTable/demo.vue +60 -60
  11. package/src/components/STable/index.js +426 -426
  12. package/src/expression/ExpressionRunner.js +26 -0
  13. package/src/expression/TestExpression.js +508 -0
  14. package/src/expression/core/Delegate.js +113 -0
  15. package/src/expression/core/Expression.js +1323 -0
  16. package/src/expression/core/Program.js +933 -0
  17. package/src/expression/core/Token.js +27 -0
  18. package/src/expression/enums/ExpressionType.js +81 -0
  19. package/src/expression/enums/TokenType.js +11 -0
  20. package/src/expression/exception/BreakWayException.js +2 -0
  21. package/src/expression/exception/ContinueWayException.js +2 -0
  22. package/src/expression/exception/ExpressionException.js +28 -0
  23. package/src/expression/exception/ReturnWayException.js +14 -0
  24. package/src/expression/exception/ServiceException.js +22 -0
  25. package/src/expression/instances/JSONArray.js +48 -0
  26. package/src/expression/instances/JSONObject.js +122 -0
  27. package/src/expression/instances/LogicConsole.js +45 -0
  28. package/src/expression/ts/ExpressionRunner.ts +28 -0
  29. package/src/expression/ts/TestExpression.ts +509 -0
  30. package/src/expression/ts/core/Delegate.ts +114 -0
  31. package/src/expression/ts/core/Expression.ts +1309 -0
  32. package/src/expression/ts/core/Program.ts +950 -0
  33. package/src/expression/ts/core/Token.ts +29 -0
  34. package/src/expression/ts/enums/ExpressionType.ts +81 -0
  35. package/src/expression/ts/enums/TokenType.ts +13 -0
  36. package/src/expression/ts/exception/BreakWayException.ts +2 -0
  37. package/src/expression/ts/exception/ContinueWayException.ts +2 -0
  38. package/src/expression/ts/exception/ExpressionException.ts +28 -0
  39. package/src/expression/ts/exception/ReturnWayException.ts +14 -0
  40. package/src/expression/ts/exception/ServiceException.ts +22 -0
  41. package/src/expression/ts/instances/JSONArray.ts +48 -0
  42. package/src/expression/ts/instances/JSONObject.ts +109 -0
  43. package/src/expression/ts/instances/LogicConsole.ts +32 -0
  44. package/src/logic/LogicRunner.js +67 -0
  45. package/src/logic/TestLogic.js +13 -0
  46. package/src/logic/plugins/common/DateTools.js +32 -0
  47. package/src/logic/plugins/index.js +5 -0
  48. package/src/logic/ts/LogicRunner.ts +67 -0
  49. package/src/logic/ts/TestLogic.ts +13 -0
  50. package/src/pages/LogicCallExample/index.vue +30 -0
  51. package/src/router/async/router.map.js +4 -2
  52. package/src/services/user.js +2 -0
  53. package/src/store/mutation-types.js +1 -0
  54. package/src/utils/EncryptUtil.js +23 -0
  55. package/src/utils/indexedDB.js +234 -234
  56. package/src/utils/request.js +382 -362
  57. package/test/request.test.js +17 -0
@@ -0,0 +1,933 @@
1
+ import Token from './Token'
2
+ import Expression from './Expression'
3
+ import Delegate from './Delegate'
4
+ import ExpressionType from '../enums/ExpressionType'
5
+ import TokenType from '../enums/TokenType'
6
+ import JSONArray from '../instances/JSONArray'
7
+
8
+ /**
9
+ * 表达式入口
10
+ */
11
+ export default class Program {
12
+ // 源程序
13
+ SOURCE
14
+ SOURCE_LENGTH
15
+ /**
16
+ * Token队列,用于回退
17
+ */
18
+ tokens = []
19
+ /**
20
+ * 字符串处理环节堆栈,$进入字符串处理环节,“{}”中间部分脱离字符串处理环节
21
+ */
22
+ inStrings = []
23
+
24
+ /**
25
+ * 当前获取到的字符位置
26
+ */
27
+ pos = 0
28
+
29
+ /**
30
+ * 当前是否在字符串处理环节
31
+ */
32
+ inString = false
33
+
34
+ constructor (source) {
35
+ this.SOURCE = source
36
+ this.SOURCE_LENGTH = this.SOURCE.length
37
+ }
38
+
39
+ /**
40
+ * 调用解析过程
41
+ */
42
+ parse () {
43
+ // 执行完以下方法后就已经诞生了一个完整的执行流程,也就是被翻译成了一套完整的指令集。
44
+ return this.createDelegate(this.expression())
45
+ }
46
+
47
+ parseExpression (expression) {
48
+ // 执行完以下方法后就已经诞生了一个完整的执行流程,也就是被翻译成了一套完整的指令集。
49
+ return this.createDelegate(expression)
50
+ }
51
+
52
+ /**
53
+ * 编译,产生可执行单元Delegate
54
+ */
55
+ createDelegate (expression) {
56
+ return new Delegate(expression, this.SOURCE)
57
+ }
58
+
59
+ /**
60
+ * 获取完整表达式
61
+ */
62
+ expression () {
63
+ const expression = this.CommaExp()
64
+ if (this.pos < this.SOURCE_LENGTH) {
65
+ throw new Error(this.GetExceptionMessage('需要逗号结尾!'))
66
+ }
67
+ return expression
68
+ }
69
+
70
+ /**
71
+ * 逗号表达式=赋值表达式(,赋值表达式)*
72
+ */
73
+ CommaExp () {
74
+ const exps = []
75
+
76
+ const first = this.AssignExp()
77
+ exps.push(first)
78
+
79
+ let t = this.GetToken()
80
+
81
+ // 没有结束
82
+ while (t.getType() === TokenType.Oper && (t.getValue() === ',' || t.getValue() === ';' || t.getValue() === '\n')) {
83
+ const r = this.AssignExp()
84
+ exps.push(r)
85
+ t = this.GetToken()
86
+ }
87
+
88
+ this.tokens.push(t)
89
+
90
+ return Expression.Comma(exps, this.pos)
91
+ }
92
+
93
+ /**
94
+ * 赋值表达式=对象属性=一般表达式|一般表达式
95
+ */
96
+ AssignExp () {
97
+ let t = this.GetToken()
98
+
99
+ // 把第一个Token的位置记录下来,方便后面回退
100
+ const firstPos = t.getStartPos()
101
+
102
+ if (t.getType() !== TokenType.Identy) {
103
+ this.pos = firstPos
104
+ this.tokens.length = 0 // Clear the tokens array
105
+ this.inString = false
106
+ return this.Exp()
107
+ }
108
+
109
+ let objExp = Expression.Identity(t.getValue(), this.pos)
110
+ objExp = this.ObjectPath(objExp)
111
+
112
+ // 只能给对象属性或者变量赋值
113
+ if (objExp.type !== ExpressionType.Property && objExp.type !== ExpressionType.Identity) {
114
+ this.pos = firstPos
115
+ this.tokens.length = 0
116
+ this.inString = false
117
+ return this.Exp()
118
+ }
119
+
120
+ t = this.GetToken()
121
+ if (t.getType() !== TokenType.Oper || t.getValue() !== '=') {
122
+ this.pos = firstPos
123
+ this.tokens.length = 0
124
+ this.inString = false
125
+ return this.Exp()
126
+ }
127
+
128
+ const exp = this.Exp()
129
+
130
+ // 如果是属性赋值
131
+ if (objExp.type === ExpressionType.Property) {
132
+ // 从属性Expression中获取对象及属性名
133
+ const name = objExp.value
134
+ objExp = objExp.children[0]
135
+ return Expression.Assign(objExp, exp, name, this.pos)
136
+ } else {
137
+ // Identity 变量赋值
138
+ return Expression.Assign(null, exp, objExp.value, this.pos)
139
+ }
140
+ }
141
+
142
+ Exp () {
143
+ const v = this.Logic()
144
+
145
+ // 是':',表示条件,否则直接返回单结果
146
+ let t = this.GetToken()
147
+ if (t.getType() === TokenType.Oper && t.getValue() === ':') {
148
+ // 第一项转换
149
+ const result = this.Logic()
150
+
151
+ // 下一个是",",继续读取下一个条件结果串,由于是右结合,只能采用递归
152
+ t = this.GetToken()
153
+ if (t.getType() === TokenType.Oper && t.getValue() === ',') {
154
+ // 第二项转换
155
+ const sExp = this.Exp()
156
+ // 返回
157
+ return Expression.Condition(v, result, sExp, this.SOURCE, this.pos)
158
+ } else {
159
+ throw new Error(this.GetExceptionMessage('必须有默认值!'))
160
+ }
161
+ } else {
162
+ this.tokens.push(t) // Put the token back
163
+ return v
164
+ }
165
+ }
166
+
167
+ Logic () {
168
+ let t = this.GetToken()
169
+
170
+ // !表达式
171
+ const hasNot = t.getType() === TokenType.Oper && t.getValue() === '!'
172
+ if (!hasNot) {
173
+ this.tokens.push(t) // Put the token back if it's not '!'
174
+ }
175
+
176
+ let v = this.Compare()
177
+ if (hasNot) {
178
+ v = Expression.Not(v, this.SOURCE, this.pos)
179
+ }
180
+
181
+ t = this.GetToken()
182
+ while (t.getType() === TokenType.Oper && (t.getValue() === '&&' || t.getValue() === '||')) {
183
+ // 第二项转换
184
+ const exp = this.Logic()
185
+
186
+ // 执行
187
+ if (t.getValue() === '&&') {
188
+ v = Expression.And(v, exp, this.SOURCE, this.pos)
189
+ } else {
190
+ v = Expression.Or(v, exp, this.SOURCE, this.pos)
191
+ }
192
+
193
+ t = this.GetToken()
194
+ }
195
+
196
+ this.tokens.push(t) // Put the token back
197
+ return v
198
+ }
199
+
200
+ Compare () {
201
+ const left = this.Math()
202
+ const t = this.GetToken()
203
+
204
+ if (t.getType() === TokenType.Oper && (
205
+ t.getValue() === '>' || t.getValue() === '>=' ||
206
+ t.getValue() === '<' || t.getValue() === '<=' || t.getValue() === '=>')) {
207
+ if (t.getValue() === '=>') {
208
+ this.tokens.push(t) // Push back the token for lambda handling
209
+ return this.Lambda()
210
+ }
211
+
212
+ const rExp = this.Math()
213
+
214
+ switch (t.getValue()) {
215
+ case '>':
216
+ return Expression.GreaterThan(left, rExp, this.SOURCE, this.pos)
217
+ case '>=':
218
+ return Expression.GreaterThanOrEqual(left, rExp, this.SOURCE, this.pos)
219
+ case '<':
220
+ return Expression.LessThan(left, rExp, this.SOURCE, this.pos)
221
+ case '<=':
222
+ return Expression.LessThanOrEqual(left, rExp, this.SOURCE, this.pos)
223
+ }
224
+ } else if (t.getType() === TokenType.Oper && (
225
+ t.getValue() === '==' || t.getValue() === '!=')) {
226
+ const rExp = this.Math()
227
+
228
+ // 相等比较
229
+ if (t.getValue() === '==') {
230
+ return Expression.Equal(left, rExp, this.SOURCE, this.pos)
231
+ } else {
232
+ return Expression.NotEqual(left, rExp, this.SOURCE, this.pos)
233
+ }
234
+ }
235
+
236
+ // 返回当前的表达式结果
237
+ this.tokens.push(t) // Push the token back
238
+ return left
239
+ }
240
+
241
+ Math () {
242
+ let v = this.Mul()
243
+ let t = this.GetToken()
244
+
245
+ while (t.getType() === TokenType.Oper && (t.getValue() === '+' || t.getValue() === '-')) {
246
+ // 转换操作数2为数字
247
+ const r = this.Mul()
248
+
249
+ // 开始运算
250
+ if (t.getValue() === '+') {
251
+ v = Expression.Add(v, r, this.SOURCE, this.pos)
252
+ } else {
253
+ v = Expression.Subtract(v, r, this.SOURCE, this.pos)
254
+ }
255
+
256
+ t = this.GetToken()
257
+ }
258
+
259
+ this.tokens.push(t) // Push the token back
260
+ return v
261
+ }
262
+
263
+ Lambda () {
264
+ let t = this.GetToken()
265
+ if (t.getValue() !== '=>' || t.getValue() == null) {
266
+ throw new Error(this.GetExceptionMessage('lambda必须以=>开始'))
267
+ }
268
+
269
+ t = this.GetToken()
270
+ if (t.getValue() !== '{' || t.getValue() == null) {
271
+ throw new Error(this.GetExceptionMessage('lambda必须以{开始'))
272
+ }
273
+
274
+ // 取lambda中的表达式
275
+ const exp = this.CommaExp()
276
+
277
+ t = this.GetToken()
278
+ if (t.getValue() !== '}' || t.getValue() == null) {
279
+ throw new Error(this.GetExceptionMessage('lambda必须以}结束'))
280
+ }
281
+
282
+ return Expression.Lambda(exp, this.pos)
283
+ }
284
+
285
+ Mul () {
286
+ let v = this.UnarySub()
287
+ let t = this.GetToken()
288
+
289
+ while (t.getType() === TokenType.Oper && (t.getValue() === '*' || t.getValue() === '/' || t.getValue() === '%')) {
290
+ // Convert the second operand to a number
291
+ const r = this.UnarySub()
292
+
293
+ // Perform the operation
294
+ if (t.getValue() === '*') {
295
+ v = Expression.Multiply(v, r, this.SOURCE, this.pos)
296
+ } else if (t.getValue() === '/') {
297
+ v = Expression.Divide(v, r, this.SOURCE, this.pos)
298
+ } else {
299
+ v = Expression.Modulo(v, r, this.SOURCE, this.pos)
300
+ }
301
+
302
+ t = this.GetToken()
303
+ }
304
+
305
+ this.tokens.push(t)
306
+ return v
307
+ }
308
+
309
+ UnarySub () {
310
+ const t = this.GetToken()
311
+ if (t.getType() === TokenType.Oper && t.getValue() === '-') {
312
+ const r = this.Item()
313
+ return Expression.Subtract(Expression.Constant(0, this.pos), r, this.SOURCE, this.pos)
314
+ }
315
+ this.tokens.push(t) // Push the token back into the queue
316
+ return this.Item()
317
+ }
318
+
319
+ Item () {
320
+ const objName = ''
321
+ // 获取对象表达式
322
+ let objExp = this.ItemHead(objName)
323
+ // 获取对象路径表达式
324
+ objExp = this.ObjectPath(objExp)
325
+ return objExp
326
+ }
327
+
328
+ ItemHead (name) {
329
+ let t = this.GetToken()
330
+
331
+ if (t.getType() === TokenType.Oper && t.getValue() === '(') {
332
+ const result = this.CommaExp()
333
+ t = this.GetToken()
334
+ if (t.getType() !== TokenType.Oper || t.getValue() !== ')') {
335
+ throw new Error(this.GetExceptionMessage('括号不匹配'))
336
+ }
337
+ return result
338
+ } else if (t.getType() === TokenType.Oper && t.getValue() === '{') {
339
+ // JSON object
340
+ return this.Json()
341
+ } else if (t.getType() === TokenType.Oper && t.getValue() === '[') {
342
+ // JSON array
343
+ return this.JsonArray()
344
+ } else if (t.getType() === TokenType.Oper && (t.getValue() === '$' || t.getValue() === '"')) {
345
+ // String concatenation sequence
346
+ return this.StringUnion()
347
+ } else if (t.getType() === TokenType.Int || t.getType() === TokenType.Double || t.getType() === TokenType.Bool) {
348
+ return Expression.Constant(t.getValue(), this.pos)
349
+ } else if (t.getType() === TokenType.Identy) {
350
+ const objName = t.getValue()
351
+
352
+ switch (objName) {
353
+ case 'return':
354
+ return Expression.Return(this.Exp(), this.pos)
355
+ case 'try':
356
+ this.tokens.push(t) // Revert the token back to the queue
357
+ return this.Try()
358
+ case 'throw':
359
+ return Expression.Throw(this.Exp(), this.pos)
360
+ case 'validate':
361
+ return this.Validate()
362
+ case 'assert':
363
+ return Expression.Assert(this.Exp(), this.pos)
364
+ case 'break':
365
+ return Expression.Break(this.pos, undefined)
366
+ case 'continue':
367
+ return Expression.Continue(this.pos, undefined)
368
+ }
369
+
370
+ // Return the object name
371
+ name += objName
372
+ // Process the object name
373
+ return this.ObjectName(objName)
374
+ } else if (t.getType() === TokenType.Null) {
375
+ return Expression.Constant(null, this.pos)
376
+ }
377
+
378
+ throw new Error(this.GetExceptionMessage('单词类型错误:' + t.getType()))
379
+ }
380
+
381
+ /**
382
+ * TryCatch := try {expression} (catch(Exception类 名){表达式})* finally{表达式}?
383
+ */
384
+ Try () {
385
+ let t = this.GetToken()
386
+ if (t.getValue() !== 'try') {
387
+ throw new Error(this.GetExceptionMessage('try-catch必须以try开始'))
388
+ }
389
+
390
+ t = this.GetToken()
391
+ if (t.getValue() !== '{') {
392
+ throw new Error(this.GetExceptionMessage('try块必须以{开始'))
393
+ }
394
+
395
+ // Get the expression inside the try block
396
+ const tryExp = this.CommaExp()
397
+
398
+ t = this.GetToken()
399
+ if (t.getValue() !== '}') {
400
+ throw new Error(this.GetExceptionMessage('try块必须以}结束'))
401
+ }
402
+
403
+ // Handle the catch part
404
+ const catches = this.Catch()
405
+
406
+ // Handle finally
407
+ let finallyExp
408
+ t = this.GetToken()
409
+ if (t.getValue()) {
410
+ if (t.getValue() === 'finally') {
411
+ t = this.GetToken()
412
+ if (t.getValue() !== '{') {
413
+ throw new Error(this.GetExceptionMessage('finally块必须以{开始'))
414
+ }
415
+
416
+ // Get the expression inside the finally block
417
+ finallyExp = this.CommaExp()
418
+ t = this.GetToken()
419
+ if (t.getValue() !== '}') {
420
+ throw new Error(this.GetExceptionMessage('finally块必须以}结束'))
421
+ }
422
+ t = this.GetToken()
423
+ }
424
+ }
425
+
426
+ this.tokens.push(t)
427
+
428
+ // Return the exception handling expression
429
+ return Expression.Try(tryExp, catches, this.pos, finallyExp)
430
+ }
431
+
432
+ /**
433
+ * catch部分处理
434
+ */
435
+ Catch () {
436
+ const result = []
437
+ let t = this.GetToken()
438
+
439
+ while (t.getValue() === 'catch') {
440
+ t = this.GetToken()
441
+ if (t.getValue() !== '(') {
442
+ throw new Error(this.GetExceptionMessage('catch块参数必须以(开始'))
443
+ }
444
+
445
+ // Get the class name
446
+ t = this.GetToken()
447
+ const className = t.getValue()
448
+
449
+ // Get the variable name
450
+ t = this.GetToken()
451
+ const varName = t.getValue()
452
+
453
+ t = this.GetToken()
454
+ if (t.getValue() !== ')') {
455
+ throw new Error(this.GetExceptionMessage('catch块参数必须以)结束'))
456
+ }
457
+
458
+ // Get the opening curly brace
459
+ t = this.GetToken()
460
+ if (t.getValue() !== '{') {
461
+ throw new Error(this.GetExceptionMessage('catch块必须以{开始'))
462
+ }
463
+
464
+ // Get the expression inside the catch block
465
+ const catchExp = this.CommaExp()
466
+ result.push(Expression.Catch(className, varName, catchExp, this.pos))
467
+
468
+ // Get the closing curly brace
469
+ t = this.GetToken()
470
+ if (t.getValue() !== '}') {
471
+ throw new Error(this.GetExceptionMessage('catch块必须以}结束'))
472
+ }
473
+
474
+ // Get the next token
475
+ t = this.GetToken()
476
+ }
477
+
478
+ this.tokens.push(t)
479
+ return result
480
+ }
481
+
482
+ /**
483
+ * Validate block handling
484
+ */
485
+ Validate () {
486
+ const t = this.GetToken()
487
+ if (t.getValue() !== '{') {
488
+ throw new Error(this.GetExceptionMessage('validate只接收Json对象'))
489
+ }
490
+
491
+ // Get the expression in the validate block
492
+ const exp = this.Json()
493
+
494
+ // Return Validate processing expression
495
+ return Expression.Validate(exp, this.pos)
496
+ }
497
+
498
+ /**
499
+ * JSON Object ::= {} | {propertyName: propertyValue, propertyName: propertyValue}
500
+ */
501
+ Json () {
502
+ const children = []
503
+
504
+ let t = this.GetToken()
505
+ // Empty object, return directly
506
+ if (t.getType() === TokenType.Oper && t.getValue() === '}') {
507
+ return Expression.Json(children, this.pos)
508
+ }
509
+
510
+ this.tokens.push(t)
511
+ children.push(this.Attr())
512
+ t = this.GetToken()
513
+
514
+ // If it's a comma, continue checking the next property
515
+ while (t.getType() === TokenType.Oper && t.getValue() === ',') {
516
+ const nextT = this.GetToken()
517
+ if (nextT.getType() === TokenType.Oper && nextT.getValue() === '}') {
518
+ t = nextT
519
+ break
520
+ }
521
+ this.tokens.push(nextT)
522
+ children.push(this.Attr())
523
+ t = this.GetToken()
524
+ }
525
+
526
+ if (t.getType() !== TokenType.Oper || t.getValue() !== '}') {
527
+ throw new Error(this.GetExceptionMessage('JSON对象构建错误'))
528
+ }
529
+
530
+ return Expression.Json(children, this.pos)
531
+ }
532
+
533
+ /**
534
+ * JSON Array ::= []
535
+ */
536
+ JsonArray () {
537
+ let t = this.GetToken()
538
+ // Empty array, return directly
539
+ if (t.getType() === TokenType.Oper && t.getValue() === ']') {
540
+ // Return JSON array constant
541
+ return Expression.Constant(new JSONArray(), this.pos)
542
+ }
543
+
544
+ // Loop to get array contents
545
+ this.tokens.push(t)
546
+ const ps = this.Params()
547
+ t = this.GetToken()
548
+ if (t.getType() !== TokenType.Oper || t.getValue() !== ']') {
549
+ throw new Error(this.GetExceptionMessage('JSON集合构建错误'))
550
+ }
551
+
552
+ return Expression.Array(ps, this.pos)
553
+ }
554
+
555
+ /**
556
+ * Attribute-Value Pair ::= propertyName: propertyValue
557
+ */
558
+ Attr () {
559
+ const name = this.GetToken()
560
+ let value
561
+ if (name.getType() === TokenType.Identy) {
562
+ value = name.getValue()
563
+ } else if (name.getType() === TokenType.Oper && (name.getValue() === '$' || name.getValue() === '"')) {
564
+ const expression = this.StringUnion().children[1]
565
+ value = expression.value
566
+ } else {
567
+ throw new Error(this.GetExceptionMessage('JSON对象的key必须是属性名或字符串'))
568
+ }
569
+
570
+ const t = this.GetToken()
571
+ if (t.getType() !== TokenType.Oper || t.getValue() !== ':') {
572
+ throw new Error(this.GetExceptionMessage('JSON构建错误'))
573
+ }
574
+
575
+ const exp = this.Exp()
576
+ return Expression.Attr(value, exp, this.pos)
577
+ }
578
+
579
+ /**
580
+ * Parse string concatenation sequence
581
+ */
582
+ StringUnion () {
583
+ let exp = Expression.Constant('', this.pos)
584
+ let t = this.GetToken()
585
+ // Object sequence
586
+ while ((t.getType() === TokenType.Oper && t.getValue() === '{') || t.getType() === TokenType.String) {
587
+ // If it's a string, return the concatenated result
588
+ if (t.getType() === TokenType.String) {
589
+ exp = Expression.Concat(exp, Expression.Constant(t.getValue(), this.pos), this.SOURCE, this.pos)
590
+ } else {
591
+ // Handle content inside the {}
592
+ const objExp = this.Exp()
593
+ t = this.GetToken()
594
+ if (t.getType() !== TokenType.Oper || t.getValue() !== '}') {
595
+ throw new Error(this.GetExceptionMessage("缺少'}'"))
596
+ }
597
+ // String concatenation
598
+ exp = Expression.Concat(exp, objExp, this.SOURCE, this.pos)
599
+ }
600
+ t = this.GetToken()
601
+ }
602
+ this.tokens.push(t)
603
+ return exp
604
+ }
605
+
606
+ /**
607
+ * Get object and object expression by name
608
+ */
609
+ ObjectName (objName) {
610
+ return Expression.Identity(objName, this.pos)
611
+ }
612
+
613
+ /**
614
+ * Object path parsing, handles method calls, properties, and array indices
615
+ */
616
+ ObjectPath (inExp) {
617
+ let objExp = this.ArrayIndex(inExp)
618
+ let t = this.GetToken()
619
+ while (t.getType() === TokenType.Oper && t.getValue() === '.') {
620
+ const nameToken = this.GetToken()
621
+ const n = this.GetToken()
622
+ if (n.getType() === TokenType.Oper && n.getValue() === '(') {
623
+ const name = nameToken.getValue()
624
+ if (name === 'each') {
625
+ objExp = this.For(objExp)
626
+ } else {
627
+ objExp = this.MethodCall(name, objExp)
628
+ }
629
+ } else {
630
+ this.tokens.push(n)
631
+ const pi = nameToken.getValue()
632
+ objExp = Expression.Property(objExp, pi, this.pos)
633
+ objExp = this.ArrayIndex(objExp)
634
+ }
635
+ t = this.GetToken()
636
+ }
637
+ this.tokens.push(t)
638
+
639
+ return objExp
640
+ }
641
+
642
+ /**
643
+ * Array index parsing with optional condition
644
+ */
645
+ ArrayIndex (objExp) {
646
+ let n = this.GetToken()
647
+ if (n.getType() === TokenType.Oper && n.getValue() === '[') {
648
+ const exp = this.Exp()
649
+ n = this.GetToken()
650
+ if (n.getType() !== TokenType.Oper || n.getValue() !== ']') {
651
+ throw new Error(this.GetExceptionMessage("缺少']'"))
652
+ }
653
+ return Expression.ArrayIndex(objExp, exp, this.SOURCE, this.pos)
654
+ }
655
+ this.tokens.push(n)
656
+ return objExp
657
+ }
658
+
659
+ /**
660
+ * For loop handling
661
+ */
662
+ For (obj) {
663
+ const exp = this.CommaExp()
664
+ const t = this.GetToken()
665
+ if (t.getType() !== TokenType.Oper || t.getValue() !== ')') {
666
+ throw new Error(this.GetExceptionMessage('函数调用括号不匹配'))
667
+ }
668
+ return Expression.For(obj, exp, this.SOURCE, this.pos)
669
+ }
670
+
671
+ /**
672
+ * Method call handling with parameters
673
+ */
674
+ MethodCall (name, obj) {
675
+ let t = this.GetToken()
676
+ if (t.getType() === TokenType.Oper && t.getValue() === ')') {
677
+ const ps = []
678
+ return Expression.Call(obj, name, ps, this.pos)
679
+ }
680
+
681
+ this.tokens.push(t)
682
+ const ps = this.Params()
683
+ t = this.GetToken()
684
+ if (t.getType() !== TokenType.Oper || t.getValue() !== ')') {
685
+ throw new Error(this.GetExceptionMessage('函数调用括号不匹配'))
686
+ }
687
+
688
+ return Expression.Call(obj, name, ps, this.pos)
689
+ }
690
+
691
+ /**
692
+ * Function parameter list handling
693
+ */
694
+ Params () {
695
+ const ps = []
696
+ let name = this.paramName()
697
+ let exp = this.Exp()
698
+ this.procParam(ps, exp, name)
699
+ let t = this.GetToken()
700
+ while (t.getType() === TokenType.Oper && t.getValue() === ',') {
701
+ name = this.paramName()
702
+ exp = this.Exp()
703
+ this.procParam(ps, exp, name)
704
+ t = this.GetToken()
705
+ }
706
+ this.tokens.push(t)
707
+ return ps
708
+ }
709
+
710
+ /**
711
+ * Parse parameter name
712
+ */
713
+ paramName () {
714
+ const t = this.GetToken()
715
+ if (t.getType() === TokenType.Identy) {
716
+ const t1 = this.GetToken()
717
+ if (t1.getValue() === ':') {
718
+ return t.getValue()
719
+ } else {
720
+ this.tokens.push(t)
721
+ this.tokens.push(t1)
722
+ return ''
723
+ }
724
+ } else {
725
+ this.tokens.push(t)
726
+ return ''
727
+ }
728
+ }
729
+
730
+ /**
731
+ * Process parameters, especially if it contains the "data" object
732
+ */
733
+ procParam (ps, exp, name) {
734
+ const delegate = this.createDelegate(exp)
735
+ if (delegate.containsKey('data')) {
736
+ ps.push(Expression.Constant(delegate, this.pos))
737
+ } else {
738
+ ps.push(Expression.Param(exp, name, this.pos))
739
+ }
740
+ }
741
+
742
+ /**
743
+ * Get exception message with position information
744
+ */
745
+ GetExceptionMessage (msg) {
746
+ const result = this.SOURCE.substring(0, this.pos) + ' <- ' + this.SOURCE.substring(this.pos)
747
+ return `${msg}:\n${result}`
748
+ }
749
+
750
+ GetToken () {
751
+ // If there are tokens in the queue, return the last one saved
752
+ if (this.tokens.length > 0) {
753
+ return this.tokens.shift()
754
+ }
755
+
756
+ const sPos = this.pos
757
+ let hasKeyword = this.pos < this.SOURCE_LENGTH
758
+ let value = null
759
+
760
+ if (hasKeyword) {
761
+ value = this.SOURCE.charAt(this.pos)
762
+ }
763
+
764
+ // If it's '{', save the previous state and change to non-string state
765
+ if (hasKeyword && value === '{') {
766
+ this.inStrings.push(this.inString)
767
+ this.inString = false
768
+ const str = this.SOURCE.substring(this.pos, this.pos + 1)
769
+ this.pos += 1
770
+ return new Token(TokenType.Oper, str, sPos)
771
+ }
772
+
773
+ // If in string state, process the string
774
+ if (this.inString) {
775
+ const startPos = this.pos
776
+ while (hasKeyword && value !== '{' && value !== '}' && value !== '$' && value !== '\"') {
777
+ if (value === '\\') {
778
+ const nextStrValue = this.SOURCE.charAt(this.pos + 1)
779
+ if (this.pos + 1 < this.SOURCE_LENGTH && ['{', '}', '\"', '$', '\\'].includes(nextStrValue)) {
780
+ this.pos++
781
+ } else {
782
+ break
783
+ }
784
+ }
785
+ this.pos++
786
+ if (this.pos < this.SOURCE_LENGTH) {
787
+ value = this.SOURCE.charAt(this.pos)
788
+ } else {
789
+ hasKeyword = false
790
+ }
791
+ }
792
+ if (!(hasKeyword && value === '{')) {
793
+ this.inString = this.inStrings.pop()
794
+ }
795
+ const t = new Token(TokenType.String, this.SOURCE.substring(startPos, this.pos)
796
+ .replace('\\$', '$')
797
+ .replace('\\{', '{')
798
+ .replace('\\}', '}')
799
+ .replace(/\\"/g, '"')
800
+ .replace('\\\\', '\\'), sPos)
801
+
802
+ if (hasKeyword && (value === '$' || value === '\"')) {
803
+ this.pos++
804
+ }
805
+ return t
806
+ }
807
+
808
+ // Skip whitespace and comments
809
+ while (hasKeyword && (value === ' ' || value === '\n' || value === '\t' || (this.pos < this.SOURCE_LENGTH - 2 && value === '/' && this.SOURCE.charAt(this.pos + 1) === '/'))) {
810
+ if (value !== ' ' && value !== '\n' && value !== '\t') {
811
+ this.pos += 2
812
+ if (this.pos < this.SOURCE_LENGTH) {
813
+ value = this.SOURCE.charAt(this.pos)
814
+ } else {
815
+ hasKeyword = false
816
+ }
817
+ while (hasKeyword && value !== '\n') {
818
+ this.pos++
819
+ if (this.pos < this.SOURCE_LENGTH) {
820
+ value = this.SOURCE.charAt(this.pos)
821
+ } else {
822
+ hasKeyword = false
823
+ }
824
+ }
825
+ }
826
+ this.pos++
827
+ if (this.pos < this.SOURCE_LENGTH) {
828
+ value = this.SOURCE.charAt(this.pos)
829
+ } else {
830
+ hasKeyword = false
831
+ }
832
+ }
833
+
834
+ // If we are at the end of the source, return an "End" token
835
+ if (this.pos === this.SOURCE_LENGTH) {
836
+ return new Token(TokenType.End, null, sPos)
837
+ }
838
+
839
+ if (value !== null) {
840
+ // Handle number tokens
841
+ if (value >= '0' && value <= '9') {
842
+ const oldPos = this.pos
843
+ while (hasKeyword && value >= '0' && value <= '9') {
844
+ this.pos++
845
+ if (this.pos < this.SOURCE_LENGTH) {
846
+ value = this.SOURCE.charAt(this.pos)
847
+ } else {
848
+ hasKeyword = false
849
+ }
850
+ }
851
+
852
+ if (hasKeyword && value === '.') {
853
+ do {
854
+ this.pos++
855
+ if (this.pos < this.SOURCE_LENGTH) {
856
+ value = this.SOURCE.charAt(this.pos)
857
+ } else {
858
+ hasKeyword = false
859
+ }
860
+ } while (hasKeyword && value >= '0' && value <= '9')
861
+ const str = this.SOURCE.substring(oldPos, this.pos)
862
+ return new Token(TokenType.Double, parseFloat(str), sPos)
863
+ } else {
864
+ const str = this.SOURCE.substring(oldPos, this.pos)
865
+ return new Token(TokenType.Int, parseInt(str, 10), sPos)
866
+ }
867
+ } else if ((value >= 'a' && value <= 'z') || (value >= 'A' && value <= 'Z') || value === '_' || /[\u4e00-\u9fa5]/.test(value)) {
868
+ const oldPos = this.pos
869
+ while (hasKeyword && ((value >= 'a' && value <= 'z') || (value >= 'A' && value <= 'Z') || (value >= '0' && value <= '9') || value === '_' || /[\u4e00-\u9fa5]/.test(value))) {
870
+ this.pos++
871
+ if (this.pos < this.SOURCE_LENGTH) {
872
+ value = this.SOURCE.charAt(this.pos)
873
+ } else {
874
+ hasKeyword = false
875
+ }
876
+ }
877
+ const str = this.SOURCE.substring(oldPos, this.pos)
878
+ switch (str) {
879
+ case 'false':
880
+ case 'true':
881
+ return new Token(TokenType.Bool, Boolean(str), sPos)
882
+ case 'null':
883
+ return new Token(TokenType.Null, null, sPos)
884
+ default:
885
+ return new Token(TokenType.Identy, str, sPos)
886
+ }
887
+ } else if ((value === '&' && this.SOURCE.charAt(this.pos + 1) === '&') || (value === '|' && this.SOURCE.charAt(this.pos + 1) === '|')) {
888
+ const str = this.SOURCE.substring(this.pos, this.pos + 2)
889
+ this.pos += 2
890
+ return new Token(TokenType.Oper, str, sPos)
891
+ } else if (['+', '-', '*', '/', '%', '>', '<', '!'].includes(value)) {
892
+ let str = ''
893
+ if (this.SOURCE.charAt(this.pos + 1) === '=') {
894
+ str = this.SOURCE.substring(this.pos, this.pos + 2)
895
+ this.pos += 2
896
+ } else {
897
+ str = this.SOURCE.substring(this.pos, this.pos + 1)
898
+ this.pos += 1
899
+ }
900
+ return new Token(TokenType.Oper, str, sPos)
901
+ } else if (value === '=') {
902
+ let str
903
+ if (this.SOURCE.charAt(this.pos + 1) === '=' || this.SOURCE.charAt(this.pos + 1) === '>') {
904
+ str = this.SOURCE.substring(this.pos, this.pos + 2)
905
+ this.pos += 2
906
+ } else {
907
+ str = this.SOURCE.substring(this.pos, this.pos + 1)
908
+ this.pos += 1
909
+ }
910
+ return new Token(TokenType.Oper, str, sPos)
911
+ } else if ('()[],;.:@{}"$'.includes(value)) {
912
+ if (value === '$' || value === '\"') {
913
+ this.inStrings.push(false)
914
+ this.inString = true
915
+ } else if ((value === '{' || value === '}') && this.inStrings.length) {
916
+ if (value === '{') {
917
+ this.inStrings.push(false)
918
+ this.inString = false
919
+ } else {
920
+ this.inString = this.inStrings.pop()
921
+ }
922
+ }
923
+ const str = this.SOURCE.substring(this.pos, this.pos + 1)
924
+ this.pos += 1
925
+ return new Token(TokenType.Oper, str, sPos)
926
+ } else {
927
+ throw new Error(`Invalid token: '${value}'`)
928
+ }
929
+ }
930
+
931
+ throw new Error('Unknown error while parsing.')
932
+ }
933
+ }