@sap/cds-compiler 6.6.0 → 6.7.1
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.
- package/CHANGELOG.md +34 -1
- package/bin/cdsc.js +2 -0
- package/bin/cdsse.js +1 -1
- package/lib/base/message-registry.js +6 -7
- package/lib/base/model.js +0 -72
- package/lib/checks/elements.js +1 -1
- package/lib/checks/featureFlags.js +2 -2
- package/lib/compiler/assert-consistency.js +3 -4
- package/lib/compiler/base.js +8 -0
- package/lib/compiler/builtins.js +8 -9
- package/lib/compiler/checks.js +27 -6
- package/lib/compiler/cycle-detector.js +4 -4
- package/lib/compiler/define.js +65 -83
- package/lib/compiler/extend.js +357 -325
- package/lib/compiler/finalize-parse-cdl.js +3 -4
- package/lib/compiler/generate.js +205 -203
- package/lib/compiler/kick-start.js +34 -49
- package/lib/compiler/populate.js +95 -28
- package/lib/compiler/propagator.js +3 -5
- package/lib/compiler/resolve.js +17 -13
- package/lib/compiler/shared.js +47 -19
- package/lib/compiler/tweak-assocs.js +2 -4
- package/lib/compiler/utils.js +84 -31
- package/lib/gen/BaseParser.js +924 -1055
- package/lib/gen/CdlGrammar.checksum +1 -1
- package/lib/gen/CdlParser.js +5 -2
- package/lib/json/from-csn.js +25 -16
- package/lib/main.d.ts +13 -0
- package/lib/model/revealInternalProperties.js +18 -0
- package/lib/parsers/AstBuildingParser.js +22 -5
- package/lib/render/toHdbcds.js +2 -2
- package/lib/render/utils/sql.js +2 -2
- package/lib/render/utils/standardDatabaseFunctions.js +2 -2
- package/lib/transform/db/constraints.js +3 -4
- package/lib/transform/db/killAnnotations.js +1 -1
- package/lib/transform/db/processSqlServices.js +10 -11
- package/lib/transform/effective/associations.js +1 -1
- package/lib/transform/forOdata.js +7 -124
- package/lib/transform/odata/fioriTreeViews.js +173 -0
- package/lib/transform/odata/flattening.js +2 -2
- package/lib/transform/translateAssocsToJoins.js +7 -4
- package/package.json +1 -1
- package/share/messages/message-explanations.json +0 -2
- package/share/messages/type-unexpected-foreign-keys.md +0 -52
- package/share/messages/type-unexpected-on-condition.md +0 -52
package/lib/gen/BaseParser.js
CHANGED
|
@@ -1,1072 +1,941 @@
|
|
|
1
|
-
//
|
|
1
|
+
//Base class for generated parser, for redepage v0.3.2
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
// TODO: instance method
|
|
6
|
-
// name → true, list of predicates which are tested for rule exit
|
|
7
|
-
// const ruleExitPredicates = {};
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
13
|
|
|
14
14
|
class BaseParser {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
_tracePush( state ) {
|
|
909
|
-
if (this.constructor.tracingParser)
|
|
910
|
-
this.trace.push( state ?? '⚠' );
|
|
911
|
-
}
|
|
912
|
-
_traceSubPush( state ) {
|
|
913
|
-
if (this.constructor.tracingParser)
|
|
914
|
-
this.trace.at(-1).push( state );
|
|
915
|
-
}
|
|
916
|
-
traceAction( location ) { // TODO: remove
|
|
917
|
-
this._trace( 1, location );
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
_trace( msg, la = this.la() ?? this.lb() ) {
|
|
921
|
-
if (!this.constructor.tracingParser)
|
|
922
|
-
return;
|
|
923
|
-
// indentation according to rule call depth is nice, but only if without
|
|
924
|
-
// excessive spaces → truncate:
|
|
925
|
-
const indent = ' '.repeat( this.stack.length % 32 );
|
|
926
|
-
if (msg === 1) {
|
|
927
|
-
let line = ' execute action'; // align with non-action messages
|
|
928
|
-
if (this.trace.length > 1) { // i.e. with some 'g' command
|
|
929
|
-
line += ', states: ' + this.trace.map( traceStep ).join( ' → ' );
|
|
930
|
-
this.trace = [ this.s ?? '⚠' ];
|
|
931
|
-
}
|
|
932
|
-
this.log( indent, line, `(${ la })` );
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
|
-
else if (la === 2) { // confirming tokens in expected set
|
|
936
|
-
this.log( indent, ' ', msg + ':',
|
|
937
|
-
this.trace.map( traceStep ).join( ' → ' ) );
|
|
938
|
-
this.trace = [ this.s ?? '⚠' ];
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
const { location } = la;
|
|
942
|
-
if (!this.trace.length) {
|
|
943
|
-
this.log( `In ${ location.file }:` );
|
|
944
|
-
this.trace = [ -1 ];
|
|
945
|
-
}
|
|
946
|
-
this.trace.push( this.s ?? '⚠' );
|
|
947
|
-
if (Array.isArray( msg )) { // rule call and exit
|
|
948
|
-
const [ intro, state, finale, exit ] = msg;
|
|
949
|
-
let start = state;
|
|
950
|
-
while (typeof this.table[--start] !== 'string')
|
|
951
|
-
;
|
|
952
|
-
const post = (exit || start + 1 < state) && finale;
|
|
953
|
-
msg = `${ intro } “${ this.table[start] }”${ post || '' } ${ exit || 'from' } stack level ${ this.stack.length }`;
|
|
954
|
-
}
|
|
955
|
-
// Yes, I know util.format, but do not want to have a `require` in this file
|
|
956
|
-
const line = location.line < 1e5 ? ` ${ location.line }`.slice(-5) : `${ location.line }`;
|
|
957
|
-
const col = location.col < 1e4 ? `:${ location.col } `.slice(0,5) : `:${location.col }`;
|
|
958
|
-
this.log( line + col + indent + msg + ', states:',
|
|
959
|
-
this.trace.map( traceStep ).join( ' → ' ) );
|
|
960
|
-
this.trace = [ this.s ?? '⚠' ];
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
inSameRule_( lowState = this.s, highState = this.stack.at(-1).followState ) {
|
|
964
|
-
if (lowState > highState)
|
|
965
|
-
[ lowState, highState ] = [ highState, lowState ];
|
|
966
|
-
while (lowState < highState) {
|
|
967
|
-
if (typeof this.table[++lowState] === 'string') // rule boundary
|
|
968
|
-
return false;
|
|
969
|
-
}
|
|
970
|
-
return true;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
// Predefined conditions with extra option names:
|
|
974
|
-
|
|
975
|
-
hide_( _arg, mode ) {
|
|
976
|
-
return mode === 'M';
|
|
977
|
-
}
|
|
978
|
-
precLeft_( prec ) { // <prec=…>, <…,assoc=left>, <…,prefix=once>
|
|
979
|
-
const parentPrec = this.stack.at( -1 ).prec;
|
|
980
|
-
if (parentPrec != null && parentPrec >= prec)
|
|
981
|
-
return true;
|
|
982
|
-
this.prec_ = prec;
|
|
983
|
-
return false;
|
|
984
|
-
}
|
|
985
|
-
precRight_( prec ) { // <…,assoc=right>, <…,prefix>
|
|
986
|
-
const parentPrec = this.stack.at( -1 ).prec;
|
|
987
|
-
if (parentPrec != null && parentPrec >= prec)
|
|
988
|
-
return true;
|
|
989
|
-
this.prec_ = prec - 1;
|
|
990
|
-
return false;
|
|
991
|
-
}
|
|
992
|
-
precNone_( prec ) { // <…,assoc=none>, <…,postfix=once>
|
|
993
|
-
const parentPrec = this.stack.at( -1 ).prec;
|
|
994
|
-
if (parentPrec != null && parentPrec >= prec ||
|
|
995
|
-
this.prec_ != null && this.prec_ <= prec)
|
|
996
|
-
return true;
|
|
997
|
-
this.prec_ = prec;
|
|
998
|
-
return false;
|
|
999
|
-
}
|
|
1000
|
-
precPost_( prec ) { // <…,postfix>
|
|
1001
|
-
const parentPrec = this.stack.at( -1 ).prec;
|
|
1002
|
-
if (parentPrec != null && parentPrec >= prec ||
|
|
1003
|
-
this.prec_ != null && this.prec_ < prec)
|
|
1004
|
-
return true;
|
|
1005
|
-
this.prec_ = prec;
|
|
1006
|
-
return false;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
const members = BaseParser.prototype;
|
|
1010
|
-
// functions below are to be called with `call` to set `this`
|
|
1011
|
-
|
|
1012
|
-
members.isNoKeywordInRuleFollow.afterError = true;
|
|
1013
|
-
|
|
1014
|
-
members.precLeft_.traceName = function( prec ) {
|
|
1015
|
-
const parentPrec = this.stack.at( -1 ).prec;
|
|
1016
|
-
return `${ parentPrec ?? '-∞' }<${ prec }`;
|
|
1017
|
-
}
|
|
1018
|
-
members.precRight_.traceName = function( prec ) {
|
|
1019
|
-
const left = this.precLeft_.traceName.call( this, prec );
|
|
1020
|
-
return `${ left },↓`;
|
|
1021
|
-
}
|
|
1022
|
-
members.precNone_.traceName = function( prec ) {
|
|
1023
|
-
const left = this.precLeft_.traceName.call( this, prec );
|
|
1024
|
-
return `${ left }<${ this.prec_ == null ? '∞' : this.prec_ }`;
|
|
1025
|
-
}
|
|
1026
|
-
members.precPost_.traceName = function( prec ) {
|
|
1027
|
-
const left = this.precLeft_.traceName.call( this, prec );
|
|
1028
|
-
return `${ left }≤${ this.prec_ == null ? '∞' : this.prec_ }`;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
function traceStep( step ) {
|
|
1032
|
-
if (!Array.isArray( step ))
|
|
1033
|
-
return step;
|
|
1034
|
-
const result = { true: '✔', false: '✖' }[step.at( -1 )] ?? '';
|
|
1035
|
-
const intro = (typeof step[1] === 'number') ? '→' : '';
|
|
1036
|
-
const arg = step.slice( 1, result ? -1 : undefined ).join( '→' );
|
|
1037
|
-
return `${ step[0] }(${ intro }${ arg })${ result }`;
|
|
15
|
+
keywords;
|
|
16
|
+
table;
|
|
17
|
+
lexer;
|
|
18
|
+
|
|
19
|
+
tokens = undefined;
|
|
20
|
+
tokenIdx = 0;
|
|
21
|
+
conditionTokenIdx = -1;
|
|
22
|
+
errorTokenIdx = -1;
|
|
23
|
+
recoverTokenIdx = -1;
|
|
24
|
+
reuseErrorTokenIdx = null;
|
|
25
|
+
fixKeywordTokenIdx = -1;
|
|
26
|
+
conditionStackLength = -1;
|
|
27
|
+
nextTokenAsId = false;
|
|
28
|
+
|
|
29
|
+
s = null;
|
|
30
|
+
errorState = null;
|
|
31
|
+
stack = [];
|
|
32
|
+
dynamic_ = {};
|
|
33
|
+
prec_ = null;
|
|
34
|
+
$hasErrors = null;
|
|
35
|
+
leanConditions = {};
|
|
36
|
+
_trace = [];
|
|
37
|
+
|
|
38
|
+
constructor( lexer, keywords, table ) {
|
|
39
|
+
this.keywords = { __proto__: null, ...keywords };
|
|
40
|
+
this.table = compileTable( table );
|
|
41
|
+
this.lexer = lexer;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
init() {
|
|
45
|
+
this.lexer.tokenize( this );
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_runTransparently( callback ) {
|
|
50
|
+
const { tokenIdx } = this;
|
|
51
|
+
const saved = this._saveForWalk();
|
|
52
|
+
const { length } = this.stack;
|
|
53
|
+
const r = callback();
|
|
54
|
+
this.stack.length = length;
|
|
55
|
+
Object.assign( this, saved );
|
|
56
|
+
this.tokenIdx = tokenIdx;
|
|
57
|
+
return r;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_saveForWalk() {
|
|
61
|
+
return {
|
|
62
|
+
s: this.s,
|
|
63
|
+
stack: this.stack,
|
|
64
|
+
dynamic_: this.dynamic_,
|
|
65
|
+
prec_: this.prec_,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_cloneFromSaved( saved ) {
|
|
70
|
+
this.s = saved.s;
|
|
71
|
+
this.stack = saved.stack.map( obj => ({ ...obj }) );
|
|
72
|
+
this.dynamic_ = this._cloneDynamic( saved.dynamic_ );
|
|
73
|
+
this.prec_ = saved.prec_;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_cloneDynamic( dynamic_ ) {
|
|
77
|
+
let chain = [];
|
|
78
|
+
while (dynamic_ !== Object.prototype) {
|
|
79
|
+
const obj = {};
|
|
80
|
+
for (const [ prop, val ] of Object.entries( dynamic_ ))
|
|
81
|
+
obj[prop] = Array.isArray( val ) ? [ ...val ] : val;
|
|
82
|
+
chain.push( obj );
|
|
83
|
+
dynamic_ = Object.getPrototypeOf( dynamic_ );
|
|
84
|
+
}
|
|
85
|
+
let copy = Object.prototype;
|
|
86
|
+
let { length } = chain;
|
|
87
|
+
while (--length >= 0)
|
|
88
|
+
copy = { __proto__: copy, ...chain[length] };
|
|
89
|
+
return copy;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
la() {
|
|
95
|
+
return this.tokens[this.tokenIdx];
|
|
96
|
+
}
|
|
97
|
+
lb( k = 1 ) {
|
|
98
|
+
return this.tokens[this.tokenIdx - k];
|
|
99
|
+
}
|
|
100
|
+
lr() {
|
|
101
|
+
return this.tokens[this.stack[this.stack.length - 1].tokenIdx];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
l() {
|
|
107
|
+
return this.la().type;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
lk() {
|
|
112
|
+
const la = this.la();
|
|
113
|
+
if (!this.nextTokenAsId)
|
|
114
|
+
return la.keyword || la.type;
|
|
115
|
+
|
|
116
|
+
this.nextTokenAsId = false;
|
|
117
|
+
return la.type;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
e() {
|
|
121
|
+
const la = this.la();
|
|
122
|
+
|
|
123
|
+
if (this.errorTokenIdx === this.tokenIdx &&
|
|
124
|
+
(this.reuseErrorTokenIdx == null && this.reuseErrorTokenIdx < this.tokenIdx))
|
|
125
|
+
throw Error( `Already reported error for ${ tokenFullName( la ) } at ${ la.location }`);
|
|
126
|
+
|
|
127
|
+
la.parsedAs = '';
|
|
128
|
+
this.errorTokenIdx = this.tokenIdx;
|
|
129
|
+
this.conditionStackLength = null;
|
|
130
|
+
|
|
131
|
+
let { length } = this.stack;
|
|
132
|
+
while (--length && this.tokenIdx === this.stack[length].tokenIdx)
|
|
133
|
+
this.stack[length].followState = null;
|
|
134
|
+
if (++length === this.stack.length)
|
|
135
|
+
return this._reportAndRecover();
|
|
136
|
+
|
|
137
|
+
this.stack[length].followState = this.errorState;
|
|
138
|
+
this.s = null;
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
ei() {
|
|
144
|
+
if (!this.la().keyword)
|
|
145
|
+
return this.e();
|
|
146
|
+
this.nextTokenAsId = true;
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
gr( follow ) {
|
|
154
|
+
if (this.stack[this.stack.length - 1].tokenIdx === this.tokenIdx)
|
|
155
|
+
|
|
156
|
+
return this.e();
|
|
157
|
+
this.s = 0;
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
const { type, keyword } = this.tokens[this.tokenIdx];
|
|
161
|
+
if (keyword &&
|
|
162
|
+
follow?.[0] === 'Id' && !this.keywords[keyword] &&
|
|
163
|
+
this.fixKeywordTokenIdx !== this.tokenIdx ||
|
|
164
|
+
follow?.includes( keyword || type ))
|
|
165
|
+
return true
|
|
166
|
+
|
|
167
|
+
const match = this._matchesInFollow( type, keyword, 'E' );
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
return (match ?? true) || this.e();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
g( state, follow ) {
|
|
176
|
+
if (!(state == null ? this.e() : state || this.gr( follow )))
|
|
177
|
+
return false;
|
|
178
|
+
this.s = state;
|
|
179
|
+
return true
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
giA( state, follow ) {
|
|
184
|
+
if (!this.tokens[this.tokenIdx].keyword)
|
|
185
|
+
return this.g( state, follow );
|
|
186
|
+
this.nextTokenAsId = true;
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
gi( state, follow ) {
|
|
192
|
+
const lk = this.tokens[this.tokenIdx].keyword;
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
if (!lk || this.keywords[lk])
|
|
196
|
+
return this.g( state, follow );
|
|
197
|
+
this.nextTokenAsId = true;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
gP( state, follow ) {
|
|
203
|
+
return this.lP( follow ) && this.g( state );
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
m( state, token ) {
|
|
209
|
+
return (this.tokens[this.tokenIdx].type === token)
|
|
210
|
+
? this.c( state )
|
|
211
|
+
: this.e();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
mi( state, ident = true ) {
|
|
216
|
+
return (this.tokens[this.tokenIdx].type === 'Id')
|
|
217
|
+
? this.ci( state, ident )
|
|
218
|
+
: this.e();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
miA( state, ident = true ) {
|
|
223
|
+
return (this.tokens[this.tokenIdx].type === 'Id')
|
|
224
|
+
? this.ciA( state, ident )
|
|
225
|
+
: this.e();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
mk( state, token ) {
|
|
230
|
+
return (this.tokens[this.tokenIdx].keyword === token)
|
|
231
|
+
? this.ck( state )
|
|
232
|
+
: this.e();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
c( state, parsedAs = 'token' ) {
|
|
236
|
+
const la = this.tokens[this.tokenIdx++];
|
|
237
|
+
la.parsedAs = parsedAs;
|
|
238
|
+
this.s = state;
|
|
239
|
+
this.errorState = state;
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
ci( state, ident = 'ident' ) {
|
|
245
|
+
if (this.tokenIdx === this.fixKeywordTokenIdx)
|
|
246
|
+
return this.e();
|
|
247
|
+
const la = this.tokens[this.tokenIdx];
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
if (this.keywords[la.keyword]) {
|
|
251
|
+
|
|
252
|
+
if (this._runTransparently( () => {
|
|
253
|
+
++this.tokenIdx;
|
|
254
|
+
this.s = state;
|
|
255
|
+
const { type, keyword } = this.la();
|
|
256
|
+
return !(this._pred_next( type, keyword, 'R' ) ??
|
|
257
|
+
this._matchesInFollow( type, keyword, 'R' ));
|
|
258
|
+
} ))
|
|
259
|
+
return this.e();
|
|
260
|
+
this.reportReservedWord_();
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
return this.c( state, ident )
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
ciA( state, ident = 'ident' ) {
|
|
268
|
+
return this.c( state, ident )
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
ck( state ) {
|
|
273
|
+
return this.c( state, 'keyword' )
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
ckP( state, first2 ) {
|
|
278
|
+
return this.lP( first2 ) && this.ck( state );
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
ckA( state ) {
|
|
283
|
+
|
|
284
|
+
return this.c( state, (this.l() === 'Id' ? 'keyword' : 'token') );
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
skipToken_() {
|
|
288
|
+
++this.tokenIdx;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
reuseToken_() {
|
|
292
|
+
--this.tokenIdx;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
gc( state, cond, arg ) {
|
|
303
|
+
if (this.conditionTokenIdx === this.tokenIdx &&
|
|
304
|
+
this.conditionStackLength == null &&
|
|
305
|
+
!this[cond].afterError)
|
|
306
|
+
return true
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
const fail = this[cond]( arg, true );
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
if (fail) {
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
const { keyword } = this.la();
|
|
326
|
+
if (keyword && this.table[this.s][keyword])
|
|
327
|
+
this.fixKeywordTokenIdx = this.tokenIdx;
|
|
328
|
+
this.conditionTokenIdx = this.tokenIdx;
|
|
329
|
+
this.conditionStackLength = this.stack.length;
|
|
330
|
+
this.conditionName = cond;
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
this.conditionFailure = fail;
|
|
334
|
+
}
|
|
335
|
+
return !fail || this.g( state ) && false;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
ec( cond, arg ) {
|
|
339
|
+
return this.gc( null, cond, arg );
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
isNoKeywordInRuleFollow() {
|
|
344
|
+
const { keyword } = this.la();
|
|
345
|
+
if (!keyword || this.keywords[keyword] == null)
|
|
346
|
+
return false;
|
|
347
|
+
return this._matchesInFollow( 'Id', keyword, 'F' );
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
rule_( state, followState = -1 ) {
|
|
354
|
+
this.s = state;
|
|
355
|
+
|
|
356
|
+
this.stack.push( {
|
|
357
|
+
ruleState: state,
|
|
358
|
+
followState,
|
|
359
|
+
tokenIdx: this.tokenIdx,
|
|
360
|
+
prec: this.prec_,
|
|
361
|
+
} );
|
|
362
|
+
this.dynamic_ = Object.create( this.dynamic_ );
|
|
363
|
+
this.prec_ = null;
|
|
364
|
+
this.errorState ??= state;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
exit_() {
|
|
368
|
+
if (this.s)
|
|
369
|
+
throw Error( `this.s === ${ this.s }; illegally set by action, or runtime/generator bug` );
|
|
370
|
+
this.dynamic_ = Object.getPrototypeOf( this.dynamic_ );
|
|
371
|
+
const caller = this.stack.pop();
|
|
372
|
+
const immediately = this.tokenIdx === caller.tokenIdx && this.tokenIdx >= this.errorTokenIdx;
|
|
373
|
+
if (this.constructor.tracingParser) {
|
|
374
|
+
const post = this.s == null &&
|
|
375
|
+
(immediately
|
|
376
|
+
? ' immediately'
|
|
377
|
+
: caller.followState == null
|
|
378
|
+
? ' unsuccessfully'
|
|
379
|
+
: ' prematurely');
|
|
380
|
+
const text = immediately ? '⚠ exit rule' : '⏎ exit rule';
|
|
381
|
+
this.s = caller.followState;
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
this.prec_ = caller.prec;
|
|
386
|
+
this.s = caller.followState;
|
|
387
|
+
if (immediately)
|
|
388
|
+
return this.s != null && this._reportAndRecover();
|
|
389
|
+
|
|
390
|
+
if (this.s != null)
|
|
391
|
+
this.errorState = this.s;
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
lP( first2 ) {
|
|
400
|
+
|
|
401
|
+
const { keyword: lk1 } = this.tokens[this.tokenIdx];
|
|
402
|
+
if (!lk1 || this.keywords[lk1] !== 0 || this.fixKeywordTokenIdx === this.tokenIdx)
|
|
403
|
+
return true;
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
const { type: lt2, keyword: lk2 } = this.tokens[this.tokenIdx + 1];
|
|
407
|
+
if (lt2 === 'IllegalToken')
|
|
408
|
+
return true
|
|
409
|
+
|
|
410
|
+
if (lk2 && first2?.[0] === 'Id' && !this.keywords[lk2] ||
|
|
411
|
+
first2?.includes( lk2 || lt2 ))
|
|
412
|
+
return true
|
|
413
|
+
|
|
414
|
+
if (this._walkPred( this.table[this.s][lk1], lk1, lt2, lk2 ))
|
|
415
|
+
return true;
|
|
416
|
+
|
|
417
|
+
const choice = this.table[this.s];
|
|
418
|
+
if (!this._walkPred( choice.Id || choice[''], null, lt2, lk2 ))
|
|
419
|
+
return true;
|
|
420
|
+
this.nextTokenAsId = true;
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
_walkPred( cmd, lk1, lt2, lk2 ) {
|
|
425
|
+
const saved = this._saveForWalk();
|
|
426
|
+
const { length } = this.stack;
|
|
427
|
+
if (typeof cmd[0] !== 'number')
|
|
428
|
+
this.s = cmd[1];
|
|
429
|
+
if (cmd[0] !== (lk1 ? 'ck' : 'ci')) {
|
|
430
|
+
|
|
431
|
+
let match1 = this._pred_next( 'Id', lk1, 'P' );
|
|
432
|
+
if (!match1) {
|
|
433
|
+
if (lk1) {
|
|
434
|
+
|
|
435
|
+
const { location } = this.la();
|
|
436
|
+
throw Error( `Cannot match first prediction token at ${ location.line }:${ location.col } in rule at state ${ saved.s }` );
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (match1 == null)
|
|
440
|
+
match1 = this._matchesInFollow( 'Id', lk1, 'I' );
|
|
441
|
+
Object.assign( this, saved );
|
|
442
|
+
this.stack.length = length;
|
|
443
|
+
return !!match1;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
++this.tokenIdx;
|
|
448
|
+
const mode = lk1 ? 'K' : 'I';
|
|
449
|
+
let match2 = this._pred_next( lt2, lk2, mode );
|
|
450
|
+
|
|
451
|
+
if (match2 == null)
|
|
452
|
+
match2 = !!this._matchesInFollow( lt2, lk2, mode );
|
|
453
|
+
|
|
454
|
+
Object.assign( this, saved );
|
|
455
|
+
this.stack.length = length;
|
|
456
|
+
--this.tokenIdx;
|
|
457
|
+
return match2;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
_pred_next( type, keyword, mode ) {
|
|
479
|
+
const properCall = (mode === 'P');
|
|
480
|
+
const lean = (mode !== 'M');
|
|
481
|
+
|
|
482
|
+
let hasMatchedToken = null;
|
|
483
|
+
while (this.s) {
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
let cmd = this.table[this.s];
|
|
487
|
+
if (!Array.isArray( cmd )) {
|
|
488
|
+
const lookahead = cmd[' lookahead'];
|
|
489
|
+
const c = lookahead
|
|
490
|
+
? cmd[this[lookahead]( mode )]
|
|
491
|
+
: keyword && cmd[keyword] || cmd[type];
|
|
492
|
+
cmd = !(c && this._rejectCondition( c, mode, lean )) && c || cmd[''];
|
|
493
|
+
}
|
|
494
|
+
const state = this.s;
|
|
495
|
+
this.s = cmd[1];
|
|
496
|
+
switch (cmd[0]) {
|
|
497
|
+
case 'c': case 'ck': case 'ckA':
|
|
498
|
+
return true;
|
|
499
|
+
case 'ciA':
|
|
500
|
+
return mode !== 'F';
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
case 'ci':
|
|
505
|
+
if (!keyword ||
|
|
506
|
+
!this.keywords[keyword] && this.fixKeywordTokenIdx !== this.tokenIdx)
|
|
507
|
+
return mode !== 'F';
|
|
508
|
+
cmd = this.table[state][''];
|
|
509
|
+
this.s = cmd[1];
|
|
510
|
+
break;
|
|
511
|
+
case 'm':
|
|
512
|
+
return type === cmd[2];
|
|
513
|
+
case 'mi':
|
|
514
|
+
return type === 'Id' && mode !== 'F' &&
|
|
515
|
+
(!keyword ||
|
|
516
|
+
!this.keywords[keyword] && this.fixKeywordTokenIdx !== this.tokenIdx);
|
|
517
|
+
case 'miA':
|
|
518
|
+
return type === 'Id' && mode !== 'F';
|
|
519
|
+
case 'mk':
|
|
520
|
+
return keyword === cmd[2];
|
|
521
|
+
case 'g': case 'e':
|
|
522
|
+
break;
|
|
523
|
+
default:
|
|
524
|
+
if (typeof cmd[0] !== 'number')
|
|
525
|
+
throw Error( `Unexpected command ${ cmd[0] } at state ${ state }` );
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
hasMatchedToken = false;
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
if (properCall) {
|
|
532
|
+
|
|
533
|
+
this.stack.push( {
|
|
534
|
+
ruleState: cmd[1],
|
|
535
|
+
followState: cmd[0],
|
|
536
|
+
tokenIdx: this.tokenIdx,
|
|
537
|
+
prec: this.prec_,
|
|
538
|
+
} );
|
|
539
|
+
this.dynamic_ = Object.create( this.dynamic_ );
|
|
540
|
+
this.prec_ = null;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
if (this.s == null)
|
|
553
|
+
return false;
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
return (hasMatchedToken ?? this.tokenIdx > this.stack.at( -1 ).tokenIdx)
|
|
562
|
+
&& null;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
_rejectCondition( cmd, mode, lean ) {
|
|
566
|
+
const cond = cmd[3];
|
|
567
|
+
if (!cond || lean && !this.leanConditions[cond])
|
|
568
|
+
return false;
|
|
569
|
+
if (!this.constructor.tracingParser)
|
|
570
|
+
return !!this[cond]( cmd[4], mode );
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
const succeed = !this[cond]( cmd[4], mode );
|
|
576
|
+
|
|
577
|
+
return !succeed;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
_matchesInFollow( type, keyword, mode ) {
|
|
581
|
+
|
|
582
|
+
const savedState = this.s;
|
|
583
|
+
|
|
584
|
+
const { dynamic_ } = this;
|
|
585
|
+
let match;
|
|
586
|
+
let depth = this.stack.length;
|
|
587
|
+
|
|
588
|
+
while (match == null && --depth) {
|
|
589
|
+
this.dynamic_ = Object.getPrototypeOf( this.dynamic_ );
|
|
590
|
+
this.s = this.stack[depth].followState;
|
|
591
|
+
|
|
592
|
+
match = this._pred_next( type, keyword, mode );
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
}
|
|
598
|
+
this.dynamic_ = dynamic_;
|
|
599
|
+
this.s = savedState;
|
|
600
|
+
return match;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
_confirmExpected( token, saved ) {
|
|
604
|
+
const fix = /^[_a-z]/.test( token );
|
|
605
|
+
const [ type, keyword ] = (fix) ? [ 'Id', token ] : [ token ];
|
|
606
|
+
Object.assign( this.la(), { type, keyword } );
|
|
607
|
+
this._cloneFromSaved( saved );
|
|
608
|
+
this.fixKeywordTokenIdx = fix && this.tokenIdx;
|
|
609
|
+
|
|
610
|
+
let match;
|
|
611
|
+
while (this.stack.length) {
|
|
612
|
+
match = this._pred_next( type, keyword, 'M' );
|
|
613
|
+
|
|
614
|
+
if (match != null)
|
|
615
|
+
break;
|
|
616
|
+
this.dynamic_ = Object.getPrototypeOf( this.dynamic_ );
|
|
617
|
+
this.s = this.stack.pop().followState;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return match ?? true;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
_calculateTokenSet( mode ) {
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
const savedState = this.s;
|
|
631
|
+
const savedDynamic = this.dynamic_;
|
|
632
|
+
const savedStack = this.stack;
|
|
633
|
+
this.stack = [ ...savedStack ];
|
|
634
|
+
this.s = this.errorState;
|
|
635
|
+
|
|
636
|
+
const set = Object.create(null);
|
|
637
|
+
|
|
638
|
+
if (mode === 'M') {
|
|
639
|
+
while (this.stack.length && this._tokenSetInRule( set, true )) {
|
|
640
|
+
this.dynamic_ = Object.getPrototypeOf( this.dynamic_ );
|
|
641
|
+
this.s = this.stack.pop().followState;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
let val = this.stack.length + 1;
|
|
646
|
+
while (this.stack.length) {
|
|
647
|
+
this._tokenSetInRule( set, val );
|
|
648
|
+
val = this.stack.length;
|
|
649
|
+
|
|
650
|
+
this.dynamic_ = Object.getPrototypeOf( this.dynamic_ );
|
|
651
|
+
this.s = this.stack.pop().followState;
|
|
652
|
+
}
|
|
653
|
+
set.EOF ??= 0;
|
|
654
|
+
}
|
|
655
|
+
this.stack = savedStack;
|
|
656
|
+
this.s = savedState;
|
|
657
|
+
this.dynamic_ = savedDynamic;
|
|
658
|
+
return set;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
_tokenSetInRule( expecting, val, cmd, collectKeywordsAndIdOnly = false ) {
|
|
666
|
+
const savedDynamic = this.dynamic_;
|
|
667
|
+
const savedState = this.s;
|
|
668
|
+
let enteredRules = 0;
|
|
669
|
+
loop: while (this.s) {
|
|
670
|
+
cmd ??= this.table[this.s];
|
|
671
|
+
if (!Array.isArray( cmd )) {
|
|
672
|
+
const lookahead = cmd[' lookahead'];
|
|
673
|
+
const dict = cmd;
|
|
674
|
+
for (const prop in dict) {
|
|
675
|
+
if (prop && Object.hasOwn( dict, prop ) && prop !== 'Id' &&
|
|
676
|
+
!Object.hasOwn( expecting, prop ) && prop.charAt(0) !== ' ')
|
|
677
|
+
this.addTokenToSet_( expecting, prop, val, collectKeywordsAndIdOnly, lookahead );
|
|
678
|
+
}
|
|
679
|
+
cmd = dict[''];
|
|
680
|
+
if (dict.Id) {
|
|
681
|
+
|
|
682
|
+
if (cmd[0] === 'e') {
|
|
683
|
+
collectKeywordsAndIdOnly = true;
|
|
684
|
+
cmd = dict.Id;
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
|
|
688
|
+
this._tokenSetInRule( expecting, val, dict.Id, true );
|
|
689
|
+
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
switch (cmd[0]) {
|
|
695
|
+
case 'm': case 'mk':
|
|
696
|
+
this.addTokenToSet_( expecting, cmd[2], val, collectKeywordsAndIdOnly );
|
|
697
|
+
break loop;
|
|
698
|
+
case 'ci': case 'ciA': case 'mi': case 'miA':
|
|
699
|
+
this.addTokenToSet_( expecting, 'Id', val, false );
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
break loop;
|
|
704
|
+
case 'g': case 'gi': case 'e':
|
|
705
|
+
break;
|
|
706
|
+
default:
|
|
707
|
+
if (typeof cmd[0] !== 'number')
|
|
708
|
+
throw Error( `Unexpected command ${ cmd[0] } at state ${ this.s }` );
|
|
709
|
+
++enteredRules;
|
|
710
|
+
|
|
711
|
+
this.stack.push( {
|
|
712
|
+
ruleState: cmd[1],
|
|
713
|
+
followState: cmd[0],
|
|
714
|
+
tokenIdx: this.tokenIdx,
|
|
715
|
+
prec: this.prec_,
|
|
716
|
+
} );
|
|
717
|
+
this.dynamic_ = Object.create( this.dynamic_ );
|
|
718
|
+
this.prec_ = null;
|
|
719
|
+
}
|
|
720
|
+
this.s = cmd[1];
|
|
721
|
+
cmd = null;
|
|
722
|
+
}
|
|
723
|
+
const inspectOuterRules = (this.s === 0 && !enteredRules);
|
|
724
|
+
this.s = savedState;
|
|
725
|
+
this.dynamic_ = savedDynamic;
|
|
726
|
+
this.stack.length -= enteredRules;
|
|
727
|
+
return inspectOuterRules;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
addTokenToSet_( set, token, val, collectKeywordsOnly, _lookahead ) {
|
|
732
|
+
if (!collectKeywordsOnly || /^[_a-z]/.test( token ))
|
|
733
|
+
set[token] ??= val;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
expectingArray_() {
|
|
739
|
+
const token = this.la();
|
|
740
|
+
const set = this._calculateTokenSet( 'M' );
|
|
741
|
+
|
|
742
|
+
const { keyword, type } = token;
|
|
743
|
+
if (keyword && set[keyword] === true)
|
|
744
|
+
delete set[keyword];
|
|
745
|
+
else if (set[type] === true && !(keyword && this.keywords[keyword] != null))
|
|
746
|
+
delete set[type];
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
const saved = this._saveForWalk();
|
|
750
|
+
saved._trace = this._trace;
|
|
751
|
+
saved.fixKeywordTokenIdx = this.fixKeywordTokenIdx;
|
|
752
|
+
const expecting = Object.keys( set )
|
|
753
|
+
.filter( tok => this._confirmExpected( tok, saved ) );
|
|
754
|
+
token.type = type;
|
|
755
|
+
token.keyword = keyword;
|
|
756
|
+
Object.assign( this, saved );
|
|
757
|
+
return expecting;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
_findSyncToken( syncSet ) {
|
|
761
|
+
const rewindDepth = this.stack.length
|
|
762
|
+
this.recoverTokenIdx = this.tokenIdx;
|
|
763
|
+
while (this.recoverTokenIdx < this.tokens.length) {
|
|
764
|
+
const { keyword, type } = this.tokens[this.recoverTokenIdx];
|
|
765
|
+
let recoverDepth = keyword ? syncSet[keyword] : null;
|
|
766
|
+
if (recoverDepth != null)
|
|
767
|
+
return recoverDepth;
|
|
768
|
+
recoverDepth = syncSet[type];
|
|
769
|
+
|
|
770
|
+
if (recoverDepth != null &&
|
|
771
|
+
(type !== 'Id' || (!keyword || !this.keywords[keyword]) &&
|
|
772
|
+
|
|
773
|
+
(recoverDepth > rewindDepth ||
|
|
774
|
+
[ ';', '}' ].includes( this.tokens[this.recoverTokenIdx - 1].type ))))
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
return recoverDepth;
|
|
778
|
+
++this.recoverTokenIdx;
|
|
779
|
+
}
|
|
780
|
+
throw Error( 'EOF must be last in `tokens`' );
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
_reportAndRecover() {
|
|
784
|
+
this.s = this.errorState;
|
|
785
|
+
const syncSet = this._calculateTokenSet( 'Y' );
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
this.recoverTokenIdx = this.tokenIdx;;
|
|
789
|
+
const prev = this.lb();
|
|
790
|
+
const reuseRecoverDepth = this.reuseErrorTokenIdx != null &&
|
|
791
|
+
prev?.keyword && prev.parsedAs !== 'keyword' &&
|
|
792
|
+
this.reuseErrorTokenIdx < this.tokenIdx && syncSet[prev.keyword];
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
this.reportUnexpectedToken_( reuseRecoverDepth ? 'reuse' : null );
|
|
797
|
+
|
|
798
|
+
if (this.reuseErrorTokenIdx != null)
|
|
799
|
+
this.reuseErrorTokenIdx = (reuseRecoverDepth) ? this.tokenIdx : -1;
|
|
800
|
+
this.fixKeywordTokenIdx = (reuseRecoverDepth) ? --this.recoverTokenIdx : -1;
|
|
801
|
+
|
|
802
|
+
const recoverDepth = reuseRecoverDepth || this._findSyncToken( syncSet );
|
|
803
|
+
this.s = null;
|
|
804
|
+
let depth = this.stack.length;
|
|
805
|
+
if (recoverDepth > depth)
|
|
806
|
+
this.s = this.errorState;
|
|
807
|
+
|
|
808
|
+
while (depth > recoverDepth)
|
|
809
|
+
this.stack[--depth].followState = null;
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
if (this.tokenIdx > this.recoverTokenIdx)
|
|
821
|
+
this.reuseToken_();
|
|
822
|
+
else while (this.tokenIdx < this.recoverTokenIdx)
|
|
823
|
+
this.skipToken_();
|
|
824
|
+
this.conditionTokenIdx = this.tokenIdx;
|
|
825
|
+
this.conditionStackLength = null;
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
log( ...args ) {
|
|
832
|
+
console.log( ...args );
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
reportError_( location, text ) {
|
|
836
|
+
this.$hasErrors = true;
|
|
837
|
+
this.log( `${ location }:`, text );
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
reportUnexpectedToken_( msg ) {
|
|
841
|
+
const token = (msg === 'reuse') ? this.lb() : this.la();
|
|
842
|
+
msg ??= `Unexpected token ${ tokenFullName( token, ': ' ) }`;
|
|
843
|
+
msg = (msg === 'reuse')
|
|
844
|
+
? `Missing input before keyword ${ tokenFullName( token, ': ' ) }`
|
|
845
|
+
: msg + ' - expecting: ' + this.expectingArray_().map( tokenName ).sort().join( ', ' );
|
|
846
|
+
this.reportError_( token.location, msg );
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
reportReservedWord_() {
|
|
850
|
+
this.reportUnexpectedToken_( `Unexpected reserved word ‘${ this.la().text }’` );
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
errorAndRecoverOutside( token, text ) {
|
|
854
|
+
|
|
855
|
+
this.reportError_( token.location, text );
|
|
856
|
+
while (this.l() !== ';')
|
|
857
|
+
this.skipToken_();
|
|
858
|
+
this.s = null;
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
inSameRule_( lowState = this.s, highState = this.stack.at(-1).followState ) {
|
|
863
|
+
if (lowState > highState)
|
|
864
|
+
[ lowState, highState ] = [ highState, lowState ];
|
|
865
|
+
while (lowState < highState) {
|
|
866
|
+
if (typeof this.table[++lowState] === 'string')
|
|
867
|
+
return false;
|
|
868
|
+
}
|
|
869
|
+
return true;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
hide_( _arg, mode ) {
|
|
875
|
+
return mode === 'M';
|
|
876
|
+
}
|
|
877
|
+
precLeft_( prec ) {
|
|
878
|
+
const parentPrec = this.stack.at( -1 ).prec;
|
|
879
|
+
if (parentPrec != null && parentPrec >= prec)
|
|
880
|
+
return true;
|
|
881
|
+
this.prec_ = prec;
|
|
882
|
+
return false;
|
|
883
|
+
}
|
|
884
|
+
precRight_( prec ) {
|
|
885
|
+
const parentPrec = this.stack.at( -1 ).prec;
|
|
886
|
+
if (parentPrec != null && parentPrec >= prec)
|
|
887
|
+
return true;
|
|
888
|
+
this.prec_ = prec - 1;
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
precNone_( prec ) {
|
|
892
|
+
const parentPrec = this.stack.at( -1 ).prec;
|
|
893
|
+
if (parentPrec != null && parentPrec >= prec ||
|
|
894
|
+
this.prec_ != null && this.prec_ <= prec)
|
|
895
|
+
return true;
|
|
896
|
+
this.prec_ = prec;
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
precPost_( prec ) {
|
|
900
|
+
const parentPrec = this.stack.at( -1 ).prec;
|
|
901
|
+
if (parentPrec != null && parentPrec >= prec ||
|
|
902
|
+
this.prec_ != null && this.prec_ < prec)
|
|
903
|
+
return true;
|
|
904
|
+
this.prec_ = prec;
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
1038
907
|
}
|
|
1039
908
|
|
|
1040
909
|
function tokenName( type ) {
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
910
|
+
if (typeof type !== 'string')
|
|
911
|
+
type = (!type.parsedAs || type.parsedAs === 'keyword') && type.keyword || type.type;
|
|
912
|
+
return (/^[A-Z]+/.test( type )) ? `‹${ type }›` : `‘${ type }’`;
|
|
1044
913
|
}
|
|
1045
914
|
|
|
1046
915
|
function tokenFullName( token, sep ) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
916
|
+
return (token.parsedAs && token.parsedAs !== 'keyword' && token.parsedAs !== 'token' ||
|
|
917
|
+
token.type !== 'Id' && token.type !== token.text && token.text)
|
|
918
|
+
? `‘${ token.text }’${ sep }${ tokenName( token ) }`
|
|
919
|
+
: tokenName( token );
|
|
1051
920
|
}
|
|
1052
921
|
|
|
1053
922
|
function compileTable( table ) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
if (!line[''])
|
|
1066
|
-
line[''] = [ 'e' ];
|
|
1067
|
-
}
|
|
1068
|
-
table.$compiled = true;
|
|
1069
|
-
return table;
|
|
923
|
+
if (table.$compiled)
|
|
924
|
+
return table;
|
|
925
|
+
for (const line of table) {
|
|
926
|
+
if (typeof line !== 'object' || Array.isArray( line ))
|
|
927
|
+
continue;
|
|
928
|
+
const cache = Object.create( null );
|
|
929
|
+
for (const prop of Object.keys( line )) {
|
|
930
|
+
const alt = line[prop];
|
|
931
|
+
if (!Array.isArray( alt ) && prop.charAt(0) !== ' ')
|
|
932
|
+
line[prop] = (typeof alt === 'string') ? line[alt] : (cache[alt] ??= [ 'g', alt ]);
|
|
1070
933
|
}
|
|
1071
|
-
|
|
934
|
+
if (!line[''])
|
|
935
|
+
line[''] = [ 'e' ];
|
|
936
|
+
}
|
|
937
|
+
table.$compiled = true;
|
|
938
|
+
return table;
|
|
939
|
+
}
|
|
940
|
+
BaseParser.prototype.isNoKeywordInRuleFollow.afterError = true;
|
|
1072
941
|
module.exports = BaseParser;
|