@dbml/parse 0.0.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.
@@ -0,0 +1,4698 @@
1
+ import C from "lodash";
2
+ var l = /* @__PURE__ */ ((e) => (e.SPACE = "<space>", e.TAB = "<tab>", e.NEWLINE = "<newline>", e.COMMA = "<comma>", e.LPAREN = "<lparen>", e.RPAREN = "<rparen>", e.LBRACE = "<lbrace>", e.RBRACE = "<rbrace>", e.LBRACKET = "<lbracket>", e.RBRACKET = "<rbracket>", e.LANGLE = "<langle>", e.RANGLE = "<rangle>", e.OP = "<op>", e.EOF = "<eof>", e.NUMERIC_LITERAL = "<number>", e.STRING_LITERAL = "<string>", e.COLOR_LITERAL = "<color>", e.FUNCTION_EXPRESSION = "<function-expression>", e.QUOTED_STRING = "<variable>", e.IDENTIFIER = "<identifier>", e.SEMICOLON = "<semicolon>", e.COLON = "<colon>", e.SINGLE_LINE_COMMENT = "<single-line-comment>", e.MULTILINE_COMMENT = "<multiline-comment>", e))(l || {});
3
+ function tr(e) {
4
+ switch (e.kind) {
5
+ case "<newline>":
6
+ case "<space>":
7
+ case "<tab>":
8
+ case "<single-line-comment>":
9
+ case "<multiline-comment>":
10
+ return !0;
11
+ default:
12
+ return !1;
13
+ }
14
+ }
15
+ function at(e) {
16
+ if (!e)
17
+ return !1;
18
+ switch (e) {
19
+ case "+":
20
+ case "-":
21
+ case "*":
22
+ case "/":
23
+ case "%":
24
+ case "<":
25
+ case ">":
26
+ case "=":
27
+ case "!":
28
+ case ".":
29
+ case "&":
30
+ case "|":
31
+ return !0;
32
+ default:
33
+ return !1;
34
+ }
35
+ }
36
+ function ot(e) {
37
+ return e !== void 0 && e.kind === "<op>";
38
+ }
39
+ class P {
40
+ constructor(t, r, s, n, i) {
41
+ this.kind = t, this.startPos = r, this.endPos = s, this.value = n, this.leadingTrivia = [], this.trailingTrivia = [], this.leadingInvalid = [], this.trailingInvalid = [], this.isInvalid = i, this.start = r.offset, this.end = s.offset;
42
+ }
43
+ static create(t, r, s, n, i) {
44
+ return new P(t, r, s, n, i);
45
+ }
46
+ }
47
+ function xt(e) {
48
+ return e.trailingTrivia.find(({ kind: t }) => t === l.NEWLINE) !== void 0;
49
+ }
50
+ function lt(e, t) {
51
+ return t.leadingTrivia.find(({ kind: s }) => s === l.NEWLINE) !== void 0 || xt(e);
52
+ }
53
+ function _t(e) {
54
+ return e.trailingTrivia.find(({ kind: t }) => t === l.SPACE) !== void 0;
55
+ }
56
+ function Ot(e) {
57
+ return e.trailingTrivia.length === 0 ? e.end : Ot(C.last(e.trailingTrivia));
58
+ }
59
+ function vt(e) {
60
+ return e.leadingTrivia.length === 0 ? e.start : vt(e.leadingTrivia[0]);
61
+ }
62
+ function rr(e) {
63
+ return [l.SINGLE_LINE_COMMENT, l.MULTILINE_COMMENT].includes(
64
+ e.kind
65
+ );
66
+ }
67
+ class sr {
68
+ constructor() {
69
+ this.id = 0;
70
+ }
71
+ reset() {
72
+ this.id = 0;
73
+ }
74
+ nextId() {
75
+ return this.id++;
76
+ }
77
+ }
78
+ class O {
79
+ // The enclosing element/program
80
+ // args must be passed in order of appearance in the node
81
+ constructor(t, r, s) {
82
+ this.id = t, this.kind = r;
83
+ const n = s.find((a) => a !== void 0 && !Number.isNaN(a.start));
84
+ n ? (this.startPos = n.startPos, this.fullStart = n instanceof P ? vt(n) : n.fullStart) : (this.startPos = {
85
+ offset: NaN,
86
+ column: NaN,
87
+ line: NaN
88
+ }, this.fullStart = NaN);
89
+ const i = [...s].reverse().find((a) => a !== void 0 && !Number.isNaN(a.end));
90
+ i ? (this.endPos = i.endPos, this.fullEnd = i instanceof P ? Ot(i) : i.fullEnd) : (this.endPos = {
91
+ offset: NaN,
92
+ column: NaN,
93
+ line: NaN
94
+ }, this.fullEnd = NaN), this.start = this.startPos.offset, this.end = this.endPos.offset;
95
+ }
96
+ }
97
+ var de = /* @__PURE__ */ ((e) => (e.PROGRAM = "<program>", e.ELEMENT_DECLARATION = "<element-declaration>", e.ATTRIBUTE = "<attribute>", e.IDENTIFIER_STREAM = "<identifer-stream>", e.LITERAL = "<literal>", e.VARIABLE = "<variable>", e.PREFIX_EXPRESSION = "<prefix-expression>", e.INFIX_EXPRESSION = "<infix-expression>", e.POSTFIX_EXPRESSION = "<postfix-expression>", e.FUNCTION_EXPRESSION = "<function-expression>", e.FUNCTION_APPLICATION = "<function-application>", e.BLOCK_EXPRESSION = "<block-expression>", e.LIST_EXPRESSION = "<list-expression>", e.TUPLE_EXPRESSION = "<tuple-expression>", e.CALL_EXPRESSION = "<call-expression>", e.PRIMARY_EXPRESSION = "<primary-expression>", e.GROUP_EXPRESSION = "<group-expression>", e))(de || {});
98
+ class ae extends O {
99
+ constructor({ body: t = [], eof: r }, s) {
100
+ super(s, "<program>", [...t, r]), this.body = t, this.eof = r;
101
+ }
102
+ }
103
+ class A extends O {
104
+ constructor({
105
+ type: t,
106
+ name: r,
107
+ as: s,
108
+ alias: n,
109
+ attributeList: i,
110
+ bodyColon: a,
111
+ body: o
112
+ }, u) {
113
+ if (super(u, "<element-declaration>", [
114
+ t,
115
+ r,
116
+ s,
117
+ n,
118
+ i,
119
+ a,
120
+ o
121
+ ]), a && !(o instanceof te || o instanceof A))
122
+ throw new Error("If an element has a simple body, it must be a function application node");
123
+ this.type = t, this.name = r, this.as = s, this.alias = n, this.attributeList = i, this.bodyColon = a, this.body = o;
124
+ }
125
+ }
126
+ class q extends O {
127
+ constructor({ identifiers: t = [] }, r) {
128
+ super(r, "<identifer-stream>", t || []), this.identifiers = t;
129
+ }
130
+ }
131
+ class xe extends O {
132
+ constructor({
133
+ name: t,
134
+ colon: r,
135
+ value: s
136
+ }, n) {
137
+ super(n, "<attribute>", [t, r, s]), this.name = t, this.value = s, this.colon = r;
138
+ }
139
+ }
140
+ class z extends O {
141
+ constructor({ op: t, expression: r }, s) {
142
+ super(s, "<prefix-expression>", [t, r]), this.op = t, this.expression = r;
143
+ }
144
+ }
145
+ class K extends O {
146
+ constructor({
147
+ op: t,
148
+ leftExpression: r,
149
+ rightExpression: s
150
+ }, n) {
151
+ super(n, "<infix-expression>", [r, t, s]), this.op = t, this.leftExpression = r, this.rightExpression = s;
152
+ }
153
+ }
154
+ class Ce extends O {
155
+ constructor({ op: t, expression: r }, s) {
156
+ super(s, "<postfix-expression>", [r, t]), this.op = t, this.expression = r;
157
+ }
158
+ }
159
+ class B extends O {
160
+ constructor({ value: t }, r) {
161
+ super(r, "<function-expression>", [t]), this.value = t;
162
+ }
163
+ }
164
+ class te extends O {
165
+ constructor({ callee: t, args: r = [] }, s) {
166
+ super(s, "<function-application>", [t, ...r]), this.callee = t, this.args = r;
167
+ }
168
+ }
169
+ class j extends O {
170
+ constructor({
171
+ blockOpenBrace: t,
172
+ body: r = [],
173
+ blockCloseBrace: s
174
+ }, n) {
175
+ super(n, "<block-expression>", [t, ...r, s]), this.blockOpenBrace = t, this.body = r, this.blockCloseBrace = s;
176
+ }
177
+ }
178
+ class U extends O {
179
+ constructor({
180
+ listOpenBracket: t,
181
+ elementList: r = [],
182
+ commaList: s = [],
183
+ listCloseBracket: n
184
+ }, i) {
185
+ super(i, "<list-expression>", [
186
+ t,
187
+ ...yt(r, s),
188
+ n
189
+ ]), this.listOpenBracket = t, this.elementList = r, this.commaList = s, this.listCloseBracket = n;
190
+ }
191
+ }
192
+ class Q extends O {
193
+ constructor({
194
+ tupleOpenParen: t,
195
+ elementList: r = [],
196
+ commaList: s = [],
197
+ tupleCloseParen: n
198
+ }, i) {
199
+ super(i, "<tuple-expression>", [
200
+ t,
201
+ ...yt(r, s),
202
+ n
203
+ ]), this.tupleOpenParen = t, this.elementList = r, this.commaList = s, this.tupleCloseParen = n;
204
+ }
205
+ }
206
+ class qe extends Q {
207
+ constructor({
208
+ groupOpenParen: t,
209
+ expression: r,
210
+ groupCloseParen: s
211
+ }, n) {
212
+ super(
213
+ {
214
+ tupleOpenParen: t,
215
+ elementList: r && [r],
216
+ commaList: [],
217
+ tupleCloseParen: s
218
+ },
219
+ n
220
+ ), this.kind = "<group-expression>";
221
+ }
222
+ }
223
+ class oe extends O {
224
+ constructor({
225
+ callee: t,
226
+ argumentList: r
227
+ }, s) {
228
+ super(s, "<call-expression>", [t, r]), this.callee = t, this.argumentList = r;
229
+ }
230
+ }
231
+ class ue extends O {
232
+ constructor({ literal: t }, r) {
233
+ super(r, "<literal>", [t]), this.literal = t;
234
+ }
235
+ }
236
+ class M extends O {
237
+ constructor({ variable: t }, r) {
238
+ super(r, "<variable>", [t]), this.variable = t;
239
+ }
240
+ }
241
+ class S extends O {
242
+ constructor({ expression: t }, r) {
243
+ super(r, "<primary-expression>", [t]), this.expression = t;
244
+ }
245
+ }
246
+ function yt(e, t) {
247
+ if (!e || e.length === 0)
248
+ return t || [];
249
+ if (!t || t.length === 0)
250
+ return e || [];
251
+ const [r] = e, [s] = t;
252
+ return (r.start < s.start ? C.flatten(C.zip(e, t)) : C.flatten(C.zip(t, e))).filter(
253
+ (n) => n !== null
254
+ );
255
+ }
256
+ function ys(e, t = !1) {
257
+ return JSON.stringify(
258
+ e,
259
+ function(r, s) {
260
+ var n;
261
+ return !(this instanceof ae) && r === "symbol" ? s == null ? void 0 : s.id : (
262
+ /* this instanceof SyntaxNode && */
263
+ r === "symbol" ? {
264
+ symbolTable: s == null ? void 0 : s.symbolTable,
265
+ id: s == null ? void 0 : s.id,
266
+ references: s == null ? void 0 : s.references.map((i) => i.id),
267
+ declaration: (n = s == null ? void 0 : s.declaration) == null ? void 0 : n.id
268
+ } : (
269
+ /* this instanceof SyntaxNode && */
270
+ r === "referee" || /* this instanceof SyntaxNode && */
271
+ r === "parent" || /* this instanceof NodeSymbol && */
272
+ r === "declaration" ? s == null ? void 0 : s.id : (
273
+ /* this instanceof NodeSymbol && */
274
+ r === "symbolTable" ? Object.fromEntries(s.table) : s
275
+ )
276
+ )
277
+ );
278
+ },
279
+ t ? 2 : 0
280
+ );
281
+ }
282
+ class I {
283
+ constructor(t) {
284
+ this.value = t;
285
+ }
286
+ unwrap() {
287
+ return this.value;
288
+ }
289
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
290
+ unwrap_or(t) {
291
+ return this.value;
292
+ }
293
+ and_then(t) {
294
+ return t(this.value);
295
+ }
296
+ map(t) {
297
+ return new I(t(this.value));
298
+ }
299
+ // eslint-disable-next-line class-methods-use-this
300
+ isOk() {
301
+ return !0;
302
+ }
303
+ }
304
+ class T {
305
+ // eslint-disable-next-line class-methods-use-this
306
+ unwrap() {
307
+ throw new Error("Trying to unwrap a None value");
308
+ }
309
+ // eslint-disable-next-line class-methods-use-this
310
+ unwrap_or(t) {
311
+ return t;
312
+ }
313
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
314
+ and_then(t) {
315
+ return new T();
316
+ }
317
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
318
+ map(t) {
319
+ return new T();
320
+ }
321
+ // eslint-disable-next-line class-methods-use-this
322
+ isOk() {
323
+ return !1;
324
+ }
325
+ }
326
+ var N = /* @__PURE__ */ ((e) => (e.Schema = "Schema", e.Table = "Table", e.Column = "Column", e.TableGroup = "TableGroup", e.TableGroupField = "TableGroup field", e.Enum = "Enum", e.EnumField = "Enum field", e))(N || {});
327
+ function je(e) {
328
+ return `Schema:${e}`;
329
+ }
330
+ function ze(e) {
331
+ return `Table:${e}`;
332
+ }
333
+ function Ke(e) {
334
+ return `Column:${e}`;
335
+ }
336
+ function Qe(e) {
337
+ return `Enum:${e}`;
338
+ }
339
+ function Ye(e) {
340
+ return `Enum field:${e}`;
341
+ }
342
+ function Me(e) {
343
+ return `TableGroup:${e}`;
344
+ }
345
+ function kt(e) {
346
+ return `TableGroup field:${e}`;
347
+ }
348
+ function Be(e, t) {
349
+ switch (t) {
350
+ case "Column":
351
+ return Ke(e);
352
+ case "Enum":
353
+ return Qe(e);
354
+ case "Enum field":
355
+ return Ye(e);
356
+ case "Schema":
357
+ return je(e);
358
+ case "Table":
359
+ return ze(e);
360
+ case "TableGroup":
361
+ return Me(e);
362
+ case "TableGroup field":
363
+ return kt(e);
364
+ default:
365
+ throw new Error("Unreachable");
366
+ }
367
+ }
368
+ function ee(e) {
369
+ const [t, r] = e.split(":");
370
+ return Object.values(N).includes(t) ? new I({
371
+ name: r,
372
+ kind: t
373
+ }) : new T();
374
+ }
375
+ function nr(e) {
376
+ const t = ee(e).unwrap_or(void 0);
377
+ if (!t)
378
+ return !1;
379
+ const { kind: r, name: s } = t;
380
+ return r === "Schema" && s === "public";
381
+ }
382
+ var x = /* @__PURE__ */ ((e) => (e[e.TopLevelContext = 0] = "TopLevelContext", e[e.ProjectContext = 1] = "ProjectContext", e[e.TableContext = 2] = "TableContext", e[e.TableGroupContext = 3] = "TableGroupContext", e[e.EnumContext = 4] = "EnumContext", e[e.RefContext = 5] = "RefContext", e[e.IndexesContext = 6] = "IndexesContext", e[e.NoteContext = 7] = "NoteContext", e[e.CustomContext = 8] = "CustomContext", e))(x || {});
383
+ function ir(e, t) {
384
+ switch (e) {
385
+ case 0:
386
+ return t === 1 || t === 2 || t === 3 || t === 4 || t === 5;
387
+ case 1:
388
+ return t === 2 || t === 3 || t === 4 || t === 7 || t === 5 || t === 8;
389
+ case 2:
390
+ return t === 6 || t === 7 || t === 5;
391
+ default:
392
+ return !1;
393
+ }
394
+ }
395
+ class ar {
396
+ constructor() {
397
+ this.stack = [
398
+ 0
399
+ /* TopLevelContext */
400
+ ];
401
+ }
402
+ push(t) {
403
+ this.stack.push(t);
404
+ }
405
+ pop() {
406
+ return this.stack.length === 1 ? this.stack[0] : this.stack.pop();
407
+ }
408
+ top() {
409
+ return this.stack[this.stack.length - 1];
410
+ }
411
+ parent() {
412
+ return this.stack.length === 1 ? this.stack[0] : this.stack[this.stack.length - 2];
413
+ }
414
+ isWithinContext(t) {
415
+ for (let r = this.stack.length - 1; r >= 0; r -= 1)
416
+ if (this.stack[r] === t)
417
+ return !0;
418
+ return !1;
419
+ }
420
+ }
421
+ class we {
422
+ constructor() {
423
+ this.table = /* @__PURE__ */ new Map();
424
+ }
425
+ has(t) {
426
+ return this.table.has(t);
427
+ }
428
+ set(t, r) {
429
+ this.table.set(t, r);
430
+ }
431
+ get(t, r) {
432
+ return this.table.get(t) || r !== void 0 && this.set(t, r) || r;
433
+ }
434
+ entries() {
435
+ return this.table.entries();
436
+ }
437
+ }
438
+ class or {
439
+ constructor() {
440
+ this.id = 0;
441
+ }
442
+ reset() {
443
+ this.id = 0;
444
+ }
445
+ nextId() {
446
+ return this.id++;
447
+ }
448
+ }
449
+ class St {
450
+ constructor({ symbolTable: t }, r) {
451
+ this.references = [], this.id = r, this.symbolTable = t;
452
+ }
453
+ }
454
+ class lr {
455
+ constructor({ symbolTable: t, declaration: r }, s) {
456
+ this.references = [], this.id = s, this.symbolTable = t, this.declaration = r;
457
+ }
458
+ }
459
+ class cr {
460
+ constructor({ declaration: t }, r) {
461
+ this.references = [], this.id = r, this.declaration = t;
462
+ }
463
+ }
464
+ class Rt {
465
+ constructor({ symbolTable: t, declaration: r }, s) {
466
+ this.references = [], this.id = s, this.symbolTable = t, this.declaration = r;
467
+ }
468
+ }
469
+ class Dt {
470
+ constructor({ declaration: t }, r) {
471
+ this.references = [], this.id = r, this.declaration = t;
472
+ }
473
+ }
474
+ class ur {
475
+ constructor({ symbolTable: t, declaration: r }, s) {
476
+ this.references = [], this.id = s, this.symbolTable = t, this.declaration = r;
477
+ }
478
+ }
479
+ class hr {
480
+ constructor({ declaration: t }, r) {
481
+ this.references = [], this.id = r, this.declaration = t;
482
+ }
483
+ }
484
+ function dr(e, t) {
485
+ switch (t) {
486
+ case x.TableContext:
487
+ return ze(e);
488
+ case x.EnumContext:
489
+ return Qe(e);
490
+ case x.TableGroupContext:
491
+ return Me(e);
492
+ default:
493
+ return;
494
+ }
495
+ }
496
+ function fr(e, t) {
497
+ switch (t) {
498
+ case x.TableContext:
499
+ return Ke(e);
500
+ case x.EnumContext:
501
+ return Ye(e);
502
+ case x.TableGroupContext:
503
+ return Me(e);
504
+ default:
505
+ return;
506
+ }
507
+ }
508
+ function ct(e, t, r) {
509
+ switch (t) {
510
+ case x.TableContext:
511
+ return r.create(Rt, { symbolTable: new we(), declaration: e });
512
+ case x.EnumContext:
513
+ return r.create(lr, { symbolTable: new we(), declaration: e });
514
+ case x.TableGroupContext:
515
+ return r.create(ur, { symbolTable: new we(), declaration: e });
516
+ default:
517
+ return;
518
+ }
519
+ }
520
+ function Er(e, t, r) {
521
+ switch (t) {
522
+ case x.TableContext:
523
+ return r.create(Dt, { declaration: e });
524
+ case x.EnumContext:
525
+ return r.create(cr, { declaration: e });
526
+ case x.TableGroupContext:
527
+ return r.create(hr, { declaration: e });
528
+ default:
529
+ return;
530
+ }
531
+ }
532
+ function pr(e) {
533
+ return [
534
+ je,
535
+ ze,
536
+ Qe,
537
+ Me,
538
+ Ke,
539
+ Ye,
540
+ kt
541
+ ].map((t) => t(e));
542
+ }
543
+ function He(e) {
544
+ const [t] = e;
545
+ return t >= "a" && t <= "z" || t >= "A" && t <= "Z" || t === "_";
546
+ }
547
+ function ke(e) {
548
+ const [t] = e;
549
+ return t >= "0" && t <= "9";
550
+ }
551
+ function Nr(e) {
552
+ const [t] = e;
553
+ return ke(t) || He(t) && t.toLowerCase() >= "a" && t.toLowerCase() <= "f";
554
+ }
555
+ function Ie(e) {
556
+ return He(e) || ke(e);
557
+ }
558
+ function ut(e, t) {
559
+ const r = [], s = Math.min(e.length, t.length);
560
+ for (let n = 0; n < s; n += 1)
561
+ r.push(e[n], t[n]);
562
+ return r.push(...e.slice(s), ...t.slice(s)), r;
563
+ }
564
+ function Ae(e, t) {
565
+ return e >= t.start && e < t.end;
566
+ }
567
+ var c = /* @__PURE__ */ ((e) => (e[e.UNKNOWN_SYMBOL = 1e3] = "UNKNOWN_SYMBOL", e[e.UNEXPECTED_SYMBOL = 1001] = "UNEXPECTED_SYMBOL", e[e.UNEXPECTED_EOF = 1002] = "UNEXPECTED_EOF", e[e.UNEXPECTED_NEWLINE = 1003] = "UNEXPECTED_NEWLINE", e[e.UNKNOWN_TOKEN = 1004] = "UNKNOWN_TOKEN", e[e.UNEXPECTED_TOKEN = 1005] = "UNEXPECTED_TOKEN", e[e.MISPLACED_LIST_NODE = 1006] = "MISPLACED_LIST_NODE", e[e.MISSING_SPACES = 1007] = "MISSING_SPACES", e[e.UNKNOWN_PREFIX_OP = 1008] = "UNKNOWN_PREFIX_OP", e[e.INVALID_OPERAND = 1009] = "INVALID_OPERAND", e[e.EMPTY_ATTRIBUTE_NAME = 1010] = "EMPTY_ATTRIBUTE_NAME", e[e.INVALID_NAME = 3e3] = "INVALID_NAME", e[e.UNEXPECTED_NAME = 3001] = "UNEXPECTED_NAME", e[e.NAME_NOT_FOUND = 3002] = "NAME_NOT_FOUND", e[e.DUPLICATE_NAME = 3003] = "DUPLICATE_NAME", e[e.INVALID_ALIAS = 3004] = "INVALID_ALIAS", e[e.UNEXPECTED_ALIAS = 3005] = "UNEXPECTED_ALIAS", e[e.UNEXPECTED_SETTINGS = 3006] = "UNEXPECTED_SETTINGS", e[e.INVALID_SETTINGS = 3007] = "INVALID_SETTINGS", e[e.UNEXPECTED_SIMPLE_BODY = 3008] = "UNEXPECTED_SIMPLE_BODY", e[e.UNEXPECTED_COMPLEX_BODY = 3009] = "UNEXPECTED_COMPLEX_BODY", e[e.INVALID_TABLE_CONTEXT = 3010] = "INVALID_TABLE_CONTEXT", e[e.INVALID_TABLE_SETTING = 3011] = "INVALID_TABLE_SETTING", e[e.DUPLICATE_TABLE_SETTING = 3012] = "DUPLICATE_TABLE_SETTING", e[e.INVALID_TABLEGROUP_CONTEXT = 3013] = "INVALID_TABLEGROUP_CONTEXT", e[e.INVALID_TABLEGROUP_ELEMENT_NAME = 3014] = "INVALID_TABLEGROUP_ELEMENT_NAME", e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME = 3015] = "DUPLICATE_TABLEGROUP_ELEMENT_NAME", e[e.INVALID_TABLEGROUP_FIELD = 3016] = "INVALID_TABLEGROUP_FIELD", e[e.INVALID_COLUMN = 3017] = "INVALID_COLUMN", e[e.INVALID_COLUMN_NAME = 3018] = "INVALID_COLUMN_NAME", e[e.UNKNOWN_COLUMN_SETTING = 3019] = "UNKNOWN_COLUMN_SETTING", e[e.INVALID_COLUMN_TYPE = 3020] = "INVALID_COLUMN_TYPE", e[e.DUPLICATE_COLUMN_NAME = 3021] = "DUPLICATE_COLUMN_NAME", e[e.DUPLICATE_COLUMN_SETTING = 3022] = "DUPLICATE_COLUMN_SETTING", e[e.INVALID_COLUMN_SETTING_VALUE = 3023] = "INVALID_COLUMN_SETTING_VALUE", e[e.INVALID_ENUM_CONTEXT = 3024] = "INVALID_ENUM_CONTEXT", e[e.INVALID_ENUM_ELEMENT_NAME = 3025] = "INVALID_ENUM_ELEMENT_NAME", e[e.INVALID_ENUM_ELEMENT = 3026] = "INVALID_ENUM_ELEMENT", e[e.DUPLICATE_ENUM_ELEMENT_NAME = 3027] = "DUPLICATE_ENUM_ELEMENT_NAME", e[e.UNKNOWN_ENUM_ELEMENT_SETTING = 3028] = "UNKNOWN_ENUM_ELEMENT_SETTING", e[e.DUPLICATE_ENUM_ELEMENT_SETTING = 3029] = "DUPLICATE_ENUM_ELEMENT_SETTING", e[e.INVALID_ENUM_ELEMENT_SETTING = 3030] = "INVALID_ENUM_ELEMENT_SETTING", e[e.INVALID_REF_CONTEXT = 3031] = "INVALID_REF_CONTEXT", e[e.UNKNOWN_REF_SETTING = 3032] = "UNKNOWN_REF_SETTING", e[e.DUPLICATE_REF_SETTING = 3033] = "DUPLICATE_REF_SETTING", e[e.INVALID_REF_SETTING_VALUE = 3034] = "INVALID_REF_SETTING_VALUE", e[e.INVALID_REF_RELATIONSHIP = 3035] = "INVALID_REF_RELATIONSHIP", e[e.INVALID_REF_FIELD = 3036] = "INVALID_REF_FIELD", e[e.INVALID_NOTE_CONTEXT = 3037] = "INVALID_NOTE_CONTEXT", e[e.INVALID_NOTE = 3038] = "INVALID_NOTE", e[e.NOTE_REDEFINED = 3039] = "NOTE_REDEFINED", e[e.NOTE_CONTENT_REDEFINED = 3040] = "NOTE_CONTENT_REDEFINED", e[e.INVALID_INDEXES_CONTEXT = 3041] = "INVALID_INDEXES_CONTEXT", e[e.INVALID_INDEXES_FIELD = 3042] = "INVALID_INDEXES_FIELD", e[e.INVALID_INDEX = 3043] = "INVALID_INDEX", e[e.UNKNOWN_INDEX_SETTING = 3044] = "UNKNOWN_INDEX_SETTING", e[e.DUPLICATE_INDEX_SETTING = 3045] = "DUPLICATE_INDEX_SETTING", e[e.UNEXPECTED_INDEX_SETTING_VALUE = 3046] = "UNEXPECTED_INDEX_SETTING_VALUE", e[e.INVALID_INDEX_SETTING_VALUE = 3047] = "INVALID_INDEX_SETTING_VALUE", e[e.INVALID_PROJECT_CONTEXT = 3048] = "INVALID_PROJECT_CONTEXT", e[e.PROJECT_REDEFINED = 3049] = "PROJECT_REDEFINED", e[e.INVALID_PROJECT_FIELD = 3050] = "INVALID_PROJECT_FIELD", e[e.INVALID_CUSTOM_CONTEXT = 3051] = "INVALID_CUSTOM_CONTEXT", e[e.INVALID_CUSTOM_ELEMENT_VALUE = 3052] = "INVALID_CUSTOM_ELEMENT_VALUE", e[e.INVALID_ELEMENT_IN_SIMPLE_BODY = 3053] = "INVALID_ELEMENT_IN_SIMPLE_BODY", e[e.BINDING_ERROR = 4e3] = "BINDING_ERROR", e[e.UNSUPPORTED = 5e3] = "UNSUPPORTED", e[e.CIRCULAR_REF = 5001] = "CIRCULAR_REF", e[e.SAME_ENDPOINT = 5002] = "SAME_ENDPOINT", e[e.UNEQUAL_FIELDS_BINARY_REF = 5003] = "UNEQUAL_FIELDS_BINARY_REF", e[e.CONFLICTING_SETTING = 5004] = "CONFLICTING_SETTING", e))(c || {});
568
+ class w extends Error {
569
+ constructor(t, r, s) {
570
+ super(r), this.code = t, this.diagnostic = r, this.nodeOrToken = s, this.start = s.start, this.end = s.end, this.name = this.constructor.name, Object.setPrototypeOf(this, w.prototype);
571
+ }
572
+ isTokenError() {
573
+ return this.nodeOrToken instanceof P;
574
+ }
575
+ isNodeError() {
576
+ return !(this.nodeOrToken instanceof P);
577
+ }
578
+ }
579
+ class H {
580
+ constructor(t, r) {
581
+ this.value = t, this.errors = r === void 0 ? [] : r;
582
+ }
583
+ getValue() {
584
+ return this.value;
585
+ }
586
+ getErrors() {
587
+ return this.errors;
588
+ }
589
+ chain(t) {
590
+ const r = t(this.value), s = [...this.errors, ...r.errors];
591
+ return new H(r.value, s);
592
+ }
593
+ map(t) {
594
+ return new H(t(this.value), this.errors);
595
+ }
596
+ }
597
+ function br(e, t, r) {
598
+ if (!e || !Ir(e) || t.length === 0)
599
+ return new T();
600
+ const s = [...t], n = ve(e).unwrap(), i = s.pop();
601
+ if (!(i instanceof j))
602
+ return new T();
603
+ const a = C.last(s) instanceof U ? s.pop() : void 0;
604
+ return s.length === 3 && ve(s[1]).unwrap().value === "as" ? new I(
605
+ r.create(A, {
606
+ type: n,
607
+ name: s[0],
608
+ as: ve(s[1]).unwrap(),
609
+ alias: s[2],
610
+ attributeList: a,
611
+ body: i
612
+ })
613
+ ) : s.length === 1 ? new I(
614
+ r.create(A, {
615
+ type: n,
616
+ name: s[0],
617
+ attributeList: a,
618
+ body: i
619
+ })
620
+ ) : s.length === 0 ? new I(
621
+ r.create(A, {
622
+ type: n,
623
+ attributeList: a,
624
+ body: i
625
+ })
626
+ ) : new T();
627
+ }
628
+ function ht(e) {
629
+ return e.kind === l.IDENTIFIER && e.value === "as";
630
+ }
631
+ function E(e) {
632
+ e && (e instanceof P ? mr(e) : gr(e));
633
+ }
634
+ function mr(e) {
635
+ e.kind !== l.EOF && (e.isInvalid = !0);
636
+ }
637
+ function gr(e) {
638
+ if (e instanceof A)
639
+ E(e.type), E(e.name), E(e.as), E(e.alias), E(e.bodyColon), E(e.attributeList), E(e.body);
640
+ else if (e instanceof q)
641
+ e.identifiers.forEach(E);
642
+ else if (e instanceof xe)
643
+ E(e.name), E(e.colon), E(e.value);
644
+ else if (e instanceof z)
645
+ E(e.op), E(e.expression);
646
+ else if (e instanceof K)
647
+ E(e.leftExpression), E(e.op), E(e.rightExpression);
648
+ else if (e instanceof Ce)
649
+ E(e.op), E(e.expression);
650
+ else if (e instanceof j)
651
+ E(e.blockOpenBrace), e.body.forEach(E), E(e.blockCloseBrace);
652
+ else if (e instanceof U)
653
+ E(e.listOpenBracket), e.commaList.forEach(E), e.elementList.forEach(E), E(e.listCloseBracket);
654
+ else if (e instanceof Q)
655
+ E(e.tupleOpenParen), e.commaList.forEach(E), e.elementList.forEach(E), E(e.tupleCloseParen);
656
+ else if (e instanceof oe)
657
+ E(e.callee), E(e.argumentList);
658
+ else if (e instanceof te)
659
+ E(e.callee), e.args.forEach(E);
660
+ else if (e instanceof S)
661
+ E(e.expression);
662
+ else if (e instanceof B)
663
+ E(e.value);
664
+ else if (e instanceof M)
665
+ E(e.variable);
666
+ else if (e instanceof ue)
667
+ E(e.literal);
668
+ else
669
+ throw e instanceof qe ? new Error("This case is handled by the TupleExpressionNode case") : new Error("Unreachable case in markInvalidNode");
670
+ }
671
+ function Ct(e) {
672
+ return !!(e != null && e.isInvalid);
673
+ }
674
+ function D(...e) {
675
+ return e.filter((t) => t !== void 0);
676
+ }
677
+ function Tr(e) {
678
+ if (e instanceof ae)
679
+ return D(...e.body, e.eof);
680
+ if (e instanceof A)
681
+ return D(
682
+ e.type,
683
+ e.name,
684
+ e.as,
685
+ e.alias,
686
+ e.attributeList,
687
+ e.bodyColon,
688
+ e.body
689
+ );
690
+ if (e instanceof xe)
691
+ return D(e.name, e.colon, e.value);
692
+ if (e instanceof q)
693
+ return e.identifiers;
694
+ if (e instanceof ue)
695
+ return e.literal ? [e.literal] : [];
696
+ if (e instanceof M)
697
+ return D(e.variable);
698
+ if (e instanceof z)
699
+ return D(e.op, e.expression);
700
+ if (e instanceof K)
701
+ return D(e.leftExpression, e.op, e.rightExpression);
702
+ if (e instanceof Ce)
703
+ return D(e.expression, e.op);
704
+ if (e instanceof B)
705
+ return D(e.value);
706
+ if (e instanceof te)
707
+ return D(e.callee, ...e.args);
708
+ if (e instanceof j)
709
+ return D(e.blockOpenBrace, ...e.body, e.blockCloseBrace);
710
+ if (e instanceof U)
711
+ return D(
712
+ e.listOpenBracket,
713
+ ...ut(e.elementList, e.commaList),
714
+ e.listCloseBracket
715
+ );
716
+ if (e instanceof Q)
717
+ return D(
718
+ e.tupleOpenParen,
719
+ ...ut(e.elementList, e.commaList),
720
+ e.tupleCloseParen
721
+ );
722
+ if (e instanceof oe)
723
+ return D(e.callee, e.argumentList);
724
+ if (e instanceof S)
725
+ return D(e.expression);
726
+ throw e instanceof qe ? new Error("This case is already handled by TupleExpressionNode") : new Error("Unreachable - no other possible cases");
727
+ }
728
+ function ve(e) {
729
+ return Y(e) ? new I(e.expression.variable) : new T();
730
+ }
731
+ function J(e) {
732
+ var t;
733
+ return e instanceof S && (e.expression instanceof M && e.expression.variable instanceof P || e.expression instanceof ue && ((t = e.expression.literal) == null ? void 0 : t.kind) === l.STRING_LITERAL);
734
+ }
735
+ function Y(e) {
736
+ return e instanceof S && e.expression instanceof M && e.expression.variable instanceof P;
737
+ }
738
+ function Ir(e) {
739
+ var t;
740
+ return e instanceof S && e.expression instanceof M && ((t = e.expression.variable) == null ? void 0 : t.kind) === l.IDENTIFIER;
741
+ }
742
+ function Pe(e) {
743
+ var t;
744
+ return e instanceof K && e.leftExpression instanceof O && e.rightExpression instanceof O && ((t = e.op) == null ? void 0 : t.value) === ".";
745
+ }
746
+ function le(e) {
747
+ if (e === void 0)
748
+ return new T();
749
+ const t = e.identifiers.map((r) => r.value).join(" ");
750
+ return t === "" ? new T() : new I(t);
751
+ }
752
+ function dt(e) {
753
+ return e.create(B, {});
754
+ }
755
+ function Mt(e) {
756
+ return e instanceof B && e.value === void 0;
757
+ }
758
+ class Lr {
759
+ // list of errors during lexing
760
+ constructor(t) {
761
+ this.start = {
762
+ offset: 0,
763
+ line: 0,
764
+ column: 0
765
+ }, this.current = {
766
+ offset: 0,
767
+ line: 0,
768
+ column: 0
769
+ }, this.tokens = [], this.errors = [], this.text = t;
770
+ }
771
+ isAtEnd() {
772
+ return this.current.offset >= this.text.length;
773
+ }
774
+ advance() {
775
+ const t = this.peek();
776
+ return this.current = { ...this.current }, t === `
777
+ ` ? (this.current.line += 1, this.current.column = 0) : this.current.column += 1, this.current.offset += 1, t;
778
+ }
779
+ peek(t = 0) {
780
+ if (!(this.current.offset + t >= this.text.length))
781
+ return this.text[this.current.offset + t];
782
+ }
783
+ // Check if the sequence ahead matches `sequence`
784
+ check(t) {
785
+ for (let r = 0; r < t.length; r += 1)
786
+ if (t[r] !== this.peek(r))
787
+ return !1;
788
+ return !0;
789
+ }
790
+ // If the sequence ahead matches `sequence`, move `current` past `sequence`
791
+ match(t) {
792
+ return this.check(t) ? (t.split("").forEach(() => this.advance()), !0) : !1;
793
+ }
794
+ addToken(t, r = !1) {
795
+ this.tokens.push(this.createToken(t, r));
796
+ }
797
+ createToken(t, r = !1) {
798
+ return P.create(
799
+ t,
800
+ this.start,
801
+ this.current,
802
+ this.text.substring(this.start.offset, this.current.offset),
803
+ r
804
+ );
805
+ }
806
+ lex() {
807
+ return this.scanTokens(), this.tokens.push(P.create(l.EOF, this.start, this.current, "", !1)), this.gatherTrivia(), this.gatherInvalid(), new H(this.tokens, this.errors);
808
+ }
809
+ scanTokens() {
810
+ for (; !this.isAtEnd(); ) {
811
+ const t = this.advance();
812
+ switch (t) {
813
+ case " ":
814
+ this.addToken(l.SPACE);
815
+ break;
816
+ case "\r":
817
+ break;
818
+ case `
819
+ `:
820
+ this.addToken(l.NEWLINE);
821
+ break;
822
+ case " ":
823
+ this.addToken(l.TAB);
824
+ break;
825
+ case ",":
826
+ this.addToken(l.COMMA);
827
+ break;
828
+ case "(":
829
+ this.addToken(l.LPAREN);
830
+ break;
831
+ case ")":
832
+ this.addToken(l.RPAREN);
833
+ break;
834
+ case "[":
835
+ this.addToken(l.LBRACKET);
836
+ break;
837
+ case "]":
838
+ this.addToken(l.RBRACKET);
839
+ break;
840
+ case "{":
841
+ this.addToken(l.LBRACE);
842
+ break;
843
+ case "}":
844
+ this.addToken(l.RBRACE);
845
+ break;
846
+ case ";":
847
+ this.addToken(l.SEMICOLON);
848
+ break;
849
+ case ":":
850
+ this.addToken(l.COLON);
851
+ break;
852
+ case "'":
853
+ this.match("''") ? this.multilineStringLiteral() : this.singleLineStringLiteral();
854
+ break;
855
+ case '"':
856
+ this.quotedVariable();
857
+ break;
858
+ case "`":
859
+ this.functionExpression();
860
+ break;
861
+ case "#":
862
+ this.colorLiteral();
863
+ break;
864
+ case "/":
865
+ this.match("/") ? this.singleLineComment() : this.match("*") ? this.multilineComment() : this.operator();
866
+ break;
867
+ default:
868
+ if (at(t)) {
869
+ this.operator();
870
+ break;
871
+ }
872
+ if (He(t)) {
873
+ this.identifier();
874
+ break;
875
+ }
876
+ if (ke(t)) {
877
+ this.numericLiteral();
878
+ break;
879
+ }
880
+ this.addToken(l.OP, !0), this.errors.push(
881
+ new w(
882
+ c.UNKNOWN_SYMBOL,
883
+ `Unexpected token '${t}'`,
884
+ this.createToken(l.OP, !0)
885
+ )
886
+ );
887
+ break;
888
+ }
889
+ this.start = { ...this.current };
890
+ }
891
+ }
892
+ gatherTrivia() {
893
+ let t = !0, r = [], s;
894
+ const n = [];
895
+ for (const i of this.tokens)
896
+ tr(i) ? (r.push(i), i.kind === l.NEWLINE && s && (s.trailingTrivia = r, t = !0, s = void 0, r = [])) : (t ? i.leadingTrivia = r : s.trailingTrivia = r, n.push(i), r = [], s = i, t = !1);
897
+ this.tokens = n;
898
+ }
899
+ gatherInvalid() {
900
+ let t;
901
+ const r = [], s = [];
902
+ for (t = 0; t < this.tokens.length && Ct(this.tokens[t]); t += 1)
903
+ s.push(this.tokens[t]);
904
+ let n = this.tokens[t];
905
+ for (n.leadingInvalid = [...s, ...n.leadingInvalid]; t < this.tokens.length; t += 1) {
906
+ const i = this.tokens[t];
907
+ i.isInvalid ? n.trailingInvalid.push(i) : (n = i, r.push(i));
908
+ }
909
+ this.tokens = r;
910
+ }
911
+ // Consuming characters until the `stopSequence` is encountered
912
+ consumeUntil(t, r, {
913
+ allowNewline: s,
914
+ // Whether newline is allowed
915
+ allowEof: n,
916
+ // Whether EOF is allowed
917
+ raw: i,
918
+ // Whether to interpret '\' as a backlash
919
+ consumeStopSequence: a = !0
920
+ }) {
921
+ let o = "";
922
+ for (; !this.isAtEnd() && (s || !this.check(`
923
+ `)) && !this.check(r); )
924
+ this.peek() === "\\" && !i ? (this.advance(), o += this.escapedString()) : o += this.advance();
925
+ if (this.isAtEnd() && !n) {
926
+ const u = this.createToken(t, !0);
927
+ this.tokens.push(u), this.errors.push(
928
+ new w(c.UNEXPECTED_EOF, "EOF reached while parsing", u)
929
+ );
930
+ return;
931
+ }
932
+ if (this.check(`
933
+ `) && !s) {
934
+ const u = this.createToken(t, !0);
935
+ this.tokens.push(u), this.errors.push(
936
+ new w(
937
+ c.UNEXPECTED_NEWLINE,
938
+ "Invalid newline encountered while parsing",
939
+ u
940
+ )
941
+ );
942
+ return;
943
+ }
944
+ a && this.match(r), this.tokens.push(P.create(t, this.start, this.current, o, !1));
945
+ }
946
+ singleLineStringLiteral() {
947
+ this.consumeUntil(l.STRING_LITERAL, "'", {
948
+ allowNewline: !1,
949
+ allowEof: !1,
950
+ raw: !1
951
+ });
952
+ }
953
+ multilineStringLiteral() {
954
+ this.consumeUntil(l.STRING_LITERAL, "'''", {
955
+ allowNewline: !0,
956
+ allowEof: !1,
957
+ raw: !1
958
+ });
959
+ }
960
+ functionExpression() {
961
+ this.consumeUntil(l.FUNCTION_EXPRESSION, "`", {
962
+ allowNewline: !1,
963
+ allowEof: !1,
964
+ raw: !0
965
+ });
966
+ }
967
+ quotedVariable() {
968
+ this.consumeUntil(l.QUOTED_STRING, '"', {
969
+ allowNewline: !1,
970
+ allowEof: !1,
971
+ raw: !1
972
+ });
973
+ }
974
+ singleLineComment() {
975
+ this.consumeUntil(l.SINGLE_LINE_COMMENT, `
976
+ `, {
977
+ allowNewline: !0,
978
+ allowEof: !0,
979
+ raw: !0,
980
+ consumeStopSequence: !1
981
+ });
982
+ }
983
+ multilineComment() {
984
+ this.consumeUntil(l.MULTILINE_COMMENT, "*/", {
985
+ allowNewline: !0,
986
+ allowEof: !1,
987
+ raw: !0
988
+ });
989
+ }
990
+ identifier() {
991
+ for (; !this.isAtEnd() && Ie(this.peek()); )
992
+ this.advance();
993
+ this.addToken(l.IDENTIFIER);
994
+ }
995
+ operator() {
996
+ for (; at(this.peek()); )
997
+ this.advance();
998
+ this.addToken(l.OP);
999
+ }
1000
+ numericLiteral() {
1001
+ let t = 0;
1002
+ if (this.isAtEnd())
1003
+ return this.addToken(l.NUMERIC_LITERAL);
1004
+ for (; !this.isAtEnd(); ) {
1005
+ const s = this.check(".");
1006
+ if (t += s ? 1 : 0, t > 1)
1007
+ break;
1008
+ if (!s && this.current.offset === this.text.length - 1)
1009
+ return this.advance(), this.addToken(l.NUMERIC_LITERAL);
1010
+ if (!s && !Ie(this.peek()))
1011
+ return this.addToken(l.NUMERIC_LITERAL);
1012
+ if (!s && !ke(this.peek()))
1013
+ break;
1014
+ this.advance();
1015
+ }
1016
+ for (; !this.isAtEnd() && (this.check(".") || Ie(this.peek())); )
1017
+ this.advance();
1018
+ const r = this.createToken(l.NUMERIC_LITERAL, !0);
1019
+ this.tokens.push(r), this.errors.push(new w(c.UNKNOWN_TOKEN, "Invalid number", r));
1020
+ }
1021
+ colorLiteral() {
1022
+ for (; !this.isAtEnd() && Ie(this.peek()); )
1023
+ this.advance();
1024
+ this.addToken(l.COLOR_LITERAL);
1025
+ }
1026
+ escapedString() {
1027
+ if (this.isAtEnd())
1028
+ return "\\";
1029
+ switch (this.advance()) {
1030
+ case "t":
1031
+ return " ";
1032
+ case "n":
1033
+ return `
1034
+ `;
1035
+ case "\\":
1036
+ return "\\";
1037
+ case "r":
1038
+ return "\r";
1039
+ case "'":
1040
+ return "'";
1041
+ case '"':
1042
+ return '"';
1043
+ case "0":
1044
+ return "\0";
1045
+ case "b":
1046
+ return "\b";
1047
+ case "v":
1048
+ return "\v";
1049
+ case "f":
1050
+ return "\f";
1051
+ case "u": {
1052
+ let t = "";
1053
+ for (let r = 0; r <= 3; r += 1) {
1054
+ if (this.isAtEnd() || !Ie(this.peek()))
1055
+ return `\\u${t}`;
1056
+ t += this.advance();
1057
+ }
1058
+ return String.fromCharCode(parseInt(t, 16));
1059
+ }
1060
+ default:
1061
+ return `\\${this.tokens[this.current.offset - 1]}`;
1062
+ }
1063
+ }
1064
+ }
1065
+ var ye = /* @__PURE__ */ ((e) => (e[e.ListExpression = 0] = "ListExpression", e[e.GroupExpression = 1] = "GroupExpression", e[e.BlockExpression = 2] = "BlockExpression", e))(ye || {});
1066
+ class wr {
1067
+ constructor() {
1068
+ this.stack = [], this.numberOfNestedLParens = 0, this.numberOfNestedLBrackets = 0, this.numberOfNestedLBraces = 0;
1069
+ }
1070
+ push(t) {
1071
+ this.stack.push(t), t === 0 && (this.numberOfNestedLBrackets += 1), t === 1 && (this.numberOfNestedLParens += 1), t === 2 && (this.numberOfNestedLBraces += 1);
1072
+ }
1073
+ pop() {
1074
+ const t = this.stack.pop();
1075
+ return t === 0 && (this.numberOfNestedLBrackets -= 1), t === 1 && (this.numberOfNestedLParens -= 1), t === 2 && (this.numberOfNestedLBraces -= 1), t;
1076
+ }
1077
+ top() {
1078
+ return C.last(this.stack);
1079
+ }
1080
+ isWithinGroupExpressionContext() {
1081
+ return this.numberOfNestedLParens > 0;
1082
+ }
1083
+ isWithinListExpressionContext() {
1084
+ return this.numberOfNestedLBrackets > 0;
1085
+ }
1086
+ isWithinBlockExpressionContext() {
1087
+ return this.numberOfNestedLBraces > 0;
1088
+ }
1089
+ // Call the passed in callback
1090
+ // with the guarantee that the passed in context will be pushed and popped properly
1091
+ // even in cases of exceptions
1092
+ withContextDo(t, r) {
1093
+ return () => {
1094
+ this.push(t);
1095
+ try {
1096
+ return r();
1097
+ } finally {
1098
+ this.pop();
1099
+ }
1100
+ };
1101
+ }
1102
+ // Return the type of the handler context currently in the context stack to handle `token`
1103
+ findHandlerContext(t, r) {
1104
+ if (!(this.numberOfNestedLBraces <= 0 && this.numberOfNestedLBrackets <= 0 && this.numberOfNestedLParens <= 0))
1105
+ for (let s = r; s < t.length - 1; s += 1)
1106
+ switch (t[s].kind) {
1107
+ case l.COMMA:
1108
+ if (this.isWithinGroupExpressionContext() || this.isWithinListExpressionContext())
1109
+ return [...this.stack].reverse().find(
1110
+ (i) => [
1111
+ 1,
1112
+ 0
1113
+ /* ListExpression */
1114
+ ].includes(i)
1115
+ );
1116
+ break;
1117
+ case l.RPAREN:
1118
+ if (this.isWithinGroupExpressionContext())
1119
+ return 1;
1120
+ break;
1121
+ case l.RBRACE:
1122
+ if (this.isWithinBlockExpressionContext())
1123
+ return 2;
1124
+ break;
1125
+ case l.RBRACKET:
1126
+ if (this.isWithinListExpressionContext())
1127
+ return 0;
1128
+ break;
1129
+ }
1130
+ }
1131
+ }
1132
+ class Ar {
1133
+ constructor(t) {
1134
+ this.generator = t;
1135
+ }
1136
+ create(t, r) {
1137
+ return new t(r, this.generator.nextId());
1138
+ }
1139
+ }
1140
+ class d {
1141
+ constructor(t, r, s) {
1142
+ this.token = t, this.partialNode = r, this.handlerContext = s;
1143
+ }
1144
+ }
1145
+ class xr {
1146
+ constructor(t, r) {
1147
+ this.current = 0, this.errors = [], this.contextStack = new wr(), this.synchronizeProgram = () => {
1148
+ const s = this.peek();
1149
+ s.kind !== l.EOF ? E(this.advance()) : (E(this.peek()), this.logError(s, c.UNEXPECTED_EOF, "Unexpected EOF"));
1150
+ }, this.synchronizeElementDeclarationName = () => {
1151
+ for (; !this.isAtEnd(); ) {
1152
+ const s = this.peek();
1153
+ if (ht(s) || this.check(l.COLON, l.LBRACE, l.LBRACKET))
1154
+ break;
1155
+ E(s), this.advance();
1156
+ }
1157
+ }, this.synchronizeElementDeclarationAlias = () => {
1158
+ for (; !this.isAtEnd(); ) {
1159
+ const s = this.peek();
1160
+ if (this.check(l.COLON, l.LBRACE, l.LBRACKET))
1161
+ break;
1162
+ E(s), this.advance();
1163
+ }
1164
+ }, this.blockExpression = this.contextStack.withContextDo(ye.BlockExpression, () => {
1165
+ const s = { body: [] }, n = () => this.nodeFactory.create(j, s);
1166
+ try {
1167
+ this.consume("Expect an opening brace '{'", l.LBRACE), s.blockOpenBrace = this.previous();
1168
+ } catch (i) {
1169
+ if (!(i instanceof d))
1170
+ throw i;
1171
+ if (s.blockOpenBrace = i.partialNode, !this.canHandle(i))
1172
+ throw new d(i.token, n(), i.handlerContext);
1173
+ this.synchronizeBlock();
1174
+ }
1175
+ for (; !this.isAtEnd() && !this.check(l.RBRACE); )
1176
+ try {
1177
+ s.body.push(this.canBeField() ? this.fieldDeclaration() : this.expression());
1178
+ } catch (i) {
1179
+ if (!(i instanceof d))
1180
+ throw i;
1181
+ if (s.body.push(i.partialNode), !this.canHandle(i))
1182
+ throw new d(i.token, n(), i.handlerContext);
1183
+ this.synchronizeBlock();
1184
+ }
1185
+ try {
1186
+ this.consume("Expect a closing brace '}'", l.RBRACE), s.blockCloseBrace = this.previous();
1187
+ } catch (i) {
1188
+ if (!(i instanceof d))
1189
+ throw i;
1190
+ if (s.blockCloseBrace = i.partialNode, !this.canHandle(i))
1191
+ throw new d(i.token, n(), i.handlerContext);
1192
+ this.synchronizeBlock();
1193
+ }
1194
+ return n();
1195
+ }), this.synchronizeBlock = () => {
1196
+ if (!this.check(l.RBRACE))
1197
+ for (E(this.advance()); !this.isAtEnd(); ) {
1198
+ const s = this.peek();
1199
+ if (this.check(l.RBRACE) || lt(this.previous(), s))
1200
+ break;
1201
+ E(s), this.advance();
1202
+ }
1203
+ }, this.tupleExpression = this.contextStack.withContextDo(ye.GroupExpression, () => {
1204
+ const s = { elementList: [], commaList: [] }, n = () => this.nodeFactory.create(qe, {
1205
+ groupOpenParen: s.tupleOpenParen,
1206
+ groupCloseParen: s.tupleCloseParen,
1207
+ expression: s.elementList[0]
1208
+ }), i = () => this.nodeFactory.create(Q, s);
1209
+ try {
1210
+ this.consume("Expect an opening parenthesis '('", l.LPAREN), s.tupleOpenParen = this.previous();
1211
+ } catch (a) {
1212
+ if (!(a instanceof d))
1213
+ throw a;
1214
+ if (s.tupleOpenParen = a.partialNode, !this.canHandle(a))
1215
+ throw new d(a.token, i(), a.handlerContext);
1216
+ this.synchronizeTuple();
1217
+ }
1218
+ if (!this.isAtEnd() && !this.check(l.RPAREN))
1219
+ try {
1220
+ s.elementList.push(this.normalExpression());
1221
+ } catch (a) {
1222
+ if (!(a instanceof d))
1223
+ throw a;
1224
+ if (s.elementList.push(a.partialNode), !this.canHandle(a))
1225
+ throw new d(a.token, n(), a.handlerContext);
1226
+ this.synchronizeTuple();
1227
+ }
1228
+ for (; !this.isAtEnd() && !this.check(l.RPAREN); )
1229
+ try {
1230
+ this.consume("Expect a comma ','", l.COMMA), s.commaList.push(this.previous()), s.elementList.push(this.normalExpression());
1231
+ } catch (a) {
1232
+ if (!(a instanceof d))
1233
+ throw a;
1234
+ if (a.partialNode instanceof O && s.elementList.push(a.partialNode), !this.canHandle(a))
1235
+ throw new d(a.token, i(), a.handlerContext);
1236
+ this.synchronizeTuple();
1237
+ }
1238
+ try {
1239
+ this.consume("Expect a closing parenthesis ')'", l.RPAREN), s.tupleCloseParen = this.previous();
1240
+ } catch (a) {
1241
+ if (!(a instanceof d))
1242
+ throw a;
1243
+ if (s.tupleCloseParen = a.partialNode, !this.canHandle(a))
1244
+ throw new d(a.token, i(), a.handlerContext);
1245
+ this.synchronizeTuple();
1246
+ }
1247
+ return s.elementList.length === 1 ? n() : i();
1248
+ }), this.synchronizeTuple = () => {
1249
+ for (; !this.isAtEnd(); ) {
1250
+ const s = this.peek();
1251
+ if (this.check(l.RPAREN, l.COMMA))
1252
+ break;
1253
+ E(s), this.advance();
1254
+ }
1255
+ }, this.listExpression = this.contextStack.withContextDo(ye.ListExpression, () => {
1256
+ const s = { elementList: [], commaList: [] }, n = () => this.nodeFactory.create(U, s);
1257
+ try {
1258
+ this.consume("Expect an opening bracket '['", l.LBRACKET), s.listOpenBracket = this.previous();
1259
+ } catch (i) {
1260
+ if (!(i instanceof d))
1261
+ throw i;
1262
+ if (s.listOpenBracket = i.partialNode, !this.canHandle(i))
1263
+ throw new d(i.token, n(), i.handlerContext);
1264
+ this.synchronizeList();
1265
+ }
1266
+ if (!this.isAtEnd() && !this.check(l.RBRACKET))
1267
+ try {
1268
+ s.elementList.push(this.attribute());
1269
+ } catch (i) {
1270
+ if (!(i instanceof d))
1271
+ throw i;
1272
+ if (s.elementList.push(i.partialNode), !this.canHandle(i))
1273
+ throw new d(i.token, n(), i.handlerContext);
1274
+ this.synchronizeList();
1275
+ }
1276
+ for (; !this.isAtEnd() && !this.check(l.RBRACKET); )
1277
+ try {
1278
+ this.consume("Expect a comma ','", l.COMMA), s.commaList.push(this.previous()), s.elementList.push(this.attribute());
1279
+ } catch (i) {
1280
+ if (!(i instanceof d))
1281
+ throw i;
1282
+ if (s.elementList.push(i.partialNode), !this.canHandle(i))
1283
+ throw new d(i.token, n(), i.handlerContext);
1284
+ this.synchronizeList();
1285
+ }
1286
+ try {
1287
+ this.consume("Expect a closing bracket ']'", l.RBRACKET), s.listCloseBracket = this.previous();
1288
+ } catch (i) {
1289
+ if (!(i instanceof d))
1290
+ throw i;
1291
+ if (s.listCloseBracket = i.partialNode, !this.canHandle(i))
1292
+ throw new d(i.token, n(), i.handlerContext);
1293
+ this.synchronizeList();
1294
+ }
1295
+ return n();
1296
+ }), this.synchronizeList = () => {
1297
+ for (; !this.isAtEnd(); ) {
1298
+ const s = this.peek();
1299
+ if (this.check(l.COMMA, l.RBRACKET))
1300
+ break;
1301
+ E(s), this.advance();
1302
+ }
1303
+ }, this.synchronizeAttributeName = () => {
1304
+ for (; !this.isAtEnd(); ) {
1305
+ const s = this.peek();
1306
+ if (this.check(l.COMMA, l.RBRACKET, l.COLON))
1307
+ break;
1308
+ E(s), this.advance();
1309
+ }
1310
+ }, this.synchronizeAttributeValue = () => {
1311
+ for (; !this.isAtEnd(); ) {
1312
+ const s = this.peek();
1313
+ if (this.check(l.COMMA, l.RBRACKET))
1314
+ break;
1315
+ E(s), this.advance();
1316
+ }
1317
+ }, this.tokens = t, this.nodeFactory = new Ar(r);
1318
+ }
1319
+ isAtEnd() {
1320
+ return this.current >= this.tokens.length || this.tokens[this.current].kind === l.EOF;
1321
+ }
1322
+ advance() {
1323
+ return this.isAtEnd() ? C.last(this.tokens) : this.tokens[this.current++];
1324
+ }
1325
+ peek(t = 0) {
1326
+ return t + this.current >= this.tokens.length ? C.last(this.tokens) : this.tokens[this.current + t];
1327
+ }
1328
+ match(...t) {
1329
+ const r = this.check(...t);
1330
+ return r && this.advance(), r;
1331
+ }
1332
+ check(...t) {
1333
+ const r = this.peek();
1334
+ return t.includes(r.kind);
1335
+ }
1336
+ previous() {
1337
+ return this.tokens[this.current - 1];
1338
+ }
1339
+ canHandle(t) {
1340
+ return t.handlerContext === void 0 || t.handlerContext === this.contextStack.top();
1341
+ }
1342
+ consume(t, ...r) {
1343
+ if (!this.match(...r))
1344
+ throw this.logError(this.peek(), c.UNEXPECTED_TOKEN, t), new d(
1345
+ this.peek(),
1346
+ void 0,
1347
+ this.contextStack.findHandlerContext(this.tokens, this.current)
1348
+ );
1349
+ }
1350
+ // Discard tokens until one of `kind` is found
1351
+ // If any tokens are discarded, the error message is logged
1352
+ // Return whether the token of one of the listed kinds are eventually reached
1353
+ discardUntil(t, ...r) {
1354
+ if (this.isAtEnd() || !this.check(...r)) {
1355
+ for (E(this.peek()), this.logError(this.advance(), c.UNEXPECTED_TOKEN, t); !this.isAtEnd() && !this.check(...r); )
1356
+ E(this.advance());
1357
+ return !this.isAtEnd();
1358
+ }
1359
+ return !0;
1360
+ }
1361
+ gatherInvalid() {
1362
+ const t = [], r = [];
1363
+ let s, n = 0;
1364
+ for (; n < this.tokens.length && this.tokens[n].isInvalid; n += 1)
1365
+ r.push(this.tokens[n]);
1366
+ for (s = this.tokens[n], s.leadingInvalid = r, t.push(s), n += 1; n < this.tokens.length; n += 1) {
1367
+ const i = this.tokens[n];
1368
+ i.isInvalid ? s.trailingInvalid.push(i) : (s = i, t.push(s));
1369
+ }
1370
+ this.tokens = t;
1371
+ }
1372
+ parse() {
1373
+ const t = this.program(), r = this.advance(), s = this.nodeFactory.create(ae, { body: t, eof: r });
1374
+ return this.gatherInvalid(), new H({ ast: s, tokens: this.tokens }, this.errors);
1375
+ }
1376
+ /* Parsing and synchronizing ProgramNode */
1377
+ program() {
1378
+ const t = [];
1379
+ for (; !this.isAtEnd(); )
1380
+ try {
1381
+ const r = this.elementDeclaration();
1382
+ t.push(r);
1383
+ } catch (r) {
1384
+ if (!(r instanceof d))
1385
+ throw r;
1386
+ t.push(r.partialNode), this.synchronizeProgram();
1387
+ }
1388
+ return t;
1389
+ }
1390
+ /* Parsing and synchronizing top-level ElementDeclarationNode */
1391
+ elementDeclaration() {
1392
+ const t = {}, r = () => this.nodeFactory.create(A, t);
1393
+ try {
1394
+ this.consume("Expect an identifier", l.IDENTIFIER), t.type = this.previous();
1395
+ } catch (s) {
1396
+ throw s instanceof d ? (t.type = s.partialNode, new d(s.token, r(), s.handlerContext)) : s;
1397
+ }
1398
+ if (!this.check(l.COLON, l.LBRACE, l.LBRACKET))
1399
+ try {
1400
+ t.name = this.normalExpression();
1401
+ } catch (s) {
1402
+ if (!(s instanceof d))
1403
+ throw s;
1404
+ if (t.name = s.partialNode, !this.canHandle(s))
1405
+ throw new d(s.token, r(), s.handlerContext);
1406
+ this.synchronizeElementDeclarationName();
1407
+ }
1408
+ if (ht(this.peek()))
1409
+ if (t.as = this.advance(), this.check(l.COLON, l.LBRACE, l.LBRACKET))
1410
+ this.logError(this.peek(), c.UNEXPECTED_TOKEN, "Expect an alias");
1411
+ else
1412
+ try {
1413
+ t.alias = this.normalExpression();
1414
+ } catch (s) {
1415
+ if (!(s instanceof d))
1416
+ throw s;
1417
+ if (t.alias = s.partialNode, !this.canHandle(s))
1418
+ throw new d(s.token, r(), s.handlerContext);
1419
+ this.synchronizeElementDeclarationAlias();
1420
+ }
1421
+ try {
1422
+ t.attributeList = this.check(l.LBRACKET) ? this.listExpression() : void 0;
1423
+ } catch (s) {
1424
+ throw s instanceof d ? (t.attributeList = s.partialNode, new d(s.token, r(), s.handlerContext)) : s;
1425
+ }
1426
+ if (!this.discardUntil(
1427
+ "Expect an opening brace '{' or a colon ':'",
1428
+ l.LBRACE,
1429
+ l.COLON
1430
+ ))
1431
+ return r();
1432
+ try {
1433
+ this.match(l.COLON) ? (t.bodyColon = this.previous(), t.body = this.expression()) : t.body = this.blockExpression();
1434
+ } catch (s) {
1435
+ throw s instanceof d ? (t.body = s.partialNode, new d(s.token, r(), s.handlerContext)) : s;
1436
+ }
1437
+ return this.nodeFactory.create(A, t);
1438
+ }
1439
+ /* Parsing nested element declarations with simple body */
1440
+ // e.g
1441
+ // ```
1442
+ // Table Users {
1443
+ // Note: 'This is a note' // fieldDeclaration() handles this
1444
+ // }
1445
+ fieldDeclaration() {
1446
+ const t = {}, r = () => this.nodeFactory.create(A, t);
1447
+ try {
1448
+ this.consume("Expect an identifier", l.IDENTIFIER), t.type = this.previous();
1449
+ } catch (s) {
1450
+ throw s instanceof d ? (t.type = s.partialNode, new d(s.token, r(), s.handlerContext)) : s;
1451
+ }
1452
+ try {
1453
+ this.consume("Expect a colon ':'", l.COLON), t.bodyColon = this.previous();
1454
+ } catch (s) {
1455
+ throw s instanceof d ? (t.bodyColon = s.partialNode, new d(s.token, r(), s.handlerContext)) : s;
1456
+ }
1457
+ try {
1458
+ t.body = this.expression();
1459
+ } catch (s) {
1460
+ throw s instanceof d ? (t.body = s.partialNode, new d(s.token, r(), s.handlerContext)) : s;
1461
+ }
1462
+ return this.nodeFactory.create(A, t);
1463
+ }
1464
+ /* Parsing any ExpressionNode, including non-NormalExpression */
1465
+ expression() {
1466
+ const t = { args: [] }, r = () => br(t.callee, t.args, this.nodeFactory).unwrap_or(
1467
+ this.nodeFactory.create(te, t)
1468
+ );
1469
+ try {
1470
+ t.callee = this.normalExpression();
1471
+ } catch (n) {
1472
+ throw n instanceof d ? (t.callee = n.partialNode, new d(n.token, r(), n.handlerContext)) : n;
1473
+ }
1474
+ if (this.shouldStopExpression())
1475
+ return r();
1476
+ let s = t.callee;
1477
+ for (; !this.shouldStopExpression(); ) {
1478
+ _t(this.previous()) || this.logError(s, c.MISSING_SPACES, "Expect a following space");
1479
+ try {
1480
+ s = this.normalExpression(), t.args.push(s);
1481
+ } catch (n) {
1482
+ throw n instanceof d ? (s = n.partialNode, t.args.push(s), new d(n.token, r(), n.handlerContext)) : n;
1483
+ }
1484
+ }
1485
+ return r();
1486
+ }
1487
+ shouldStopExpression() {
1488
+ if (this.isAtEnd() || xt(this.previous()))
1489
+ return !0;
1490
+ const t = this.peek().kind;
1491
+ return t === l.RBRACE || t === l.RBRACKET || t === l.RPAREN || t === l.COMMA || t === l.COLON;
1492
+ }
1493
+ normalExpression() {
1494
+ return this.expression_bp(0);
1495
+ }
1496
+ // Pratt's parsing algorithm
1497
+ expression_bp(t) {
1498
+ let r = this.leftExpression_bp();
1499
+ for (; !this.isAtEnd(); ) {
1500
+ const s = this.peek();
1501
+ if (s.kind === l.LPAREN) {
1502
+ const { left: n } = ft(s);
1503
+ if (n < t || // When '(' is encountered,
1504
+ // consider it part of another expression if
1505
+ // it's at the start of a new line
1506
+ // and we're currently not having unmatched '(' or '['
1507
+ lt(this.previous(), s) && !this.contextStack.isWithinGroupExpressionContext() && !this.contextStack.isWithinListExpressionContext())
1508
+ break;
1509
+ try {
1510
+ r = this.nodeFactory.create(oe, {
1511
+ callee: r,
1512
+ argumentList: this.tupleExpression()
1513
+ });
1514
+ } catch (i) {
1515
+ throw i instanceof d ? (r = this.nodeFactory.create(oe, {
1516
+ callee: r,
1517
+ argumentList: i.partialNode
1518
+ }), new d(i.token, r, i.handlerContext)) : i;
1519
+ }
1520
+ } else if (ot(s)) {
1521
+ const n = s, i = ft(n);
1522
+ if (i.left !== null) {
1523
+ if (i.left <= t)
1524
+ break;
1525
+ this.advance(), r = this.nodeFactory.create(Ce, {
1526
+ expression: r,
1527
+ op: n
1528
+ });
1529
+ } else {
1530
+ const a = Or(n);
1531
+ if (a.left === null || a.left <= t)
1532
+ break;
1533
+ this.advance();
1534
+ try {
1535
+ r = this.nodeFactory.create(K, {
1536
+ leftExpression: r,
1537
+ op: n,
1538
+ rightExpression: n.value === "." ? this.extractOperand() : this.expression_bp(a.right)
1539
+ });
1540
+ } catch (o) {
1541
+ throw o instanceof d ? (r = this.nodeFactory.create(K, {
1542
+ leftExpression: r,
1543
+ op: n,
1544
+ rightExpression: o.partialNode
1545
+ }), new d(o.token, r, o.handlerContext)) : o;
1546
+ }
1547
+ }
1548
+ } else
1549
+ break;
1550
+ }
1551
+ return r;
1552
+ }
1553
+ leftExpression_bp() {
1554
+ let t;
1555
+ if (ot(this.peek())) {
1556
+ const r = {};
1557
+ r.op = this.peek();
1558
+ const s = yr(r.op);
1559
+ s.right === null && (this.logError(
1560
+ r.op,
1561
+ c.UNKNOWN_PREFIX_OP,
1562
+ `Unexpected '${r.op.value}' in an expression`
1563
+ ), this.throwDummyOperand(r.op)), this.advance();
1564
+ try {
1565
+ r.expression = this.expression_bp(s.right);
1566
+ } catch (n) {
1567
+ throw n instanceof d ? (r.expression = n.partialNode, new d(
1568
+ n.token,
1569
+ this.nodeFactory.create(z, r),
1570
+ n.handlerContext
1571
+ )) : n;
1572
+ }
1573
+ t = this.nodeFactory.create(z, r);
1574
+ } else
1575
+ t = this.extractOperand(), Mt(t) && this.throwDummyOperand(this.peek());
1576
+ return t;
1577
+ }
1578
+ // Extract an operand to be used in a normal form expression
1579
+ // e.g (1 + 2) in (1 + 2) * 3
1580
+ // e.g [1, 2, 3, 4]
1581
+ // e.g { ... }
1582
+ extractOperand() {
1583
+ return this.check(
1584
+ l.NUMERIC_LITERAL,
1585
+ l.STRING_LITERAL,
1586
+ l.COLOR_LITERAL,
1587
+ l.QUOTED_STRING,
1588
+ l.IDENTIFIER
1589
+ ) ? this.primaryExpression() : this.check(l.FUNCTION_EXPRESSION) ? this.functionExpression() : this.check(l.LBRACKET) ? this.listExpression() : this.check(l.LBRACE) ? this.blockExpression() : this.check(l.LPAREN) ? this.tupleExpression() : (this.peek().kind === l.EOF ? this.logError(
1590
+ this.peek(),
1591
+ c.UNEXPECTED_EOF,
1592
+ "Unexpected EOF"
1593
+ ) : this.logError(
1594
+ this.peek(),
1595
+ c.INVALID_OPERAND,
1596
+ `Invalid start of operand "${this.peek().value}"`
1597
+ ), dt(this.nodeFactory));
1598
+ }
1599
+ throwDummyOperand(t) {
1600
+ throw new d(
1601
+ t,
1602
+ dt(this.nodeFactory),
1603
+ this.contextStack.findHandlerContext(this.tokens, this.current)
1604
+ );
1605
+ }
1606
+ /* Parsing FunctionExpression */
1607
+ functionExpression() {
1608
+ const t = {};
1609
+ try {
1610
+ this.consume("Expect a function expression", l.FUNCTION_EXPRESSION), t.value = this.previous();
1611
+ } catch (r) {
1612
+ throw r instanceof d ? (t.value = r.partialNode, new d(
1613
+ r.token,
1614
+ this.nodeFactory.create(B, t),
1615
+ r.handlerContext
1616
+ )) : r;
1617
+ }
1618
+ return this.nodeFactory.create(B, t);
1619
+ }
1620
+ canBeField() {
1621
+ return this.peek().kind === l.IDENTIFIER && this.peek(1).kind === l.COLON;
1622
+ }
1623
+ /* Parsing PrimaryExpression */
1624
+ primaryExpression() {
1625
+ if (this.match(
1626
+ l.COLOR_LITERAL,
1627
+ l.STRING_LITERAL,
1628
+ l.NUMERIC_LITERAL
1629
+ ))
1630
+ return this.nodeFactory.create(S, {
1631
+ expression: this.nodeFactory.create(ue, { literal: this.previous() })
1632
+ });
1633
+ if (this.match(l.QUOTED_STRING, l.IDENTIFIER))
1634
+ return this.nodeFactory.create(S, {
1635
+ expression: this.nodeFactory.create(M, { variable: this.previous() })
1636
+ });
1637
+ throw this.logError(this.peek(), c.UNEXPECTED_TOKEN, "Expect a variable or literal"), new d(
1638
+ this.peek(),
1639
+ this.nodeFactory.create(S, {
1640
+ expression: this.nodeFactory.create(M, {})
1641
+ }),
1642
+ this.contextStack.findHandlerContext(this.tokens, this.current)
1643
+ );
1644
+ }
1645
+ attribute() {
1646
+ const t = {};
1647
+ if (this.check(l.COLON, l.RBRACKET, l.COMMA)) {
1648
+ const r = this.peek();
1649
+ this.logError(
1650
+ r,
1651
+ c.EMPTY_ATTRIBUTE_NAME,
1652
+ "Expect a non-empty attribute name"
1653
+ ), t.name = this.nodeFactory.create(q, { identifiers: [] });
1654
+ } else
1655
+ try {
1656
+ t.name = this.extractIdentifierStream();
1657
+ } catch (r) {
1658
+ if (!(r instanceof d))
1659
+ throw r;
1660
+ if (t.name = r.partialNode, !this.canHandle(r))
1661
+ throw new d(
1662
+ r.token,
1663
+ this.nodeFactory.create(xe, t),
1664
+ r.handlerContext
1665
+ );
1666
+ this.synchronizeAttributeName();
1667
+ }
1668
+ return this.match(l.COLON) && (t.colon = this.previous(), t.value = this.attributeValue()), this.nodeFactory.create(xe, t);
1669
+ }
1670
+ attributeValue() {
1671
+ let t;
1672
+ try {
1673
+ t = this.peek().kind === l.IDENTIFIER && this.peek(1).kind === l.IDENTIFIER ? this.extractIdentifierStream() : this.normalExpression();
1674
+ } catch (r) {
1675
+ if (!(r instanceof d) || !this.canHandle(r))
1676
+ throw r;
1677
+ t = r.partialNode, this.synchronizeAttributeValue();
1678
+ }
1679
+ return t;
1680
+ }
1681
+ extractIdentifierStream() {
1682
+ const t = [];
1683
+ for (; !this.isAtEnd() && !this.check(l.COLON, l.COMMA, l.RBRACKET); )
1684
+ if (this.match(
1685
+ l.QUOTED_STRING,
1686
+ l.STRING_LITERAL,
1687
+ l.NUMERIC_LITERAL
1688
+ ))
1689
+ E(this.previous()), this.logError(this.previous(), c.UNEXPECTED_TOKEN, "Expect an identifier");
1690
+ else
1691
+ try {
1692
+ this.consume("Expect an identifier", l.IDENTIFIER), t.push(this.previous());
1693
+ } catch (r) {
1694
+ throw r instanceof d ? new d(
1695
+ r.token,
1696
+ this.nodeFactory.create(q, { identifiers: t }),
1697
+ r.handlerContext
1698
+ ) : r;
1699
+ }
1700
+ return this.nodeFactory.create(q, { identifiers: t });
1701
+ }
1702
+ logError(t, r, s) {
1703
+ this.errors.push(new w(r, s, t));
1704
+ }
1705
+ }
1706
+ const _r = {
1707
+ "+": { left: 9, right: 10 },
1708
+ "*": { left: 11, right: 12 },
1709
+ "-": { left: 9, right: 10 },
1710
+ "/": { left: 11, right: 12 },
1711
+ "%": { left: 11, right: 12 },
1712
+ "<": { left: 7, right: 8 },
1713
+ "<=": { left: 7, right: 8 },
1714
+ ">": { left: 7, right: 8 },
1715
+ ">=": { left: 7, right: 8 },
1716
+ "<>": { left: 7, right: 8 },
1717
+ "=": { left: 2, right: 3 },
1718
+ "==": { left: 4, right: 5 },
1719
+ "!=": { left: 4, right: 5 },
1720
+ ".": { left: 16, right: 17 }
1721
+ };
1722
+ function Or(e) {
1723
+ return _r[e.value] || { left: null, right: null };
1724
+ }
1725
+ const vr = {
1726
+ "+": { left: null, right: 15 },
1727
+ "-": { left: null, right: 15 },
1728
+ "<": { left: null, right: 15 },
1729
+ ">": { left: null, right: 15 },
1730
+ "<>": { left: null, right: 15 },
1731
+ "!": { left: null, right: 15 }
1732
+ };
1733
+ function yr(e) {
1734
+ return vr[e.value] || { left: null, right: null };
1735
+ }
1736
+ const kr = {
1737
+ "(": { left: 14, right: null }
1738
+ };
1739
+ function ft(e) {
1740
+ return kr[e.value] || { left: null, right: null };
1741
+ }
1742
+ function Ee(e) {
1743
+ if (!Pe(e))
1744
+ return new I([e]);
1745
+ const t = Ee(e.leftExpression).unwrap_or(void 0);
1746
+ return t ? (t.push(e.rightExpression), new I(t)) : new T();
1747
+ }
1748
+ function pe(e) {
1749
+ if (e === void 0)
1750
+ return new T();
1751
+ const t = Ee(e).unwrap_or(void 0);
1752
+ if (!t)
1753
+ return new T();
1754
+ const r = [];
1755
+ for (const s of t) {
1756
+ const n = Je(s).unwrap_or(void 0);
1757
+ if (!n)
1758
+ return new T();
1759
+ r.push(n);
1760
+ }
1761
+ return new I(r);
1762
+ }
1763
+ function Ge(e) {
1764
+ if (e === void 0)
1765
+ return new T();
1766
+ const t = Ee(e).unwrap_or(void 0);
1767
+ if (!t || t.length === 0)
1768
+ return new T();
1769
+ const r = [];
1770
+ let s;
1771
+ if (!Y(C.last(t))) {
1772
+ const n = t.pop();
1773
+ if (jt(n))
1774
+ s = n.elementList.map(
1775
+ (i) => W(i).unwrap()
1776
+ );
1777
+ else
1778
+ return new T();
1779
+ }
1780
+ for (const n of t) {
1781
+ const i = Je(n).unwrap_or(void 0);
1782
+ if (!i)
1783
+ return new T();
1784
+ r.push(i);
1785
+ }
1786
+ return new I({
1787
+ variables: r,
1788
+ tupleElements: s
1789
+ });
1790
+ }
1791
+ function Je(e) {
1792
+ return Y(e) ? new I(e.expression.variable.value) : new T();
1793
+ }
1794
+ function Pt(e) {
1795
+ if (Et(e))
1796
+ return e instanceof B ? new I({ functional: [e], nonFunctional: [] }) : new I({ functional: [], nonFunctional: [e] });
1797
+ if (e instanceof Q && e.elementList.every(Et)) {
1798
+ const t = e.elementList.filter(
1799
+ (s) => s instanceof B
1800
+ ), r = e.elementList.filter(Y);
1801
+ return new I({ functional: t, nonFunctional: r });
1802
+ }
1803
+ return new T();
1804
+ }
1805
+ function W(e) {
1806
+ var r;
1807
+ const t = (r = e.expression.variable) == null ? void 0 : r.value;
1808
+ return t === void 0 ? new T() : new I(t);
1809
+ }
1810
+ function fe(e) {
1811
+ return J(e) ? e.expression instanceof M ? new I(e.expression.variable.value) : new I(e.expression.literal.value) : new T();
1812
+ }
1813
+ function Sr(e) {
1814
+ var t;
1815
+ return !(e instanceof K) || !qt((t = e.op) == null ? void 0 : t.value) ? !1 : Ge(e.leftExpression).and_then(() => Ge(e.rightExpression)).unwrap_or(void 0) !== void 0;
1816
+ }
1817
+ function Et(e) {
1818
+ return e instanceof S && e.expression instanceof M || e instanceof B;
1819
+ }
1820
+ function Rr(e, t) {
1821
+ var n, i, a, o;
1822
+ let r = t;
1823
+ const s = nr(e);
1824
+ for (; r; ) {
1825
+ if ((i = (n = r.symbol) == null ? void 0 : n.symbolTable) != null && i.has(e))
1826
+ return (a = r.symbol.symbolTable) == null ? void 0 : a.get(e);
1827
+ if (((o = r.symbol) == null ? void 0 : o.declaration) instanceof ae && s)
1828
+ return r.symbol;
1829
+ if (r instanceof ae)
1830
+ return;
1831
+ r = r.parent;
1832
+ }
1833
+ }
1834
+ var m = /* @__PURE__ */ ((e) => (e.TABLE = "Table", e.ENUM = "Enum", e.INDEXES = "Indexes", e.NOTE = "Note", e.PROJECT = "Project", e.REF = "Ref", e.TABLEGROUP = "TableGroup", e.CUSTOM = "custom element", e))(m || {});
1835
+ function Ze(e) {
1836
+ if (e.globally && !e.notGloballyErrorCode)
1837
+ throw new Error(
1838
+ "Misconfigurartion: If an element is globally unique, notGloballyErrorCode must be set"
1839
+ );
1840
+ if (e.locally && !e.notLocallyErrorCode)
1841
+ throw new Error(
1842
+ "Misconfigurartion: If an element is locally unique, notLocallyErrorCode must be set"
1843
+ );
1844
+ return e;
1845
+ }
1846
+ function et(e) {
1847
+ if (!e.optional && !e.notOptionalErrorCode)
1848
+ throw new Error(
1849
+ "Misconfiguration: If name is not optional, notOptionalErrorCode must be present"
1850
+ );
1851
+ if (!e.allow && !e.notAllowErrorCode)
1852
+ throw new Error("Misconfiguration: If name is not allowed, notAllowErrorCode must be present");
1853
+ if (e.shouldRegister && !e.duplicateErrorCode)
1854
+ throw new Error(
1855
+ "Misconfiguration: If name should be registered, duplicateErrorCode must be present"
1856
+ );
1857
+ return e;
1858
+ }
1859
+ function Ut(e) {
1860
+ if (!e.optional && !e.notOptionalErrorCode)
1861
+ throw new Error(
1862
+ "Misconfiguration: If alias is not optional, notOptionalErrorCode must be present"
1863
+ );
1864
+ if (!e.allow && !e.notAllowErrorCode)
1865
+ throw new Error("Misconfiguration: If alias is not allowed, notAllowErrorCode must be present");
1866
+ return e;
1867
+ }
1868
+ function Ne(e, t) {
1869
+ if (!t.optional && !t.notOptionalErrorCode)
1870
+ throw new Error(
1871
+ "Misconfiguration: If settingList is not optional, notOptionalErrorCode must be present"
1872
+ );
1873
+ if (!t.allow && !t.notAllowErrorCode)
1874
+ throw new Error(
1875
+ "Misconfiguration: If settingList is not allowed, notAllowErrorCode must be present"
1876
+ );
1877
+ if (t.allow && !t.unknownErrorCode)
1878
+ throw new Error(
1879
+ "Misconfiguration: If settingList is allowed, unknownErrorCode must be present"
1880
+ );
1881
+ if (t.allow && !t.duplicateErrorCode)
1882
+ throw new Error(
1883
+ "Misconfiguration: If settingList is allowed, duplicateErrorCode must be present"
1884
+ );
1885
+ if (t.allow && !t.invalidErrorCode)
1886
+ throw new Error(
1887
+ "Misconfiguration: If settingList is allowed, notAllowErrorCode must be present"
1888
+ );
1889
+ return {
1890
+ ...t,
1891
+ isValid(r, s) {
1892
+ const n = e[r];
1893
+ return n ? new I(n.isValid(s)) : new T();
1894
+ },
1895
+ allowDuplicate(r) {
1896
+ const s = e[r];
1897
+ return s ? new I(s.allowDuplicate) : new T();
1898
+ }
1899
+ };
1900
+ }
1901
+ function tt(e) {
1902
+ if (!e.allowSimple && !e.simpleErrorCode)
1903
+ throw new Error("Misconfiguration: If simple body is not allowed, simpleErrorCode must be set");
1904
+ if (!e.allowComplex && !e.complexErrorCode)
1905
+ throw new Error(
1906
+ "Misconfiguration: If complex body is not allowed, complexErrorCode must be set"
1907
+ );
1908
+ return e;
1909
+ }
1910
+ function re(e) {
1911
+ if (e.shouldRegister && !e.duplicateErrorCode)
1912
+ throw new Error(
1913
+ "Misconfiguration: If subfield should be registered, duplicateErrorCode must be present"
1914
+ );
1915
+ return e;
1916
+ }
1917
+ function Dr(e) {
1918
+ return e === m.CUSTOM;
1919
+ }
1920
+ function Ve(e) {
1921
+ switch (e) {
1922
+ case m.TABLE:
1923
+ return "column";
1924
+ case m.ENUM:
1925
+ return "field";
1926
+ case m.TABLEGROUP:
1927
+ return "table";
1928
+ default:
1929
+ return "subfield";
1930
+ }
1931
+ }
1932
+ function ce(e, t, r) {
1933
+ return (s, n) => e(s, n) ? [] : [new w(t, r, s)];
1934
+ }
1935
+ class se {
1936
+ constructor(t, r, s, n, i, a, o) {
1937
+ this.declarationNode = t, this.publicSchemaSymbol = r, this.contextStack = s, this.errors = n, this.kindsGloballyFound = i, this.kindsLocallyFound = a, this.symbolFactory = o;
1938
+ }
1939
+ validate() {
1940
+ this.contextStack.push(this.context.name);
1941
+ const t = this.validateContext() && this.validateUnique() && this.validateName() && this.validateAlias() && this.validateSettingList() && this.validateBodyForm() && this.validateBodyContent();
1942
+ return this.contextStack.pop(), t;
1943
+ }
1944
+ /* Validate uniqueness according to config `this.unique` */
1945
+ validateUnique() {
1946
+ return this.validateGloballyUnique() && this.validateLocallyUnique() || !this.unique.stopOnError;
1947
+ }
1948
+ validateLocallyUnique() {
1949
+ return this.unique.locally ? this.kindsLocallyFound.has(this.elementKind) ? (this.logError(
1950
+ this.declarationNode.type,
1951
+ this.unique.notLocallyErrorCode,
1952
+ `A(n) ${this.elementKind} has already been defined in this scope`
1953
+ ), !1) : (this.kindsLocallyFound.add(this.elementKind), !0) : !0;
1954
+ }
1955
+ validateGloballyUnique() {
1956
+ return this.unique.globally ? this.kindsGloballyFound.has(this.elementKind) ? (this.logError(
1957
+ this.declarationNode.type,
1958
+ this.unique.notGloballyErrorCode,
1959
+ `A(n) ${this.elementKind} has already been defined in this file`
1960
+ ), !1) : (this.kindsGloballyFound.add(this.elementKind), !0) : !0;
1961
+ }
1962
+ /* Validate context according to config `this.context` */
1963
+ validateContext() {
1964
+ return ir(this.contextStack.parent(), this.contextStack.top()) ? !0 : (this.logError(
1965
+ this.declarationNode.type,
1966
+ this.context.errorCode,
1967
+ Dr(this.elementKind) ? "Unknown element type" : `A(n) ${this.elementKind} can not appear here`
1968
+ ), !this.context.stopOnError);
1969
+ }
1970
+ /* Validate and register name according to config `this.name` */
1971
+ validateName() {
1972
+ return this.declarationNode.symbol = ct(
1973
+ this.declarationNode,
1974
+ this.context.name,
1975
+ this.symbolFactory
1976
+ ), this.checkNameInValidForm() && this.checkNameAllowed() && this.checkNameOptional() && this.checkNameComplex() && // Short-circuting prevents registerName to be called if a previous check fails
1977
+ this.registerName() || !this.name.stopOnError;
1978
+ }
1979
+ checkNameInValidForm() {
1980
+ const { name: t } = this.declarationNode;
1981
+ return t && Mt(t) ? !1 : t && !Wt(t) ? (this.logError(t, c.INVALID_NAME, "Invalid element name"), !1) : !0;
1982
+ }
1983
+ checkNameAllowed() {
1984
+ return !this.name.allow && this.declarationNode.name ? (this.logError(
1985
+ this.declarationNode.name,
1986
+ this.name.notAllowErrorCode,
1987
+ `A(n) ${this.elementKind} shouldn't have a name`
1988
+ ), !1) : !0;
1989
+ }
1990
+ checkNameOptional() {
1991
+ return !this.name.optional && !this.declarationNode.name ? (this.logError(
1992
+ this.declarationNode.type,
1993
+ this.name.notOptionalErrorCode,
1994
+ `A(n) ${this.elementKind} must have a name`
1995
+ ), !1) : !0;
1996
+ }
1997
+ checkNameComplex() {
1998
+ const { name: t } = this.declarationNode;
1999
+ return !this.name.allowComplex && t && !Xe(t) ? (this.logError(
2000
+ t,
2001
+ this.name.complexErrorCode,
2002
+ `A(n) ${this.elementKind} must have a double-quoted string or an identifier name`
2003
+ ), !1) : !0;
2004
+ }
2005
+ registerName() {
2006
+ if (this.declarationNode.name && this.name.shouldRegister) {
2007
+ const { registeredSymbol: t, ok: r } = this.registerElement(this.declarationNode.name);
2008
+ return this.declarationNode.symbol = t, r;
2009
+ }
2010
+ return !0;
2011
+ }
2012
+ /* Validate and register alias according to config `this.alias` */
2013
+ validateAlias() {
2014
+ return this.checkAliasInValidForm() && this.checkAliasAllow() && this.checkAliasOptional() && // Short-circuting prevents registerAlias to be called if a previous check fails
2015
+ this.registerAlias() || !this.alias.stopOnError;
2016
+ }
2017
+ checkAliasInValidForm() {
2018
+ const { alias: t } = this.declarationNode;
2019
+ return t && !Jr(t) ? (this.logError(t, c.INVALID_ALIAS, "Invalid element alias"), !1) : !0;
2020
+ }
2021
+ checkAliasAllow() {
2022
+ const { alias: t } = this.declarationNode;
2023
+ return !this.alias.allow && t ? (this.logError(
2024
+ t,
2025
+ this.alias.notAllowErrorCode,
2026
+ `A(n) ${this.elementKind} shouldn't have an alias`
2027
+ ), !1) : !0;
2028
+ }
2029
+ checkAliasOptional() {
2030
+ const { alias: t } = this.declarationNode;
2031
+ return !this.alias.optional && !t ? (this.logError(
2032
+ this.declarationNode.type,
2033
+ this.alias.notOptionalErrorCode,
2034
+ `A(n) ${this.elementKind} must have an alias`
2035
+ ), !1) : !0;
2036
+ }
2037
+ registerAlias() {
2038
+ const { alias: t } = this.declarationNode;
2039
+ if (t && this.name.shouldRegister) {
2040
+ const { ok: r } = this.registerElement(t, this.declarationNode.symbol);
2041
+ return r;
2042
+ }
2043
+ return !0;
2044
+ }
2045
+ // Register a name extracted from `nameNode` into the `public` schema
2046
+ // Also check for duplicated name
2047
+ // If `defaultSymbol` is undefined, create the symbol anew corresponding to the name
2048
+ // If `defaultSymbol` is given, the symbol (and its symbol table) is reused
2049
+ registerElement(t, r) {
2050
+ const s = pe(t).unwrap_or(void 0);
2051
+ if (!s)
2052
+ throw new Error(`${this.elementKind} must be a valid complex variable`);
2053
+ const n = s.pop();
2054
+ if (!n)
2055
+ throw new Error(`${this.elementKind} name shouldn't be empty`);
2056
+ const i = dr(n, this.context.name);
2057
+ s[0] === "public" && s.shift();
2058
+ const a = ts(
2059
+ s,
2060
+ this.publicSchemaSymbol.symbolTable,
2061
+ this.symbolFactory
2062
+ );
2063
+ if (!i)
2064
+ throw new Error(`${this.elementKind} fails to create id to register in the symbol table`);
2065
+ const o = ct(
2066
+ this.declarationNode,
2067
+ this.context.name,
2068
+ this.symbolFactory
2069
+ );
2070
+ if (!o)
2071
+ throw new Error(
2072
+ `${this.elementKind} fails to create a symbol to register in the symbol table`
2073
+ );
2074
+ return a.has(i) ? (this.logError(
2075
+ t,
2076
+ this.name.duplicateErrorCode,
2077
+ `${this.elementKind} "${n}" has been defined`
2078
+ ), { registeredSymbol: r || o, ok: !1 }) : (a.set(i, r || o), { registeredSymbol: r || o, ok: !0 });
2079
+ }
2080
+ /* Validate element according to config `this.settingList` */
2081
+ validateSettingList() {
2082
+ return this.checkSettingListInValidForm() && this.checkSettingListAllow() && this.checkSettingListOptional() && (!this.declarationNode.attributeList || this.validateSettingListContent(this.declarationNode.attributeList, this.settingList)) || !this.settingList.stopOnError;
2083
+ }
2084
+ checkSettingListInValidForm() {
2085
+ const { attributeList: t } = this.declarationNode;
2086
+ return t && !Zr(t) ? (this.logError(t, c.INVALID_SETTINGS, "SettingList must be a list"), !1) : !0;
2087
+ }
2088
+ checkSettingListAllow() {
2089
+ const { attributeList: t } = this.declarationNode;
2090
+ return !this.settingList.allow && t ? (this.logError(
2091
+ t,
2092
+ this.settingList.notAllowErrorCode,
2093
+ `A(n) ${this.elementKind} shouldn't have a setting list`
2094
+ ), !1) : !0;
2095
+ }
2096
+ checkSettingListOptional() {
2097
+ const { attributeList: t } = this.declarationNode;
2098
+ return !this.settingList.optional && !t ? (this.logError(
2099
+ this.declarationNode.type,
2100
+ this.settingList.notOptionalErrorCode,
2101
+ `A(n) ${this.elementKind} must have a setting list`
2102
+ ), !1) : !0;
2103
+ }
2104
+ /* Validate body format according to config `this.body` */
2105
+ validateBodyForm() {
2106
+ const t = this.declarationNode;
2107
+ if (!t.body)
2108
+ return !1;
2109
+ let r = !1;
2110
+ return !this.body.allowComplex && Nt(t) && (this.logError(
2111
+ t.body,
2112
+ this.body.complexErrorCode,
2113
+ `A(n) ${this.elementKind} should not have a complex body`
2114
+ ), r = !0), !this.body.allowSimple && es(t) && (this.logError(
2115
+ t.body,
2116
+ this.body.simpleErrorCode,
2117
+ `A(n) ${this.elementKind} should not have a simple body`
2118
+ ), r = !0), !r || !this.body.stopOnError;
2119
+ }
2120
+ /* Validate the body content */
2121
+ validateBodyContent() {
2122
+ const t = this.declarationNode;
2123
+ if (!t.body)
2124
+ return !1;
2125
+ if (Nt(t)) {
2126
+ if (!this.body.allowComplex)
2127
+ return !1;
2128
+ const r = /* @__PURE__ */ new Set();
2129
+ let s = !1, n = -1;
2130
+ return s = !t.body.body.map((i) => i instanceof A ? !i.type || this.validateNestedElementDeclaration(i, r) : (n += 1, !i.callee || this.validateSubField(i, n))).every((i) => !!i) || s, !s;
2131
+ }
2132
+ return t.body instanceof te && t.body.callee ? this.validateSubField(
2133
+ t.body,
2134
+ 0
2135
+ ) : (this.logError(
2136
+ t.body,
2137
+ c.INVALID_ELEMENT_IN_SIMPLE_BODY,
2138
+ "An element's simple body can not contain an element declaration"
2139
+ ), !1);
2140
+ }
2141
+ validateNestedElementDeclaration(t, r) {
2142
+ if (t.parent = this.declarationNode, !t.type)
2143
+ return !1;
2144
+ const s = t, n = $t(s);
2145
+ return new n(
2146
+ s,
2147
+ this.publicSchemaSymbol,
2148
+ this.contextStack,
2149
+ this.errors,
2150
+ this.kindsGloballyFound,
2151
+ r,
2152
+ this.symbolFactory
2153
+ ).validate();
2154
+ }
2155
+ /* Validate and register subfield according to config `this.subfield` */
2156
+ validateSubField(t, r) {
2157
+ const n = [t.callee, ...t.args];
2158
+ if (n.length === 0)
2159
+ throw new Error("A function application node always has at least 1 callee");
2160
+ const i = n[n.length - 1];
2161
+ if (this.validateSubFieldSettingList(i), i instanceof U && n.pop(), n.length !== this.subfield.argValidators.length)
2162
+ return this.logError(
2163
+ t,
2164
+ this.subfield.invalidArgNumberErrorCode,
2165
+ this.subfield.invalidArgNumberErrorMessage
2166
+ ), !1;
2167
+ let a = !1;
2168
+ for (let o = 0; o < n.length; o += 1) {
2169
+ const u = this.subfield.argValidators[o].validateArg(n[o], r);
2170
+ u.length > 0 && (this.errors.push(...u), a = !0);
2171
+ }
2172
+ if (this.subfield.shouldRegister && !a) {
2173
+ const o = this.registerSubField(t, n[0]).unwrap_or(void 0);
2174
+ a = o === void 0 || a, t.symbol = o;
2175
+ }
2176
+ return !a;
2177
+ }
2178
+ registerSubField(t, r) {
2179
+ if (!this.declarationNode.symbol || !this.declarationNode.symbol.symbolTable)
2180
+ throw new Error("If an element allows registering subfields, it must own a symbol table");
2181
+ if (!Xe(r))
2182
+ throw new Error("If an element allows registering subfields, their name must be simple");
2183
+ const s = ve(r).unwrap().value, { symbolTable: n } = this.declarationNode.symbol;
2184
+ if (!s)
2185
+ throw new Error(`${this.elementKind} subfield's name shouldn't be empty`);
2186
+ const i = fr(s, this.context.name);
2187
+ if (!i)
2188
+ throw new Error(
2189
+ `${this.elementKind} fails to create subfield id to register in the symbol table`
2190
+ );
2191
+ if (n.has(i))
2192
+ return this.logError(
2193
+ r,
2194
+ this.subfield.duplicateErrorCode,
2195
+ `${this.elementKind} ${Ve(this.elementKind)} "${s}" has been defined`
2196
+ ), new T();
2197
+ const a = Er(t, this.context.name, this.symbolFactory);
2198
+ if (!a)
2199
+ throw new Error(
2200
+ `${this.elementKind} fails to create subfield symbol to register in the symbol table`
2201
+ );
2202
+ return new I(n.get(i, a));
2203
+ }
2204
+ validateSubFieldSettingList(t) {
2205
+ return !(t instanceof U) && !this.subfield.settingList.optional ? (this.logError(
2206
+ t,
2207
+ this.subfield.settingList.notOptionalErrorCode,
2208
+ `A(n) ${this.elementKind} ${Ve(this.elementKind)} must have a setting list`
2209
+ ), !1) : t instanceof U && !this.subfield.settingList.allow ? (this.logError(
2210
+ t,
2211
+ this.subfield.settingList.notAllowErrorCode,
2212
+ `A(n) ${this.elementKind} ${Ve(
2213
+ this.elementKind
2214
+ )} should not have a setting list`
2215
+ ), !1) : t instanceof U ? this.validateSettingListContent(t, this.subfield.settingList) : !0;
2216
+ }
2217
+ validateSettingListContent(t, r) {
2218
+ var i;
2219
+ const s = /* @__PURE__ */ new Set();
2220
+ let n = !1;
2221
+ for (const a of t.elementList) {
2222
+ const o = (i = le(a.name).unwrap_or(void 0)) == null ? void 0 : i.toLowerCase(), { value: u } = a;
2223
+ o !== void 0 && (r.isValid(o, u).isOk() ? s.has(o) && !r.allowDuplicate(o).unwrap() ? (this.logError(a, r.duplicateErrorCode, "Duplicate setting"), n = !0) : (s.add(o), r.isValid(o, u).unwrap() || (this.logError(a, r.invalidErrorCode, "Invalid value for this setting"), n = !0)) : (this.logError(a, r.unknownErrorCode, "Unknown setting"), n = !0));
2224
+ }
2225
+ return !n;
2226
+ }
2227
+ logError(t, r, s) {
2228
+ if (r === void 0)
2229
+ throw Error(`This error shouldn't exist. Maybe a validator is misconfigured
2230
+ Error message: ${s}`);
2231
+ this.errors.push(new w(r, s, t));
2232
+ }
2233
+ }
2234
+ class F {
2235
+ constructor(t) {
2236
+ this.partialConfig = t;
2237
+ }
2238
+ doNotStopOnError() {
2239
+ return this.partialConfig.stopOnError = !1, this.partialConfig;
2240
+ }
2241
+ stopOnError() {
2242
+ return this.partialConfig.stopOnError = !0, this.partialConfig;
2243
+ }
2244
+ }
2245
+ const Ft = new F(
2246
+ tt({
2247
+ allowSimple: !0,
2248
+ simpleErrorCode: void 0,
2249
+ allowComplex: !0,
2250
+ complexErrorCode: void 0,
2251
+ stopOnError: !1
2252
+ })
2253
+ ), Cr = new F(
2254
+ tt({
2255
+ allowSimple: !0,
2256
+ simpleErrorCode: void 0,
2257
+ allowComplex: !1,
2258
+ complexErrorCode: c.UNEXPECTED_COMPLEX_BODY,
2259
+ stopOnError: !1
2260
+ })
2261
+ ), Oe = new F(
2262
+ tt({
2263
+ allowSimple: !1,
2264
+ simpleErrorCode: c.UNEXPECTED_SIMPLE_BODY,
2265
+ allowComplex: !0,
2266
+ complexErrorCode: void 0,
2267
+ stopOnError: !1
2268
+ })
2269
+ ), Mr = new F(
2270
+ Ut({
2271
+ optional: !0,
2272
+ notOptionalErrorCode: void 0,
2273
+ allow: !0,
2274
+ notAllowErrorCode: void 0,
2275
+ stopOnError: !1
2276
+ })
2277
+ ), Bt = new F(
2278
+ et({
2279
+ optional: !0,
2280
+ notOptionalErrorCode: void 0,
2281
+ allow: !0,
2282
+ notAllowErrorCode: void 0,
2283
+ allowComplex: !0,
2284
+ complexErrorCode: void 0,
2285
+ shouldRegister: !1,
2286
+ duplicateErrorCode: void 0,
2287
+ stopOnError: !1
2288
+ })
2289
+ ), rt = new F(
2290
+ et({
2291
+ optional: !1,
2292
+ notOptionalErrorCode: c.NAME_NOT_FOUND,
2293
+ allow: !0,
2294
+ notAllowErrorCode: void 0,
2295
+ allowComplex: !0,
2296
+ complexErrorCode: void 0,
2297
+ shouldRegister: !0,
2298
+ duplicateErrorCode: c.DUPLICATE_NAME,
2299
+ stopOnError: !1
2300
+ })
2301
+ ), V = new F(
2302
+ Ne(
2303
+ {},
2304
+ {
2305
+ optional: !0,
2306
+ notOptionalErrorCode: void 0,
2307
+ allow: !1,
2308
+ notAllowErrorCode: c.UNEXPECTED_SETTINGS,
2309
+ unknownErrorCode: void 0,
2310
+ duplicateErrorCode: void 0,
2311
+ invalidErrorCode: void 0,
2312
+ stopOnError: !1
2313
+ }
2314
+ )
2315
+ );
2316
+ function Pr(e) {
2317
+ return new F(
2318
+ Ze({
2319
+ globally: !1,
2320
+ notGloballyErrorCode: void 0,
2321
+ locally: !0,
2322
+ notLocallyErrorCode: e,
2323
+ stopOnError: !1
2324
+ })
2325
+ );
2326
+ }
2327
+ function Ur(e) {
2328
+ return new F(
2329
+ Ze({
2330
+ globally: !0,
2331
+ notGloballyErrorCode: e,
2332
+ locally: !1,
2333
+ notLocallyErrorCode: void 0,
2334
+ stopOnError: !1
2335
+ })
2336
+ );
2337
+ }
2338
+ const be = new F(
2339
+ Ze({
2340
+ globally: !1,
2341
+ notGloballyErrorCode: void 0,
2342
+ locally: !1,
2343
+ notLocallyErrorCode: void 0,
2344
+ stopOnError: !1
2345
+ })
2346
+ ), st = new F(
2347
+ et({
2348
+ optional: !0,
2349
+ notOptionalErrorCode: void 0,
2350
+ allow: !1,
2351
+ notAllowErrorCode: c.UNEXPECTED_NAME,
2352
+ allowComplex: !1,
2353
+ complexErrorCode: c.UNEXPECTED_NAME,
2354
+ shouldRegister: !1,
2355
+ duplicateErrorCode: void 0,
2356
+ stopOnError: !1
2357
+ })
2358
+ ), he = new F(
2359
+ Ut({
2360
+ optional: !0,
2361
+ notOptionalErrorCode: void 0,
2362
+ allow: !1,
2363
+ notAllowErrorCode: c.UNEXPECTED_ALIAS,
2364
+ stopOnError: !1
2365
+ })
2366
+ );
2367
+ class Fr extends se {
2368
+ constructor(t, r, s, n, i, a, o) {
2369
+ super(
2370
+ t,
2371
+ r,
2372
+ s,
2373
+ n,
2374
+ i,
2375
+ a,
2376
+ o
2377
+ ), this.elementKind = m.CUSTOM, this.context = {
2378
+ name: x.CustomContext,
2379
+ errorCode: c.INVALID_CUSTOM_CONTEXT,
2380
+ stopOnError: !1
2381
+ }, this.unique = be.doNotStopOnError(), this.name = st.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Cr.doNotStopOnError(), this.subfield = re({
2382
+ argValidators: [
2383
+ {
2384
+ validateArg: ce(
2385
+ J,
2386
+ c.INVALID_CUSTOM_ELEMENT_VALUE,
2387
+ "This field must be a string literal"
2388
+ )
2389
+ }
2390
+ ],
2391
+ invalidArgNumberErrorCode: c.INVALID_CUSTOM_ELEMENT_VALUE,
2392
+ invalidArgNumberErrorMessage: "A custom element field must be a single string literal",
2393
+ settingList: V.doNotStopOnError(),
2394
+ shouldRegister: !1,
2395
+ duplicateErrorCode: void 0
2396
+ });
2397
+ }
2398
+ }
2399
+ class Br extends se {
2400
+ constructor(t, r, s, n, i, a, o) {
2401
+ super(
2402
+ t,
2403
+ r,
2404
+ s,
2405
+ n,
2406
+ i,
2407
+ a,
2408
+ o
2409
+ ), this.elementKind = m.ENUM, this.context = {
2410
+ name: x.EnumContext,
2411
+ errorCode: c.INVALID_ENUM_CONTEXT,
2412
+ stopOnError: !1
2413
+ }, this.unique = be.doNotStopOnError(), this.name = rt.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Oe.doNotStopOnError(), this.subfield = re({
2414
+ argValidators: [
2415
+ {
2416
+ validateArg: ce(
2417
+ Y,
2418
+ c.INVALID_ENUM_ELEMENT_NAME,
2419
+ "This field must be a simple variable"
2420
+ )
2421
+ }
2422
+ ],
2423
+ invalidArgNumberErrorCode: c.INVALID_ENUM_ELEMENT,
2424
+ invalidArgNumberErrorMessage: "An enum's field must be a simple variable",
2425
+ settingList: Vr(),
2426
+ shouldRegister: !0,
2427
+ duplicateErrorCode: c.DUPLICATE_ENUM_ELEMENT_NAME
2428
+ });
2429
+ }
2430
+ }
2431
+ const Vr = () => Ne(
2432
+ {
2433
+ note: {
2434
+ allowDuplicate: !0,
2435
+ isValid: J
2436
+ }
2437
+ },
2438
+ {
2439
+ optional: !0,
2440
+ notOptionalErrorCode: void 0,
2441
+ allow: !0,
2442
+ notAllowErrorCode: void 0,
2443
+ unknownErrorCode: c.UNKNOWN_ENUM_ELEMENT_SETTING,
2444
+ duplicateErrorCode: c.DUPLICATE_ENUM_ELEMENT_SETTING,
2445
+ invalidErrorCode: c.INVALID_ENUM_ELEMENT_SETTING,
2446
+ stopOnError: !1
2447
+ }
2448
+ );
2449
+ class Gr extends se {
2450
+ constructor(t, r, s, n, i, a, o) {
2451
+ super(
2452
+ t,
2453
+ r,
2454
+ s,
2455
+ n,
2456
+ i,
2457
+ a,
2458
+ o
2459
+ ), this.elementKind = m.INDEXES, this.context = {
2460
+ name: x.IndexesContext,
2461
+ errorCode: c.INVALID_INDEXES_CONTEXT,
2462
+ stopOnError: !1
2463
+ }, this.unique = be.doNotStopOnError(), this.name = st.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Oe.doNotStopOnError(), this.subfield = re({
2464
+ argValidators: [
2465
+ {
2466
+ validateArg: ce(
2467
+ (u) => Pt(u).unwrap_or(void 0) !== void 0,
2468
+ c.INVALID_INDEX,
2469
+ "This field must be a function expression, a column name or a tuple of such"
2470
+ )
2471
+ }
2472
+ ],
2473
+ invalidArgNumberErrorCode: c.INVALID_INDEX,
2474
+ invalidArgNumberErrorMessage: "An Indexes field must be a function expression, a column name or a tuple of such",
2475
+ settingList: $r(),
2476
+ shouldRegister: !1,
2477
+ duplicateErrorCode: void 0
2478
+ });
2479
+ }
2480
+ }
2481
+ function Xr(e) {
2482
+ var r;
2483
+ if (!(e instanceof S) || !(e.expression instanceof M))
2484
+ return !1;
2485
+ const t = (r = e.expression.variable) == null ? void 0 : r.value;
2486
+ return t === "btree" || t === "hash";
2487
+ }
2488
+ const $r = () => Ne(
2489
+ {
2490
+ note: {
2491
+ allowDuplicate: !1,
2492
+ isValid: J
2493
+ },
2494
+ name: {
2495
+ allowDuplicate: !1,
2496
+ isValid: J
2497
+ },
2498
+ type: {
2499
+ allowDuplicate: !1,
2500
+ isValid: Xr
2501
+ },
2502
+ unique: {
2503
+ allowDuplicate: !1,
2504
+ isValid: Z
2505
+ },
2506
+ pk: {
2507
+ allowDuplicate: !1,
2508
+ isValid: Z
2509
+ }
2510
+ },
2511
+ {
2512
+ optional: !0,
2513
+ notOptionalErrorCode: void 0,
2514
+ allow: !0,
2515
+ notAllowErrorCode: void 0,
2516
+ unknownErrorCode: c.UNKNOWN_INDEX_SETTING,
2517
+ duplicateErrorCode: c.DUPLICATE_INDEX_SETTING,
2518
+ invalidErrorCode: c.INVALID_INDEX_SETTING_VALUE,
2519
+ stopOnError: !1
2520
+ }
2521
+ );
2522
+ class Wr extends se {
2523
+ constructor(t, r, s, n, i, a, o) {
2524
+ super(
2525
+ t,
2526
+ r,
2527
+ s,
2528
+ n,
2529
+ i,
2530
+ a,
2531
+ o
2532
+ ), this.elementKind = m.NOTE, this.context = {
2533
+ name: x.NoteContext,
2534
+ errorCode: c.INVALID_NOTE_CONTEXT,
2535
+ stopOnError: !1
2536
+ }, this.unique = Pr(c.NOTE_REDEFINED).doNotStopOnError(), this.name = st.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Ft.doNotStopOnError(), this.subfield = re({
2537
+ argValidators: [
2538
+ {
2539
+ validateArg: (u, h) => h > 0 ? [
2540
+ new w(
2541
+ c.NOTE_CONTENT_REDEFINED,
2542
+ "Only one note content can be defined",
2543
+ u
2544
+ )
2545
+ ] : J(u) ? [] : [
2546
+ new w(
2547
+ c.INVALID_NOTE,
2548
+ "A note's content must be doubly or singly quoted string",
2549
+ u
2550
+ )
2551
+ ]
2552
+ }
2553
+ ],
2554
+ invalidArgNumberErrorCode: c.INVALID_NOTE,
2555
+ invalidArgNumberErrorMessage: "A note content must be a doubly or singly quoted string",
2556
+ settingList: V.doNotStopOnError(),
2557
+ shouldRegister: !1,
2558
+ duplicateErrorCode: void 0
2559
+ });
2560
+ }
2561
+ }
2562
+ class qr extends se {
2563
+ constructor(t, r, s, n, i, a, o) {
2564
+ super(
2565
+ t,
2566
+ r,
2567
+ s,
2568
+ n,
2569
+ i,
2570
+ a,
2571
+ o
2572
+ ), this.elementKind = m.PROJECT, this.context = {
2573
+ name: x.ProjectContext,
2574
+ errorCode: c.INVALID_PROJECT_CONTEXT,
2575
+ stopOnError: !1
2576
+ }, this.unique = Ur(c.PROJECT_REDEFINED).doNotStopOnError(), this.name = Bt.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Oe.doNotStopOnError(), this.subfield = re({
2577
+ argValidators: [],
2578
+ invalidArgNumberErrorCode: c.INVALID_PROJECT_FIELD,
2579
+ invalidArgNumberErrorMessage: "A Project cannot have a subfield",
2580
+ settingList: V.doNotStopOnError(),
2581
+ shouldRegister: !1,
2582
+ duplicateErrorCode: void 0
2583
+ });
2584
+ }
2585
+ }
2586
+ class jr extends se {
2587
+ constructor(t, r, s, n, i, a, o) {
2588
+ super(
2589
+ t,
2590
+ r,
2591
+ s,
2592
+ n,
2593
+ i,
2594
+ a,
2595
+ o
2596
+ ), this.elementKind = m.REF, this.context = {
2597
+ name: x.RefContext,
2598
+ errorCode: c.INVALID_REF_CONTEXT,
2599
+ stopOnError: !1
2600
+ }, this.unique = be.doNotStopOnError(), this.name = Bt.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Ft.doNotStopOnError(), this.subfield = re({
2601
+ argValidators: [
2602
+ {
2603
+ validateArg: ce(
2604
+ Sr,
2605
+ c.INVALID_REF_RELATIONSHIP,
2606
+ "This field must be a valid binary relationship"
2607
+ )
2608
+ }
2609
+ ],
2610
+ invalidArgNumberErrorCode: c.INVALID_REF_FIELD,
2611
+ invalidArgNumberErrorMessage: "A ref's field must be a single valid binary relationship",
2612
+ settingList: zr(),
2613
+ shouldRegister: !1,
2614
+ duplicateErrorCode: void 0
2615
+ });
2616
+ }
2617
+ }
2618
+ function pt(e) {
2619
+ if (!(Y(e) && e.expression.variable.kind !== l.QUOTED_STRING) && !(e instanceof q))
2620
+ return !1;
2621
+ let t;
2622
+ if (e instanceof q ? t = le(e).unwrap_or("") : t = e.expression.variable.value, t)
2623
+ switch (t.toLowerCase()) {
2624
+ case "cascade":
2625
+ case "no action":
2626
+ case "set null":
2627
+ case "set default":
2628
+ case "restrict":
2629
+ return !0;
2630
+ default:
2631
+ return !1;
2632
+ }
2633
+ return !1;
2634
+ }
2635
+ const zr = () => Ne(
2636
+ {
2637
+ delete: {
2638
+ allowDuplicate: !1,
2639
+ isValid: pt
2640
+ },
2641
+ update: {
2642
+ allowDuplicate: !1,
2643
+ isValid: pt
2644
+ }
2645
+ },
2646
+ {
2647
+ optional: !0,
2648
+ notOptionalErrorCode: void 0,
2649
+ allow: !0,
2650
+ notAllowErrorCode: void 0,
2651
+ unknownErrorCode: c.UNKNOWN_REF_SETTING,
2652
+ duplicateErrorCode: c.DUPLICATE_REF_SETTING,
2653
+ invalidErrorCode: c.INVALID_REF_SETTING_VALUE,
2654
+ stopOnError: !1
2655
+ }
2656
+ );
2657
+ class Kr extends se {
2658
+ constructor(t, r, s, n, i, a, o) {
2659
+ super(
2660
+ t,
2661
+ r,
2662
+ s,
2663
+ n,
2664
+ i,
2665
+ a,
2666
+ o
2667
+ ), this.elementKind = m.TABLE, this.context = {
2668
+ name: x.TableContext,
2669
+ errorCode: c.INVALID_TABLE_CONTEXT,
2670
+ stopOnError: !1
2671
+ }, this.unique = be.doNotStopOnError(), this.name = rt.doNotStopOnError(), this.alias = Mr.doNotStopOnError(), this.settingList = Ne(
2672
+ {
2673
+ headercolor: {
2674
+ allowDuplicate: !1,
2675
+ isValid: rs
2676
+ },
2677
+ note: {
2678
+ allowDuplicate: !1,
2679
+ isValid: J
2680
+ }
2681
+ },
2682
+ {
2683
+ optional: !0,
2684
+ notOptionalErrorCode: void 0,
2685
+ allow: !0,
2686
+ notAllowErrorCode: void 0,
2687
+ unknownErrorCode: c.INVALID_TABLE_SETTING,
2688
+ duplicateErrorCode: c.DUPLICATE_TABLE_SETTING,
2689
+ invalidErrorCode: c.INVALID_TABLE_SETTING,
2690
+ stopOnError: !1
2691
+ }
2692
+ ), this.body = Oe.doNotStopOnError(), this.subfield = re({
2693
+ argValidators: [
2694
+ {
2695
+ validateArg: ce(
2696
+ Y,
2697
+ c.INVALID_COLUMN_NAME,
2698
+ "This field must be a valid column name"
2699
+ )
2700
+ },
2701
+ {
2702
+ validateArg: ce(
2703
+ Qr,
2704
+ c.INVALID_COLUMN_TYPE,
2705
+ "This field must be a valid column type"
2706
+ )
2707
+ }
2708
+ ],
2709
+ invalidArgNumberErrorCode: c.INVALID_COLUMN,
2710
+ invalidArgNumberErrorMessage: "A Table's column must have a name and a type",
2711
+ settingList: Yr(),
2712
+ shouldRegister: !0,
2713
+ duplicateErrorCode: c.DUPLICATE_COLUMN_NAME
2714
+ });
2715
+ }
2716
+ }
2717
+ function Qr(e) {
2718
+ var r, s;
2719
+ if (!(e instanceof oe || Pe(e) || e instanceof S))
2720
+ return !1;
2721
+ if (e instanceof oe) {
2722
+ if (e.callee === void 0 || (r = e.argumentList) != null && r.elementList.every((n) => n !== void 0))
2723
+ return !0;
2724
+ if (!((s = e.argumentList) != null && s.elementList.every(Se)))
2725
+ return !1;
2726
+ e = e.callee;
2727
+ }
2728
+ const t = pe(e).unwrap_or(void 0);
2729
+ return t !== void 0 && t.length > 0;
2730
+ }
2731
+ const Yr = () => Ne(
2732
+ {
2733
+ note: {
2734
+ allowDuplicate: !1,
2735
+ isValid: J
2736
+ },
2737
+ ref: {
2738
+ allowDuplicate: !0,
2739
+ isValid: ns
2740
+ },
2741
+ "primary key": {
2742
+ allowDuplicate: !1,
2743
+ isValid: Z
2744
+ },
2745
+ default: {
2746
+ allowDuplicate: !1,
2747
+ isValid: ss
2748
+ },
2749
+ increment: {
2750
+ allowDuplicate: !1,
2751
+ isValid: Z
2752
+ },
2753
+ "not null": {
2754
+ allowDuplicate: !1,
2755
+ isValid: Z
2756
+ },
2757
+ null: {
2758
+ allowDuplicate: !1,
2759
+ isValid: Z
2760
+ },
2761
+ pk: {
2762
+ allowDuplicate: !1,
2763
+ isValid: Z
2764
+ },
2765
+ unique: {
2766
+ allowDuplicate: !1,
2767
+ isValid: Z
2768
+ }
2769
+ },
2770
+ {
2771
+ optional: !0,
2772
+ notOptionalErrorCode: void 0,
2773
+ allow: !0,
2774
+ notAllowErrorCode: void 0,
2775
+ unknownErrorCode: c.UNKNOWN_COLUMN_SETTING,
2776
+ duplicateErrorCode: c.DUPLICATE_COLUMN_SETTING,
2777
+ invalidErrorCode: c.INVALID_COLUMN_SETTING_VALUE,
2778
+ stopOnError: !1
2779
+ }
2780
+ );
2781
+ class Hr extends se {
2782
+ constructor(t, r, s, n, i, a, o) {
2783
+ super(
2784
+ t,
2785
+ r,
2786
+ s,
2787
+ n,
2788
+ i,
2789
+ a,
2790
+ o
2791
+ ), this.elementKind = m.TABLEGROUP, this.context = {
2792
+ name: x.TableGroupContext,
2793
+ errorCode: c.INVALID_TABLEGROUP_CONTEXT,
2794
+ stopOnError: !1
2795
+ }, this.unique = be.doNotStopOnError(), this.name = rt.doNotStopOnError(), this.alias = he.doNotStopOnError(), this.settingList = V.doNotStopOnError(), this.body = Oe.doNotStopOnError(), this.subfield = re({
2796
+ argValidators: [
2797
+ {
2798
+ validateArg: ce(
2799
+ Wt,
2800
+ c.INVALID_TABLEGROUP_ELEMENT_NAME,
2801
+ "This field must be a valid table name"
2802
+ )
2803
+ }
2804
+ ],
2805
+ invalidArgNumberErrorCode: c.INVALID_TABLEGROUP_FIELD,
2806
+ invalidArgNumberErrorMessage: "A TableGroup field must be a single valid table name",
2807
+ settingList: V.doNotStopOnError(),
2808
+ shouldRegister: !1,
2809
+ duplicateErrorCode: void 0
2810
+ });
2811
+ }
2812
+ }
2813
+ const Vt = ["null", "true", "false"], Gt = ["-", "+"];
2814
+ function Xt(e) {
2815
+ switch (e.toLowerCase()) {
2816
+ case "enum":
2817
+ return m.ENUM;
2818
+ case "table":
2819
+ return m.TABLE;
2820
+ case "tablegroup":
2821
+ return m.TABLEGROUP;
2822
+ case "project":
2823
+ return m.PROJECT;
2824
+ case "ref":
2825
+ return m.REF;
2826
+ case "note":
2827
+ return m.NOTE;
2828
+ case "indexes":
2829
+ return m.INDEXES;
2830
+ default:
2831
+ return m.CUSTOM;
2832
+ }
2833
+ }
2834
+ function $t(e) {
2835
+ switch (Xt(e.type.value)) {
2836
+ case m.ENUM:
2837
+ return Br;
2838
+ case m.TABLE:
2839
+ return Kr;
2840
+ case m.TABLEGROUP:
2841
+ return Hr;
2842
+ case m.PROJECT:
2843
+ return qr;
2844
+ case m.REF:
2845
+ return jr;
2846
+ case m.NOTE:
2847
+ return Wr;
2848
+ case m.INDEXES:
2849
+ return Gr;
2850
+ default:
2851
+ return Fr;
2852
+ }
2853
+ }
2854
+ function Wt(e) {
2855
+ return !!pe(e).unwrap_or(!1);
2856
+ }
2857
+ function Jr(e) {
2858
+ return Xe(e);
2859
+ }
2860
+ function Xe(e) {
2861
+ return e instanceof S && e.expression instanceof M;
2862
+ }
2863
+ function Zr(e) {
2864
+ return e instanceof U;
2865
+ }
2866
+ function Nt(e) {
2867
+ return e.body instanceof j && !e.bodyColon;
2868
+ }
2869
+ function es(e) {
2870
+ return !!e.bodyColon;
2871
+ }
2872
+ function ts(e, t, r) {
2873
+ var n;
2874
+ let s = t;
2875
+ for (const i of e) {
2876
+ let a;
2877
+ const o = je(i);
2878
+ if (s.has(o)) {
2879
+ if (a = (n = s.get(o)) == null ? void 0 : n.symbolTable, !a)
2880
+ throw new Error("Expect a symbol table in a schema symbol");
2881
+ } else {
2882
+ a = new we();
2883
+ const u = r.create(St, { symbolTable: a });
2884
+ s.set(o, u);
2885
+ }
2886
+ s = a;
2887
+ }
2888
+ return s;
2889
+ }
2890
+ function qt(e) {
2891
+ return e === "-" || e === "<>" || e === ">" || e === "<";
2892
+ }
2893
+ function rs(e) {
2894
+ var r;
2895
+ if (!(e instanceof S) || !(e.expression instanceof ue) || ((r = e.expression.literal) == null ? void 0 : r.kind) !== l.COLOR_LITERAL)
2896
+ return !1;
2897
+ const t = e.expression.literal.value;
2898
+ if (t.length !== 4 && t.length !== 7 || t[0] !== "#")
2899
+ return !1;
2900
+ for (let s = 1; s < t.length; s += 1)
2901
+ if (!Nr(t[s]))
2902
+ return !1;
2903
+ return !0;
2904
+ }
2905
+ function Z(e) {
2906
+ return e === void 0 || !Array.isArray(e) && e.end === -1 && e.start === -1 || Array.isArray(e) && e.length === 0;
2907
+ }
2908
+ function ss(e) {
2909
+ var r;
2910
+ if (e instanceof S && (e.expression instanceof ue || e.expression instanceof M) || e instanceof z && Gt.includes((r = e.op) == null ? void 0 : r.value) && Se(e.expression) || e instanceof B)
2911
+ return !0;
2912
+ if (!e || Array.isArray(e) || !Pe(e))
2913
+ return !1;
2914
+ const t = pe(e).unwrap_or(void 0);
2915
+ return t !== void 0 && t.length > 0;
2916
+ }
2917
+ function Se(e) {
2918
+ var t;
2919
+ return e instanceof S && e.expression instanceof ue && ((t = e.expression.literal) == null ? void 0 : t.kind) === l.NUMERIC_LITERAL;
2920
+ }
2921
+ function ns(e) {
2922
+ var r;
2923
+ if (!(e instanceof z) || !qt((r = e.op) == null ? void 0 : r.value))
2924
+ return !1;
2925
+ const t = pe(e.expression).unwrap_or(void 0);
2926
+ return t !== void 0 && t.length > 0;
2927
+ }
2928
+ function jt(e) {
2929
+ return e instanceof Q && e.elementList.every(Y);
2930
+ }
2931
+ class bt {
2932
+ constructor(t, r) {
2933
+ this.ast = t, this.contextStack = new ar(), this.errors = [], this.symbolFactory = r, this.publicSchemaSymbol = this.symbolFactory.create(St, {
2934
+ symbolTable: new we()
2935
+ }), this.kindsGloballyFound = /* @__PURE__ */ new Set(), this.kindsLocallyFound = /* @__PURE__ */ new Set(), this.ast.symbol = this.publicSchemaSymbol, this.ast.symbol.declaration = this.ast;
2936
+ }
2937
+ validate() {
2938
+ return this.ast.body.forEach((t) => {
2939
+ if (t.parent = this.ast, t.type === void 0)
2940
+ return;
2941
+ const r = t, s = $t(r);
2942
+ new s(
2943
+ r,
2944
+ this.publicSchemaSymbol,
2945
+ this.contextStack,
2946
+ this.errors,
2947
+ this.kindsGloballyFound,
2948
+ this.kindsLocallyFound,
2949
+ this.symbolFactory
2950
+ ).validate();
2951
+ }), new H(this.ast, this.errors);
2952
+ }
2953
+ }
2954
+ class ne {
2955
+ constructor(t, r) {
2956
+ this.declarationNode = t, this.errors = r;
2957
+ }
2958
+ bind() {
2959
+ this.bindSettingList(this.declarationNode.attributeList, this.settingList), this.bindBody();
2960
+ }
2961
+ bindSettingList(t, r) {
2962
+ if (t)
2963
+ for (const s of t.elementList) {
2964
+ const n = le(s.name).unwrap_or(void 0);
2965
+ if (!n)
2966
+ continue;
2967
+ const i = r[n.toLowerCase()];
2968
+ i != null && i.shouldBind && this.scanAndBind(s.value, i);
2969
+ }
2970
+ }
2971
+ bindBody() {
2972
+ const t = this.declarationNode;
2973
+ if (!t.body)
2974
+ return;
2975
+ const { body: r } = t;
2976
+ if (r instanceof j)
2977
+ for (const s of r.body)
2978
+ if (s instanceof A && s.type) {
2979
+ const n = zt(s);
2980
+ new n(s, this.errors).bind();
2981
+ } else
2982
+ this.bindSubfield(s);
2983
+ else
2984
+ this.bindSubfield(r);
2985
+ }
2986
+ bindSubfield(t) {
2987
+ if (t instanceof A)
2988
+ return;
2989
+ const r = [t.callee, ...t.args], s = C.last(r);
2990
+ s instanceof U && (r.pop(), this.bindSettingList(s, this.subfield.settingList));
2991
+ const { argBinderRules: n } = this.subfield.arg;
2992
+ for (let i = 0; i < Math.min(r.length, n.length); i += 1)
2993
+ n[i].shouldBind && this.scanAndBind(r[i], n[i]);
2994
+ }
2995
+ // Scan for variable node and member access expression in the node to bind
2996
+ scanAndBind(t, r) {
2997
+ var s, n;
2998
+ if (t)
2999
+ if (t instanceof S) {
3000
+ if (t.expression instanceof M && ((n = r.keywords) != null && n.includes((s = t.expression.variable) == null ? void 0 : s.value)))
3001
+ return;
3002
+ this.bindFragments([t], r);
3003
+ } else
3004
+ t instanceof K ? Pe(t) ? this.bindFragments(Ee(t).unwrap_or([]), r) : (this.scanAndBind(t.leftExpression, r), this.scanAndBind(t.rightExpression, r)) : t instanceof z ? this.scanAndBind(t.expression, r) : t instanceof Ce ? this.scanAndBind(t.expression, r) : t instanceof Q && t.elementList.forEach((i) => this.scanAndBind(i, r));
3005
+ }
3006
+ // Bind the fragments of a member access expression
3007
+ // which can be a simple expression like v1.User,
3008
+ // or a complex tuple like v1.User.(id, name)
3009
+ bindFragments(t, r) {
3010
+ if (t.length === 0)
3011
+ return;
3012
+ const s = [...r.topSubnamesSymbolKind], { remainingSubnamesSymbolKind: n } = r, i = t.findIndex((p) => !Y(p)), o = i !== -1 && jt(t[i]) ? t[i] : void 0, u = i >= 0 ? s.pop() : void 0, h = t.slice(
3013
+ 0,
3014
+ i === -1 ? void 0 : i
3015
+ );
3016
+ if (h.length === 0)
3017
+ return;
3018
+ const b = [];
3019
+ for (; s.length && h.length; ) {
3020
+ const p = s.pop(), f = h.pop(), _ = W(f).unwrap();
3021
+ b.unshift({
3022
+ index: Be(_, p),
3023
+ referrer: f
3024
+ });
3025
+ }
3026
+ for (; h.length; ) {
3027
+ const p = h.pop(), f = W(p).unwrap();
3028
+ b.unshift({
3029
+ index: Be(f, n),
3030
+ referrer: p
3031
+ });
3032
+ }
3033
+ return o ? o.elementList.forEach(
3034
+ (p) => this.resolveIndexStack(
3035
+ [
3036
+ ...b,
3037
+ {
3038
+ index: Be(
3039
+ W(p).unwrap(),
3040
+ u
3041
+ ),
3042
+ referrer: p
3043
+ }
3044
+ ],
3045
+ r.ignoreNameNotFound
3046
+ )
3047
+ ) : this.resolveIndexStack(b, r.ignoreNameNotFound);
3048
+ }
3049
+ // Looking up the indexes in the subname stack from the current declaration node
3050
+ // Each time the index resolves to a symbol, the referrer's symbol is bound to it
3051
+ resolveIndexStack(t, r) {
3052
+ if (t.length === 0)
3053
+ throw new Error("Unreachable - An unresolved name must have at least one name component");
3054
+ const [s, ...n] = t, i = Rr(s.index, this.declarationNode);
3055
+ if (i === void 0) {
3056
+ const { kind: h, name: b } = ee(s.index).unwrap();
3057
+ this.logError(s.referrer, `Can not find ${h} '${b}'`, r);
3058
+ return;
3059
+ }
3060
+ i.references.push(s.referrer), s.referrer.referee = i;
3061
+ let a = i.symbolTable, { kind: o, name: u } = ee(s.index).unwrap();
3062
+ for (const h of n) {
3063
+ const { kind: b, name: p } = ee(h.index).unwrap(), f = a.get(h.index);
3064
+ if (!f) {
3065
+ this.logError(
3066
+ h.referrer,
3067
+ `${o} '${u}' does not have ${b} '${p}'`,
3068
+ r
3069
+ );
3070
+ return;
3071
+ }
3072
+ if (o = b, u = p, h.referrer.referee = f, f.references.push(h.referrer), !f.symbolTable)
3073
+ break;
3074
+ a = f.symbolTable;
3075
+ }
3076
+ }
3077
+ logError(t, r, s) {
3078
+ s || this.errors.push(new w(c.BINDING_ERROR, r, t));
3079
+ }
3080
+ }
3081
+ class is extends ne {
3082
+ constructor() {
3083
+ super(...arguments), this.subfield = {
3084
+ arg: {
3085
+ argBinderRules: []
3086
+ },
3087
+ settingList: {}
3088
+ }, this.settingList = {};
3089
+ }
3090
+ }
3091
+ class as extends ne {
3092
+ constructor() {
3093
+ super(...arguments), this.subfield = {
3094
+ arg: {
3095
+ argBinderRules: [{ shouldBind: !1 }]
3096
+ },
3097
+ settingList: {}
3098
+ }, this.settingList = {};
3099
+ }
3100
+ }
3101
+ class os extends ne {
3102
+ constructor() {
3103
+ super(...arguments), this.subfield = {
3104
+ arg: {
3105
+ argBinderRules: [
3106
+ {
3107
+ shouldBind: !0,
3108
+ topSubnamesSymbolKind: [N.Table, N.Column],
3109
+ remainingSubnamesSymbolKind: N.Schema,
3110
+ ignoreNameNotFound: !1
3111
+ }
3112
+ ]
3113
+ },
3114
+ settingList: {}
3115
+ }, this.settingList = {};
3116
+ }
3117
+ }
3118
+ class ls extends ne {
3119
+ constructor() {
3120
+ super(...arguments), this.subfield = {
3121
+ arg: {
3122
+ argBinderRules: [{ shouldBind: !1 }]
3123
+ },
3124
+ settingList: {}
3125
+ }, this.settingList = {};
3126
+ }
3127
+ }
3128
+ class cs extends ne {
3129
+ constructor() {
3130
+ super(...arguments), this.subfield = {
3131
+ arg: {
3132
+ argBinderRules: []
3133
+ },
3134
+ settingList: {}
3135
+ }, this.settingList = {};
3136
+ }
3137
+ }
3138
+ class us extends ne {
3139
+ constructor() {
3140
+ super(...arguments), this.subfield = {
3141
+ arg: {
3142
+ argBinderRules: [
3143
+ {
3144
+ shouldBind: !0,
3145
+ topSubnamesSymbolKind: [N.Table, N.Column],
3146
+ remainingSubnamesSymbolKind: N.Schema,
3147
+ ignoreNameNotFound: !1
3148
+ }
3149
+ ]
3150
+ },
3151
+ settingList: {}
3152
+ }, this.settingList = {};
3153
+ }
3154
+ }
3155
+ class hs extends ne {
3156
+ constructor() {
3157
+ super(...arguments), this.subfield = {
3158
+ arg: {
3159
+ argBinderRules: [
3160
+ { shouldBind: !1 },
3161
+ {
3162
+ shouldBind: !0,
3163
+ topSubnamesSymbolKind: [N.Enum],
3164
+ remainingSubnamesSymbolKind: N.Schema,
3165
+ ignoreNameNotFound: !0
3166
+ }
3167
+ ]
3168
+ },
3169
+ settingList: {
3170
+ ref: {
3171
+ shouldBind: !0,
3172
+ topSubnamesSymbolKind: [N.Table, N.Column],
3173
+ remainingSubnamesSymbolKind: N.Schema,
3174
+ ignoreNameNotFound: !1
3175
+ },
3176
+ default: {
3177
+ shouldBind: !0,
3178
+ topSubnamesSymbolKind: [N.Enum, N.EnumField],
3179
+ remainingSubnamesSymbolKind: N.Schema,
3180
+ ignoreNameNotFound: !1,
3181
+ keywords: Vt
3182
+ }
3183
+ }
3184
+ }, this.settingList = {};
3185
+ }
3186
+ }
3187
+ class ds extends ne {
3188
+ constructor() {
3189
+ super(...arguments), this.subfield = {
3190
+ arg: {
3191
+ argBinderRules: [
3192
+ {
3193
+ shouldBind: !0,
3194
+ topSubnamesSymbolKind: [N.Table],
3195
+ remainingSubnamesSymbolKind: N.Schema,
3196
+ ignoreNameNotFound: !1
3197
+ }
3198
+ ]
3199
+ },
3200
+ settingList: {}
3201
+ }, this.settingList = {};
3202
+ }
3203
+ }
3204
+ function zt(e) {
3205
+ switch (Xt(e.type.value)) {
3206
+ case m.ENUM:
3207
+ return as;
3208
+ case m.TABLE:
3209
+ return hs;
3210
+ case m.TABLEGROUP:
3211
+ return ds;
3212
+ case m.PROJECT:
3213
+ return cs;
3214
+ case m.REF:
3215
+ return us;
3216
+ case m.NOTE:
3217
+ return ls;
3218
+ case m.INDEXES:
3219
+ return os;
3220
+ default:
3221
+ return is;
3222
+ }
3223
+ }
3224
+ class fs {
3225
+ constructor(t) {
3226
+ this.ast = t, this.errors = [];
3227
+ }
3228
+ resolve() {
3229
+ for (const t of this.ast.body)
3230
+ if (t.type) {
3231
+ const r = zt(t);
3232
+ new r(t, this.errors).bind();
3233
+ }
3234
+ return new H(this.ast, this.errors);
3235
+ }
3236
+ }
3237
+ class Es {
3238
+ constructor(t) {
3239
+ this.generator = t;
3240
+ }
3241
+ create(t, r) {
3242
+ return new t(r, this.generator.nextId());
3243
+ }
3244
+ }
3245
+ class ps {
3246
+ constructor(t, r) {
3247
+ this.ast = t, this.symbolFactory = new Es(r);
3248
+ }
3249
+ // Analyzing: Invoking both the validator and binder
3250
+ analyze() {
3251
+ return new bt(this.ast, this.symbolFactory).validate().chain((r) => new fs(r).resolve());
3252
+ }
3253
+ // For invoking the validator only
3254
+ validate() {
3255
+ return new bt(this.ast, this.symbolFactory).validate().chain((r) => new H(r, []));
3256
+ }
3257
+ }
3258
+ function Ns(e, t, r) {
3259
+ const s = e.map((a) => a.id), n = t.map((a) => a.id), i = s[0] < n[0] ? `${s.join(",")}_${n.join(",")}` : `${n.join(",")}_${s.join(",")}`;
3260
+ return r.has(i) ? !0 : (r.add(i), !1);
3261
+ }
3262
+ function bs(e, t) {
3263
+ return C.zip(e, t).every(([r, s]) => (r == null ? void 0 : r.id) === (s == null ? void 0 : s.id));
3264
+ }
3265
+ function mt(e) {
3266
+ switch (e) {
3267
+ case "<":
3268
+ return ["1", "*"];
3269
+ case "<>":
3270
+ return ["*", "*"];
3271
+ case ">":
3272
+ return ["*", "1"];
3273
+ case "-":
3274
+ return ["1", "1"];
3275
+ }
3276
+ throw new Error("Invalid relation op");
3277
+ }
3278
+ function $e(e, t, r) {
3279
+ const { tupleElements: s, variables: n } = Ge(e).unwrap(), i = s || [n.pop()], a = n.pop(), o = n.pop();
3280
+ if (n.length > 0)
3281
+ return new w(
3282
+ c.UNSUPPORTED,
3283
+ "Nested schemas are currently not allowed",
3284
+ e
3285
+ );
3286
+ if (a === void 0 && t === null)
3287
+ throw new Error("A rel operand's table name must be defined");
3288
+ return {
3289
+ columnNames: i,
3290
+ // if tableName is undefined, the columnName must be relative to the owner
3291
+ tableName: a || t,
3292
+ schemaName: a ? o || null : r
3293
+ };
3294
+ }
3295
+ function R(e) {
3296
+ return {
3297
+ start: {
3298
+ offset: e.startPos.offset,
3299
+ line: e.startPos.line + 1,
3300
+ column: e.startPos.column + 1
3301
+ },
3302
+ end: { offset: e.endPos.offset, line: e.endPos.line + 1, column: e.endPos.column + 1 }
3303
+ };
3304
+ }
3305
+ function We(e) {
3306
+ var r;
3307
+ const t = (r = Ee(e).unwrap_or(void 0)) == null ? void 0 : r.pop();
3308
+ return t instanceof Q ? t.elementList.every((s) => !!s.referee) ? new I(t.elementList.map((s) => s.referee)) : new T() : (t == null ? void 0 : t.referee) instanceof Dt ? new I([t.referee]) : new T();
3309
+ }
3310
+ function Kt(e) {
3311
+ return e.split(`
3312
+ `).map((t) => t.trim()).join(`
3313
+ `);
3314
+ }
3315
+ class ms {
3316
+ constructor() {
3317
+ this.map = /* @__PURE__ */ new Map();
3318
+ }
3319
+ insert(t, r) {
3320
+ const s = this.map.get(t);
3321
+ s === void 0 ? this.map.set(t, [r]) : s.push(r);
3322
+ }
3323
+ getValue(t) {
3324
+ const r = this.map.get(t);
3325
+ if (r !== void 0)
3326
+ return r[0].value === void 0 ? !0 : r.length >= 2 ? r.map((s) => s.value) : r[0].value;
3327
+ }
3328
+ getAttributeNode(t) {
3329
+ const r = this.map.get(t);
3330
+ if (r !== void 0)
3331
+ return r.length >= 2 ? r : r[0];
3332
+ }
3333
+ }
3334
+ function Le(e, t) {
3335
+ const r = new ms();
3336
+ if (!e)
3337
+ return new gt(r, t);
3338
+ for (const s of e.elementList) {
3339
+ const n = le(s.name).unwrap_or("").toLowerCase();
3340
+ r.insert(n, s);
3341
+ }
3342
+ return new gt(r, t);
3343
+ }
3344
+ class gt {
3345
+ constructor(t, r) {
3346
+ this.settingMap = t, this.errors = r;
3347
+ }
3348
+ extractNote() {
3349
+ const t = this.settingMap.getValue("note");
3350
+ return t !== void 0 ? Kt(fe(t).unwrap()) : void 0;
3351
+ }
3352
+ extractDefault() {
3353
+ var s, n, i;
3354
+ const t = this.settingMap.getValue("default");
3355
+ if (t === void 0)
3356
+ return;
3357
+ const r = t;
3358
+ if (r instanceof S && r.expression instanceof M && Vt.includes((s = r.expression.variable) == null ? void 0 : s.value))
3359
+ return {
3360
+ type: "boolean",
3361
+ value: r.expression.variable.value
3362
+ };
3363
+ if (Se(r))
3364
+ return {
3365
+ type: "number",
3366
+ value: Number(r.expression.literal.value)
3367
+ };
3368
+ if (r instanceof z && Gt.includes((n = r.op) == null ? void 0 : n.value) && Se(r.expression))
3369
+ return {
3370
+ type: "number",
3371
+ value: Number(r.expression.expression.literal.value) * (((i = r.op) == null ? void 0 : i.value) === "+" ? 1 : -1)
3372
+ };
3373
+ if (J(r))
3374
+ return {
3375
+ value: fe(r).unwrap(),
3376
+ type: "string"
3377
+ };
3378
+ if (r instanceof B)
3379
+ return {
3380
+ value: r.value.value,
3381
+ type: "expression"
3382
+ };
3383
+ this.errors.push(
3384
+ new w(c.UNSUPPORTED, "Unsupported default value", r)
3385
+ );
3386
+ }
3387
+ extractRef(t, r) {
3388
+ const s = this.settingMap.getValue("ref");
3389
+ if (s === void 0)
3390
+ return [];
3391
+ const n = Array.isArray(s) ? s : [s], i = [];
3392
+ for (const a of n) {
3393
+ const o = a.expression, u = $e(o, t, r);
3394
+ if (u instanceof w)
3395
+ this.errors.push(u);
3396
+ else {
3397
+ const { columnNames: h, tableName: b, schemaName: p } = u, f = a.op.value;
3398
+ i.push({
3399
+ schemaName: p,
3400
+ tableName: b,
3401
+ fieldNames: h,
3402
+ relation: f,
3403
+ token: R(a),
3404
+ referee: We(
3405
+ a.expression
3406
+ ).unwrap()[0],
3407
+ node: a
3408
+ });
3409
+ }
3410
+ }
3411
+ return i;
3412
+ }
3413
+ extractHeaderColor() {
3414
+ const t = this.settingMap.getValue("headercolor");
3415
+ if (t !== void 0)
3416
+ return t.expression.literal.value;
3417
+ }
3418
+ extractUpdate() {
3419
+ const t = this.settingMap.getValue("update");
3420
+ if (t !== void 0)
3421
+ return t instanceof q ? le(t).unwrap_or("") : t.expression.variable.value;
3422
+ }
3423
+ extractDelete() {
3424
+ const t = this.settingMap.getValue("delete");
3425
+ if (t !== void 0)
3426
+ return t instanceof q ? le(t).unwrap_or("") : t.expression.variable.value;
3427
+ }
3428
+ extractIndexType() {
3429
+ const t = this.settingMap.getValue("type");
3430
+ if (t !== void 0)
3431
+ return t.expression.variable.value;
3432
+ }
3433
+ extractPk() {
3434
+ if ((this.settingMap.getValue("pk") || this.settingMap.getValue("primary key")) !== void 0)
3435
+ return !0;
3436
+ }
3437
+ extractUnique() {
3438
+ if (this.settingMap.getValue("unique") !== void 0)
3439
+ return !0;
3440
+ }
3441
+ extractIncrement() {
3442
+ if (this.settingMap.getValue("increment") !== void 0)
3443
+ return !0;
3444
+ }
3445
+ extractNotNull() {
3446
+ const t = this.settingMap.getValue("not null"), r = this.settingMap.getValue("null");
3447
+ if (!(t === void 0 && r === void 0)) {
3448
+ if (t && r) {
3449
+ this.errors.push(
3450
+ new w(
3451
+ c.CONFLICTING_SETTING,
3452
+ "null and not null can not be set at the same time",
3453
+ this.settingMap.getAttributeNode("not null")
3454
+ )
3455
+ );
3456
+ return;
3457
+ }
3458
+ return !!t;
3459
+ }
3460
+ }
3461
+ extractIdxName() {
3462
+ const t = this.settingMap.getValue("name");
3463
+ if (t !== void 0)
3464
+ return fe(t).unwrap();
3465
+ }
3466
+ }
3467
+ class gs {
3468
+ constructor(t) {
3469
+ this.ast = t, this.db = {
3470
+ schemas: [],
3471
+ tables: [],
3472
+ refs: [],
3473
+ enums: [],
3474
+ tableGroups: [],
3475
+ aliases: [],
3476
+ project: {}
3477
+ }, this.endpointPairSet = /* @__PURE__ */ new Set(), this.errors = [];
3478
+ }
3479
+ interpret() {
3480
+ return this.ast.body.forEach((t) => {
3481
+ switch (t.type.value.toLowerCase()) {
3482
+ case "table":
3483
+ ie(this.table(t), this.db.tables);
3484
+ break;
3485
+ case "ref":
3486
+ this.db.refs.push(...this.ref(t, null, null));
3487
+ break;
3488
+ case "tablegroup":
3489
+ ie(this.tableGroup(t), this.db.tableGroups);
3490
+ break;
3491
+ case "enum":
3492
+ ie(this.enum(t), this.db.enums);
3493
+ break;
3494
+ case "project":
3495
+ this.db.project = this.project(t), this.db.project && (this.db.tables.push(...this.db.project.tables), this.db.enums.push(...this.db.project.enums), this.db.tableGroups.push(...this.db.project.tableGroups));
3496
+ break;
3497
+ default:
3498
+ throw new Error("Unreachable - unknown element type");
3499
+ }
3500
+ }), new H(this.db, this.errors);
3501
+ }
3502
+ table(t) {
3503
+ const r = this.extractElementName(t.name);
3504
+ if (!r.isOk())
3505
+ return;
3506
+ const { name: s, schemaName: n } = r.unwrap(), i = t.alias ? W(t.alias).unwrap_or(null) : null;
3507
+ i && this.db.aliases.push({
3508
+ name: i,
3509
+ kind: "table",
3510
+ value: {
3511
+ tableName: s,
3512
+ schemaName: n
3513
+ }
3514
+ });
3515
+ const a = Le(t.attributeList, this.errors), o = a.extractHeaderColor(), u = a.extractNote();
3516
+ let h;
3517
+ const b = a.settingMap.getAttributeNode("note"), p = [], f = [], _ = [];
3518
+ return t.body.body.forEach((v) => {
3519
+ if (v instanceof te) {
3520
+ const G = this.column(v, s, n);
3521
+ ie(G, p), G != null && G.pk && _.push(G);
3522
+ } else if (v instanceof A)
3523
+ switch (v.type.value.toLowerCase()) {
3524
+ case "ref":
3525
+ this.db.refs.push(...this.ref(v, s, n));
3526
+ break;
3527
+ case "indexes":
3528
+ f.push(...this.indexes(v));
3529
+ break;
3530
+ case "note":
3531
+ u !== void 0 ? this.logError(
3532
+ v,
3533
+ c.NOTE_REDEFINED,
3534
+ "Note already appears as a setting of the table"
3535
+ ) : h = this.note(v);
3536
+ break;
3537
+ }
3538
+ }), _.length >= 2 && (f.push({
3539
+ columns: _.map(({ name: v }) => ({ value: v, type: "column" })),
3540
+ token: {
3541
+ start: { offset: -1, line: -1, column: -1 },
3542
+ // do not make sense to have a meaningful start (?)
3543
+ end: { offset: -1, line: -1, column: -1 }
3544
+ // do not make sense to have a meaningful end (?)
3545
+ },
3546
+ pk: !0
3547
+ }), _.forEach((v) => v.pk = !1)), {
3548
+ name: s,
3549
+ schemaName: n,
3550
+ alias: i,
3551
+ fields: p,
3552
+ token: R(t),
3553
+ indexes: f,
3554
+ headerColor: o,
3555
+ note: u === void 0 ? h : {
3556
+ value: u,
3557
+ token: R(b)
3558
+ }
3559
+ };
3560
+ }
3561
+ column(t, r, s) {
3562
+ const n = W(t.callee);
3563
+ let i = t.args[0], a = null;
3564
+ i instanceof oe && (a = i.argumentList.elementList.map((X) => X.expression.literal.value).join(","), i = i.callee);
3565
+ const o = this.extractElementName(i);
3566
+ if (!o.isOk())
3567
+ return;
3568
+ const { name: u, schemaName: h } = o.unwrap();
3569
+ let b, p, f, _, v, G, me, ge = [];
3570
+ const Te = [];
3571
+ if (t.args.length === 2) {
3572
+ const X = Le(t.args[1], this.errors);
3573
+ b = X.extractPk(), p = X.extractIncrement(), f = X.extractUnique(), _ = X.extractNotNull(), me = X.extractDefault(), v = X.extractNote(), G = X.settingMap.getAttributeNode("note"), ge = X.extractRef(r, s), ge.forEach(($) => {
3574
+ this.logIfSameEndpoint($.node, [t.symbol], [$.referee]) && this.logIfCircularRefError($.node, [t.symbol], [$.referee]) && (Te.push({
3575
+ schemaName: $.schemaName,
3576
+ tableName: $.tableName,
3577
+ fieldNames: $.fieldNames,
3578
+ relation: $.relation,
3579
+ token: $.token
3580
+ }), this.registerInlineRefEndpoints($, t, r, s));
3581
+ });
3582
+ }
3583
+ return {
3584
+ name: n.unwrap(),
3585
+ type: {
3586
+ schemaName: h,
3587
+ type_name: `${u}${a === null ? "" : `(${a})`}`,
3588
+ args: a
3589
+ },
3590
+ token: R(t),
3591
+ inline_refs: Te,
3592
+ pk: b,
3593
+ unique: f,
3594
+ not_null: _,
3595
+ dbdefault: me,
3596
+ increment: p,
3597
+ note: v === void 0 ? void 0 : {
3598
+ value: v,
3599
+ token: R(G)
3600
+ }
3601
+ };
3602
+ }
3603
+ registerInlineRefEndpoints(t, r, s, n) {
3604
+ const [i, a] = mt(t.relation), o = {
3605
+ schemaName: null,
3606
+ name: null,
3607
+ endpoints: [
3608
+ {
3609
+ schemaName: n,
3610
+ tableName: s,
3611
+ fieldNames: [W(r.callee).unwrap()],
3612
+ relation: i,
3613
+ token: R(r)
3614
+ },
3615
+ {
3616
+ schemaName: t.schemaName,
3617
+ tableName: t.tableName,
3618
+ fieldNames: t.fieldNames,
3619
+ relation: a,
3620
+ token: t.token
3621
+ }
3622
+ ],
3623
+ token: t.token
3624
+ };
3625
+ this.db.refs.push(o);
3626
+ }
3627
+ ref(t, r, s) {
3628
+ let n = null, i = null;
3629
+ if (t.name) {
3630
+ const o = this.extractElementName(t.name);
3631
+ if (!o.isOk())
3632
+ return [];
3633
+ n = o.unwrap().schemaName, i = o.unwrap().name;
3634
+ }
3635
+ if (!(t.body instanceof j)) {
3636
+ const o = this.refField(
3637
+ t.body,
3638
+ n,
3639
+ i,
3640
+ r,
3641
+ s
3642
+ );
3643
+ return o ? [o] : [];
3644
+ }
3645
+ const a = [];
3646
+ for (const o of t.body.body) {
3647
+ const u = this.refField(
3648
+ o,
3649
+ n,
3650
+ i,
3651
+ r,
3652
+ s
3653
+ );
3654
+ u && a.push(u);
3655
+ }
3656
+ return a;
3657
+ }
3658
+ refField(t, r, s, n, i) {
3659
+ const a = [t.callee, ...t.args], o = a[0], [u, h] = mt(o.op.value), b = We(o.leftExpression).unwrap(), p = We(o.rightExpression).unwrap();
3660
+ if (!this.logIfUnequalFields(o, b, p) || !this.logIfSameEndpoint(o, b, p) || !this.logIfCircularRefError(o, b, p))
3661
+ return;
3662
+ const f = $e(o.leftExpression, n, i), _ = $e(o.rightExpression, n, i);
3663
+ if (f instanceof w && this.errors.push(f), _ instanceof w && this.errors.push(_), f instanceof w || _ instanceof w)
3664
+ return;
3665
+ const v = {
3666
+ schemaName: f.schemaName,
3667
+ tableName: f.tableName,
3668
+ fieldNames: f.columnNames,
3669
+ relation: u,
3670
+ token: R(o.leftExpression)
3671
+ }, G = {
3672
+ schemaName: _.schemaName,
3673
+ tableName: _.tableName,
3674
+ fieldNames: _.columnNames,
3675
+ relation: h,
3676
+ token: R(o.rightExpression)
3677
+ };
3678
+ let me, ge;
3679
+ if (a.length === 2) {
3680
+ const Te = Le(a[1], this.errors);
3681
+ me = Te.extractDelete(), ge = Te.extractUpdate();
3682
+ }
3683
+ return {
3684
+ name: s,
3685
+ endpoints: [v, G],
3686
+ onDelete: me,
3687
+ onUpdate: ge,
3688
+ token: R(o),
3689
+ schemaName: r
3690
+ };
3691
+ }
3692
+ enum(t) {
3693
+ const r = this.extractElementName(t.name);
3694
+ if (!r.isOk())
3695
+ return;
3696
+ const { name: s, schemaName: n } = r.unwrap(), i = t.body.body.map(
3697
+ (a) => this.enumField(a)
3698
+ );
3699
+ return {
3700
+ name: s,
3701
+ schemaName: n,
3702
+ token: R(t),
3703
+ values: i
3704
+ };
3705
+ }
3706
+ enumField(t) {
3707
+ const r = [t.callee, ...t.args];
3708
+ let s, n;
3709
+ if (r.length === 2) {
3710
+ const i = Le(r[1], this.errors);
3711
+ s = i.extractNote(), n = i.settingMap.getAttributeNode("note");
3712
+ }
3713
+ return {
3714
+ name: W(r[0]).unwrap(),
3715
+ token: R(t),
3716
+ note: s === void 0 ? void 0 : {
3717
+ value: s,
3718
+ token: R(n)
3719
+ }
3720
+ };
3721
+ }
3722
+ project(t) {
3723
+ var s;
3724
+ const r = {
3725
+ name: ((s = t.name && W(t.name)) == null ? void 0 : s.unwrap()) || null,
3726
+ tables: [],
3727
+ refs: [],
3728
+ enums: [],
3729
+ tableGroups: [],
3730
+ note: void 0
3731
+ };
3732
+ return t.body.body.forEach((n) => {
3733
+ const i = n, a = i.type.value.toLowerCase();
3734
+ switch (a) {
3735
+ case "table":
3736
+ ie(this.table(i), r.tables);
3737
+ break;
3738
+ case "ref":
3739
+ r.refs.push(...this.ref(i, null, null));
3740
+ break;
3741
+ case "tablegroup":
3742
+ ie(this.tableGroup(i), r.tableGroups);
3743
+ break;
3744
+ case "enum":
3745
+ ie(this.enum(i), r.enums);
3746
+ break;
3747
+ case "note":
3748
+ r.note = this.note(i);
3749
+ break;
3750
+ default:
3751
+ r[a] = this.custom(i);
3752
+ break;
3753
+ }
3754
+ }), r;
3755
+ }
3756
+ // eslint-disable-next-line class-methods-use-this
3757
+ custom(t) {
3758
+ return fe(t.body.callee).unwrap_or("");
3759
+ }
3760
+ tableGroup(t) {
3761
+ const r = this.extractElementName(t.name);
3762
+ if (!r.isOk())
3763
+ return;
3764
+ const { name: s, schemaName: n } = r.unwrap(), i = [];
3765
+ for (const a of t.body.body) {
3766
+ const o = this.tableGroupField(a);
3767
+ o && i.push(o);
3768
+ }
3769
+ return {
3770
+ name: s,
3771
+ schemaName: n,
3772
+ tables: i,
3773
+ token: R(t)
3774
+ };
3775
+ }
3776
+ tableGroupField(t) {
3777
+ const r = this.extractElementName(t.callee);
3778
+ if (!r.isOk())
3779
+ return;
3780
+ const { name: s, schemaName: n } = r.unwrap();
3781
+ return {
3782
+ name: s,
3783
+ schemaName: n
3784
+ };
3785
+ }
3786
+ // eslint-disable-next-line class-methods-use-this
3787
+ note(t) {
3788
+ if (t.body instanceof j && t.body.body.length === 0)
3789
+ return;
3790
+ const r = t.body instanceof j ? fe(
3791
+ t.body.body[0].callee
3792
+ ) : fe(t.body.callee);
3793
+ return {
3794
+ value: Kt(r.unwrap()),
3795
+ token: R(t)
3796
+ };
3797
+ }
3798
+ indexes(t) {
3799
+ const r = [];
3800
+ for (const s of t.body.body) {
3801
+ const n = this.indexField(s);
3802
+ n && r.push(n);
3803
+ }
3804
+ return r;
3805
+ }
3806
+ indexField(t) {
3807
+ const r = [t.callee, ...t.args], { functional: s, nonFunctional: n } = Pt(r[0]).unwrap();
3808
+ let i, a, o, u, h, b;
3809
+ if (r.length === 2) {
3810
+ const p = Le(r[1], this.errors);
3811
+ i = p.extractPk(), a = p.extractUnique(), o = p.extractIdxName(), u = p.extractNote(), h = p.settingMap.getAttributeNode("note"), b = p.extractIndexType();
3812
+ }
3813
+ return {
3814
+ columns: [
3815
+ ...s.map((p) => ({
3816
+ value: p.value.value,
3817
+ type: "expression"
3818
+ })),
3819
+ ...n.map((p) => ({
3820
+ value: W(p).unwrap(),
3821
+ type: "column"
3822
+ }))
3823
+ ],
3824
+ token: R(t),
3825
+ type: b,
3826
+ pk: i,
3827
+ unique: a,
3828
+ name: o,
3829
+ note: u === void 0 ? void 0 : {
3830
+ value: u,
3831
+ token: R(h)
3832
+ }
3833
+ };
3834
+ }
3835
+ extractElementName(t) {
3836
+ const r = pe(t).unwrap(), s = r.pop(), n = r.pop();
3837
+ return r.length > 0 ? (this.logError(
3838
+ t,
3839
+ c.UNSUPPORTED,
3840
+ "Nested schemas are currently not allowed"
3841
+ ), new T()) : new I({
3842
+ name: s,
3843
+ // eslint-disable-next-line no-unneeded-ternary
3844
+ schemaName: n || null
3845
+ });
3846
+ }
3847
+ logIfUnequalFields(t, r, s) {
3848
+ return r.length !== s.length ? (this.logError(
3849
+ t,
3850
+ c.UNEQUAL_FIELDS_BINARY_REF,
3851
+ "Two endpoints have unequal number of fields"
3852
+ ), !1) : !0;
3853
+ }
3854
+ logIfSameEndpoint(t, r, s) {
3855
+ return bs(r, s) ? (this.logError(t, c.SAME_ENDPOINT, "Two endpoints are the same"), !1) : !0;
3856
+ }
3857
+ logIfCircularRefError(t, r, s) {
3858
+ return Ns(r, s, this.endpointPairSet) ? (this.logError(
3859
+ t,
3860
+ c.UNSUPPORTED,
3861
+ "Reference with the same endpoints already exists"
3862
+ ), !1) : !0;
3863
+ }
3864
+ logError(t, r, s) {
3865
+ this.errors.push(new w(r, s, t));
3866
+ }
3867
+ }
3868
+ function ie(e, t) {
3869
+ e !== void 0 && t.push(e);
3870
+ }
3871
+ var g = /* @__PURE__ */ ((e) => (e[e.Function = 1] = "Function", e[e.Constructor = 2] = "Constructor", e[e.Field = 3] = "Field", e[e.Variable = 4] = "Variable", e[e.Class = 5] = "Class", e[e.Struct = 6] = "Struct", e[e.Interface = 7] = "Interface", e[e.Module = 8] = "Module", e[e.Property = 9] = "Property", e[e.Event = 10] = "Event", e[e.Operator = 11] = "Operator", e[e.Unit = 12] = "Unit", e[e.Value = 13] = "Value", e[e.Constant = 14] = "Constant", e[e.Enum = 15] = "Enum", e[e.EnumMember = 16] = "EnumMember", e[e.Keyword = 17] = "Keyword", e[e.Text = 18] = "Text", e[e.Color = 19] = "Color", e[e.File = 20] = "File", e[e.Reference = 21] = "Reference", e[e.Customcolor = 22] = "Customcolor", e[e.Folder = 23] = "Folder", e[e.TypeParameter = 24] = "TypeParameter", e[e.User = 25] = "User", e[e.Issue = 26] = "Issue", e[e.Snippet = 27] = "Snippet", e))(g || {}), L = /* @__PURE__ */ ((e) => (e[e.None = 0] = "None", e[e.KeepWhitespace = 1] = "KeepWhitespace", e[e.InsertAsSnippet = 4] = "InsertAsSnippet", e))(L || {});
3872
+ function _e(e) {
3873
+ switch (e) {
3874
+ case N.Schema:
3875
+ return g.Module;
3876
+ case N.Table:
3877
+ return g.Class;
3878
+ case N.Column:
3879
+ return g.Field;
3880
+ case N.Enum:
3881
+ return g.Enum;
3882
+ case N.EnumField:
3883
+ return g.EnumMember;
3884
+ case N.TableGroup:
3885
+ return g.Struct;
3886
+ case N.TableGroupField:
3887
+ return g.Field;
3888
+ default:
3889
+ return g.Text;
3890
+ }
3891
+ }
3892
+ function Re(e, t) {
3893
+ if (!e || _t(e))
3894
+ return !1;
3895
+ for (const r of e.trailingTrivia) {
3896
+ if (r.start > t)
3897
+ break;
3898
+ if (r.kind === l.NEWLINE && r.end <= t)
3899
+ return !1;
3900
+ }
3901
+ return !0;
3902
+ }
3903
+ function y() {
3904
+ return {
3905
+ suggestions: []
3906
+ };
3907
+ }
3908
+ function De(e) {
3909
+ return {
3910
+ ...e,
3911
+ suggestions: e.suggestions.map((t) => ({
3912
+ ...t,
3913
+ insertText: ` ${t.insertText}`
3914
+ }))
3915
+ };
3916
+ }
3917
+ function Ue(e) {
3918
+ return {
3919
+ ...e,
3920
+ suggestions: e.suggestions.map((t) => ({
3921
+ ...t,
3922
+ insertText: t.insertText.search(/[^a-zA-Z\d_]/) !== -1 || t.insertText[0].match(/\d/) ? `"${t.insertText}"` : t.insertText
3923
+ }))
3924
+ };
3925
+ }
3926
+ function nt(e, t) {
3927
+ return e.getOffsetAt(t);
3928
+ }
3929
+ class Qt {
3930
+ constructor(t, r = []) {
3931
+ this.compiler = t, this.triggerCharacters = r;
3932
+ }
3933
+ provideCompletionItems(t, r) {
3934
+ var b, p;
3935
+ const s = nt(t, r), n = this.compiler.token.flatStream(), { token: i, index: a } = this.compiler.container.token(s), o = a === void 0 ? n[0] : n[a + 1];
3936
+ if ([
3937
+ ...(i == null ? void 0 : i.trailingTrivia) || [],
3938
+ ...(i == null ? void 0 : i.leadingTrivia) || [],
3939
+ ...(o == null ? void 0 : o.leadingTrivia) || []
3940
+ ].find((f) => rr(f) && Ae(s, f)))
3941
+ return y();
3942
+ if (a === void 0)
3943
+ return At();
3944
+ if ([l.STRING_LITERAL, l.QUOTED_STRING].includes(i.kind) && Ae(s, i))
3945
+ return y();
3946
+ const u = this.compiler.container.element(s);
3947
+ if (this.compiler.container.scopeKind(s) === k.TOPLEVEL || u instanceof A && u.type && u.type.start <= s && u.type.end >= s)
3948
+ return At();
3949
+ const h = [...this.compiler.container.stack(s)].reverse();
3950
+ for (const f of h)
3951
+ if (f instanceof z)
3952
+ switch ((b = f.op) == null ? void 0 : b.value) {
3953
+ case ">":
3954
+ case "<":
3955
+ case "<>":
3956
+ case "-":
3957
+ return Tt(
3958
+ this.compiler,
3959
+ s,
3960
+ f
3961
+ );
3962
+ }
3963
+ else if (f instanceof K)
3964
+ switch ((p = f.op) == null ? void 0 : p.value) {
3965
+ case ">":
3966
+ case "<":
3967
+ case "<>":
3968
+ case "-":
3969
+ return Tt(
3970
+ this.compiler,
3971
+ s,
3972
+ f
3973
+ );
3974
+ case ".":
3975
+ return Yt(
3976
+ this.compiler,
3977
+ s,
3978
+ f
3979
+ );
3980
+ }
3981
+ else {
3982
+ if (f instanceof xe)
3983
+ return It(this.compiler, s, f);
3984
+ if (f instanceof U)
3985
+ return It(this.compiler, s, f);
3986
+ if (f instanceof Q)
3987
+ return Ts(this.compiler, s);
3988
+ if (f instanceof te)
3989
+ return wt(this.compiler, s, f);
3990
+ if (f instanceof A && (f.bodyColon && s >= f.bodyColon.end || f.body && Ae(s, f.body)))
3991
+ return wt(this.compiler, s, void 0);
3992
+ }
3993
+ return y();
3994
+ }
3995
+ }
3996
+ function Tt(e, t, r) {
3997
+ const s = e.container.scopeKind(t);
3998
+ if ([k.REF, k.TABLE].includes(s)) {
3999
+ const n = Fe(e, t, e.container.element(t), [
4000
+ N.Table,
4001
+ N.Schema,
4002
+ N.Column
4003
+ ]);
4004
+ return Re(r.op, t) ? De(n) : n;
4005
+ }
4006
+ return y();
4007
+ }
4008
+ function Fe(e, t, r, s) {
4009
+ var a;
4010
+ if (r === void 0)
4011
+ return y();
4012
+ let n = r;
4013
+ const i = { suggestions: [] };
4014
+ for (; n; ) {
4015
+ if ((a = n == null ? void 0 : n.symbol) != null && a.symbolTable) {
4016
+ const { symbol: o } = n;
4017
+ i.suggestions.push(
4018
+ ...e.symbol.members(o).filter(({ kind: u }) => s.includes(u)).map(({ name: u, kind: h }) => ({
4019
+ label: u,
4020
+ insertText: u,
4021
+ insertTextRules: L.KeepWhitespace,
4022
+ kind: _e(h),
4023
+ sortText: _e(h).toString().padStart(2, "0"),
4024
+ range: void 0
4025
+ }))
4026
+ );
4027
+ }
4028
+ n = n instanceof A ? n.parent : void 0;
4029
+ }
4030
+ return Ue(i);
4031
+ }
4032
+ function Ts(e, t) {
4033
+ var s;
4034
+ switch (e.container.scopeKind(t)) {
4035
+ case k.INDEXES:
4036
+ return Jt(e, t);
4037
+ case k.REF:
4038
+ {
4039
+ const n = [...e.container.stack(t)];
4040
+ for (; n.length > 0; ) {
4041
+ const i = n.pop();
4042
+ if (i instanceof K && ((s = i.op) == null ? void 0 : s.value) === ".")
4043
+ return Yt(
4044
+ e,
4045
+ t,
4046
+ i
4047
+ );
4048
+ }
4049
+ }
4050
+ return Ht(e, t);
4051
+ }
4052
+ return y();
4053
+ }
4054
+ function It(e, t, r) {
4055
+ const { token: s } = e.container.token(t);
4056
+ if ([l.COMMA, l.LBRACKET].includes(s == null ? void 0 : s.kind)) {
4057
+ const n = Lt(e, t);
4058
+ return (s == null ? void 0 : s.kind) === l.COMMA && Re(s, t) ? De(n) : n;
4059
+ }
4060
+ if (r.name && r.name.start <= t && r.name.end >= t)
4061
+ return Lt(e, t);
4062
+ if (r.name) {
4063
+ const n = Is(
4064
+ e,
4065
+ t,
4066
+ le(r.name).unwrap()
4067
+ );
4068
+ return (s == null ? void 0 : s.kind) === l.COLON && Re(s, t) ? De(n) : n;
4069
+ }
4070
+ return y();
4071
+ }
4072
+ function Lt(e, t) {
4073
+ const r = e.container.element(t), s = e.container.scopeKind(t);
4074
+ if (r instanceof ae)
4075
+ return y();
4076
+ if (r.body && !Ae(t, r.body))
4077
+ switch (s) {
4078
+ case k.TABLE:
4079
+ return {
4080
+ suggestions: [
4081
+ {
4082
+ label: "headercolor",
4083
+ insertText: "headercolor: ",
4084
+ kind: g.Field,
4085
+ insertTextRules: L.KeepWhitespace,
4086
+ range: void 0
4087
+ },
4088
+ {
4089
+ label: "note",
4090
+ insertText: "note: ",
4091
+ kind: g.Field,
4092
+ insertTextRules: L.KeepWhitespace,
4093
+ range: void 0
4094
+ }
4095
+ ]
4096
+ };
4097
+ default:
4098
+ return y();
4099
+ }
4100
+ switch (s) {
4101
+ case k.TABLE:
4102
+ return {
4103
+ suggestions: [
4104
+ ...["primary key", "null", "not null", "increment", "pk", "unique"].map((n) => ({
4105
+ label: n,
4106
+ insertText: n,
4107
+ kind: g.Property,
4108
+ insertTextRules: L.KeepWhitespace,
4109
+ range: void 0
4110
+ })),
4111
+ ...["ref", "default"].map((n) => ({
4112
+ label: n,
4113
+ insertText: `${n}: `,
4114
+ kind: g.Property,
4115
+ insertTextRules: L.KeepWhitespace,
4116
+ range: void 0
4117
+ })),
4118
+ {
4119
+ label: "note",
4120
+ insertText: "note: ",
4121
+ kind: g.Property,
4122
+ insertTextRules: L.KeepWhitespace,
4123
+ range: void 0
4124
+ }
4125
+ ]
4126
+ };
4127
+ case k.ENUM:
4128
+ return {
4129
+ suggestions: [
4130
+ {
4131
+ label: "note",
4132
+ insertText: "note: ",
4133
+ kind: g.Property,
4134
+ insertTextRules: L.KeepWhitespace,
4135
+ range: void 0
4136
+ }
4137
+ ]
4138
+ };
4139
+ case k.INDEXES:
4140
+ return {
4141
+ suggestions: [
4142
+ ...["unique", "pk"].map((n) => ({
4143
+ label: n,
4144
+ insertText: n,
4145
+ insertTextRules: L.KeepWhitespace,
4146
+ kind: g.Property,
4147
+ range: void 0
4148
+ })),
4149
+ ...["note", "name", "type"].map((n) => ({
4150
+ label: n,
4151
+ insertText: `${n}: `,
4152
+ kind: g.Property,
4153
+ insertTextRules: L.KeepWhitespace,
4154
+ range: void 0
4155
+ }))
4156
+ ]
4157
+ };
4158
+ case k.REF:
4159
+ return {
4160
+ suggestions: ["update", "delete"].map((n) => ({
4161
+ label: n,
4162
+ insertText: `${n}: `,
4163
+ kind: g.Property,
4164
+ insertTextRules: L.KeepWhitespace,
4165
+ range: void 0
4166
+ }))
4167
+ };
4168
+ }
4169
+ return y();
4170
+ }
4171
+ function Is(e, t, r) {
4172
+ switch (r == null ? void 0 : r.toLowerCase()) {
4173
+ case "update":
4174
+ case "delete":
4175
+ return {
4176
+ suggestions: ["cascade", "set default", "set null", "restrict"].map((s) => ({
4177
+ label: s,
4178
+ insertText: s,
4179
+ kind: g.Value,
4180
+ insertTextRules: L.KeepWhitespace,
4181
+ range: void 0
4182
+ }))
4183
+ };
4184
+ case "type":
4185
+ return {
4186
+ suggestions: ["btree", "hash"].map((s) => ({
4187
+ label: s,
4188
+ insertText: `${s}`,
4189
+ kind: g.Value,
4190
+ insertTextRules: L.KeepWhitespace,
4191
+ range: void 0
4192
+ }))
4193
+ };
4194
+ }
4195
+ return y();
4196
+ }
4197
+ function Yt(e, t, r) {
4198
+ const s = Ee(r).unwrap_or([]);
4199
+ if (s.pop(), s.some((i) => !Y(i)))
4200
+ return y();
4201
+ const n = s.map((i) => Je(i).unwrap());
4202
+ return Ue({
4203
+ suggestions: e.symbol.ofName({ nameStack: n, owner: e.container.element(t) }).flatMap(({ symbol: i }) => e.symbol.members(i)).map(({ kind: i, name: a }) => ({
4204
+ label: a,
4205
+ insertText: a,
4206
+ kind: _e(i),
4207
+ range: void 0
4208
+ }))
4209
+ });
4210
+ }
4211
+ function wt(e, t, r) {
4212
+ var n;
4213
+ switch (e.container.scopeKind(t)) {
4214
+ case k.TABLE:
4215
+ return ws(e, t, r);
4216
+ case k.PROJECT:
4217
+ return As(e, t, r);
4218
+ case k.INDEXES:
4219
+ return _s(e, t);
4220
+ case k.ENUM:
4221
+ return Ls(e, t, r);
4222
+ case k.REF: {
4223
+ const i = Ht(e, t);
4224
+ return ((n = e.container.token(t).token) == null ? void 0 : n.kind) === l.COLON && Re(e.container.token(t).token, t) ? De(i) : i;
4225
+ }
4226
+ case k.TABLEGROUP:
4227
+ return xs(e);
4228
+ default:
4229
+ return y();
4230
+ }
4231
+ }
4232
+ function At() {
4233
+ return {
4234
+ suggestions: ["Table", "TableGroup", "Enum", "Project", "Ref"].map((e) => ({
4235
+ label: e,
4236
+ insertText: e,
4237
+ insertTextRules: L.KeepWhitespace,
4238
+ kind: g.Keyword,
4239
+ range: void 0
4240
+ }))
4241
+ };
4242
+ }
4243
+ function Ls(e, t, r) {
4244
+ return r != null && r.callee && it(t, r) === 1 ? Fe(e, t, e.container.element(t), [
4245
+ N.Schema,
4246
+ N.Table,
4247
+ N.Column
4248
+ ]) : y();
4249
+ }
4250
+ function ws(e, t, r) {
4251
+ if (!(r != null && r.callee))
4252
+ return {
4253
+ suggestions: ["Ref", "Note", "indexes"].map((n) => ({
4254
+ label: n,
4255
+ insertText: n,
4256
+ insertTextRules: L.KeepWhitespace,
4257
+ kind: g.Keyword,
4258
+ range: void 0
4259
+ }))
4260
+ };
4261
+ const s = it(t, r);
4262
+ return s === 0 ? {
4263
+ suggestions: ["Ref", "Note", "indexes"].map((n) => ({
4264
+ label: n,
4265
+ insertText: n,
4266
+ insertTextRules: L.KeepWhitespace,
4267
+ kind: g.Keyword,
4268
+ range: void 0
4269
+ }))
4270
+ } : s === 1 ? Os(e, t) : y();
4271
+ }
4272
+ function As(e, t, r) {
4273
+ return r != null && r.callee ? it(t, r) === 0 ? {
4274
+ suggestions: ["Table", "TableGroup", "Enum", "Note", "Ref"].map((n) => ({
4275
+ label: n,
4276
+ insertText: n,
4277
+ insertTextRules: L.KeepWhitespace,
4278
+ kind: g.Keyword,
4279
+ range: void 0
4280
+ }))
4281
+ } : y() : {
4282
+ suggestions: ["Table", "TableGroup", "Enum", "Note", "Ref"].map((n) => ({
4283
+ label: n,
4284
+ insertText: n,
4285
+ insertTextRules: L.KeepWhitespace,
4286
+ kind: g.Keyword,
4287
+ range: void 0
4288
+ }))
4289
+ };
4290
+ }
4291
+ function Ht(e, t) {
4292
+ return Fe(e, t, e.container.element(t), [
4293
+ N.Schema,
4294
+ N.Table,
4295
+ N.Column
4296
+ ]);
4297
+ }
4298
+ function xs(e) {
4299
+ return Ue({
4300
+ suggestions: [...e.parse.publicSymbolTable().entries()].flatMap(([t]) => {
4301
+ const r = ee(t).unwrap_or(void 0);
4302
+ if (r === void 0)
4303
+ return [];
4304
+ const { kind: s, name: n } = r;
4305
+ return s !== N.Table && s !== N.Schema ? [] : {
4306
+ label: n,
4307
+ insertText: n,
4308
+ insertTextRules: L.KeepWhitespace,
4309
+ kind: _e(s),
4310
+ range: void 0
4311
+ };
4312
+ })
4313
+ });
4314
+ }
4315
+ function _s(e, t) {
4316
+ return Jt(e, t);
4317
+ }
4318
+ function Os(e, t) {
4319
+ return {
4320
+ suggestions: [
4321
+ ...[
4322
+ "integer",
4323
+ "int",
4324
+ "tinyint",
4325
+ "smallint",
4326
+ "mediumint",
4327
+ "bigint",
4328
+ "bit",
4329
+ "bool",
4330
+ "binary",
4331
+ "varbinary",
4332
+ "logical",
4333
+ "char",
4334
+ "nchar",
4335
+ "varchar",
4336
+ "varchar2",
4337
+ "nvarchar",
4338
+ "nvarchar2",
4339
+ "binary_float",
4340
+ "binary_double",
4341
+ "float",
4342
+ "double",
4343
+ "decimal",
4344
+ "dec",
4345
+ "real",
4346
+ "money",
4347
+ "smallmoney",
4348
+ "enum",
4349
+ "tinyblob",
4350
+ "tinytext",
4351
+ "blob",
4352
+ "text",
4353
+ "mediumblob",
4354
+ "mediumtext",
4355
+ "longblob",
4356
+ "longtext",
4357
+ "ntext",
4358
+ "set",
4359
+ "inet6",
4360
+ "uuid",
4361
+ "image",
4362
+ "date",
4363
+ "time",
4364
+ "datetime",
4365
+ "datetime2",
4366
+ "timestamp",
4367
+ "year",
4368
+ "smalldatetime",
4369
+ "datetimeoffset",
4370
+ "XML",
4371
+ "sql_variant",
4372
+ "uniqueidentifier",
4373
+ "CURSOR",
4374
+ "BFILE",
4375
+ "CLOB",
4376
+ "NCLOB",
4377
+ "RAW"
4378
+ ].map((r) => ({
4379
+ label: r,
4380
+ insertText: r,
4381
+ insertTextRules: L.KeepWhitespace,
4382
+ kind: g.TypeParameter,
4383
+ sortText: g.TypeParameter.toString().padStart(2, "0"),
4384
+ range: void 0
4385
+ })),
4386
+ ...Fe(e, t, e.container.element(t), [
4387
+ N.Enum,
4388
+ N.Schema
4389
+ ]).suggestions
4390
+ ]
4391
+ };
4392
+ }
4393
+ function Jt(e, t) {
4394
+ const s = e.container.element(t).parent;
4395
+ if (!((s == null ? void 0 : s.symbol) instanceof Rt))
4396
+ return y();
4397
+ const { symbolTable: n } = s.symbol;
4398
+ return Ue({
4399
+ suggestions: [...n.entries()].flatMap(([i]) => {
4400
+ const a = ee(i).unwrap_or(void 0);
4401
+ if (a === void 0)
4402
+ return [];
4403
+ const { name: o } = a;
4404
+ return {
4405
+ label: o,
4406
+ insertText: o,
4407
+ insertTextRules: L.KeepWhitespace,
4408
+ kind: _e(N.Column),
4409
+ range: void 0
4410
+ };
4411
+ })
4412
+ });
4413
+ }
4414
+ function it(e, t) {
4415
+ if (!t.callee)
4416
+ return -1;
4417
+ const r = [t.callee, ...t.args], s = r.findIndex((n) => e <= n.end);
4418
+ return s === -1 ? r.length : s;
4419
+ }
4420
+ class Zt {
4421
+ constructor(t) {
4422
+ this.compiler = t;
4423
+ }
4424
+ provideDefinition(t, r) {
4425
+ var a;
4426
+ const { uri: s } = t, n = nt(t, r), i = [...this.compiler.container.stack(n)];
4427
+ for (; i.length !== 0; ) {
4428
+ const o = i.pop();
4429
+ if ((a = o == null ? void 0 : o.referee) != null && a.declaration && [de.PRIMARY_EXPRESSION, de.VARIABLE].includes(o == null ? void 0 : o.kind)) {
4430
+ const { startPos: u, endPos: h } = o.referee.declaration;
4431
+ return [
4432
+ {
4433
+ range: {
4434
+ startColumn: u.column + 1,
4435
+ startLineNumber: u.line + 1,
4436
+ endColumn: h.column + 1,
4437
+ endLineNumber: h.line + 1
4438
+ },
4439
+ uri: s
4440
+ }
4441
+ ];
4442
+ }
4443
+ }
4444
+ return [];
4445
+ }
4446
+ }
4447
+ class er {
4448
+ constructor(t) {
4449
+ this.compiler = t;
4450
+ }
4451
+ provideReferences(t, r) {
4452
+ const { uri: s } = t, n = nt(t, r), i = [...this.compiler.container.stack(n)];
4453
+ for (; i.length !== 0; ) {
4454
+ const a = i.pop();
4455
+ if (a && [
4456
+ de.ELEMENT_DECLARATION,
4457
+ de.FUNCTION_APPLICATION,
4458
+ de.PRIMARY_EXPRESSION
4459
+ ].includes(a == null ? void 0 : a.kind)) {
4460
+ const { symbol: o } = a;
4461
+ if (o != null && o.references.length)
4462
+ return o.references.map(({ startPos: u, endPos: h }) => ({
4463
+ range: {
4464
+ startColumn: u.column + 1,
4465
+ startLineNumber: u.line + 1,
4466
+ endColumn: h.column + 1,
4467
+ endLineNumber: h.line + 1
4468
+ },
4469
+ uri: s
4470
+ }));
4471
+ }
4472
+ }
4473
+ return [];
4474
+ }
4475
+ }
4476
+ const ks = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4477
+ __proto__: null,
4478
+ CompletionItemInsertTextRule: L,
4479
+ CompletionItemKind: g,
4480
+ DBMLCompletionItemProvider: Qt,
4481
+ DBMLDefinitionProvider: Zt,
4482
+ DBMLReferencesProvider: er
4483
+ }, Symbol.toStringTag, { value: "Module" }));
4484
+ var k = /* @__PURE__ */ ((e) => (e[e.TABLE = 0] = "TABLE", e[e.ENUM = 1] = "ENUM", e[e.TABLEGROUP = 2] = "TABLEGROUP", e[e.INDEXES = 3] = "INDEXES", e[e.NOTE = 4] = "NOTE", e[e.REF = 5] = "REF", e[e.PROJECT = 6] = "PROJECT", e[e.CUSTOM = 7] = "CUSTOM", e[e.TOPLEVEL = 8] = "TOPLEVEL", e))(k || {});
4485
+ class Ss {
4486
+ constructor() {
4487
+ this.source = "", this.cache = new Array(
4488
+ 16
4489
+ /* TOTAL_QUERY_COUNT */
4490
+ ).fill(null), this.nodeIdGenerator = new sr(), this.symbolIdGenerator = new or(), this.token = {
4491
+ invalidStream: this.createQuery(
4492
+ 6,
4493
+ () => this.parse.tokens().filter(Ct)
4494
+ ),
4495
+ // Valid + Invalid tokens (which are guarenteed to be non-trivials) are included in the stream
4496
+ flatStream: this.createQuery(
4497
+ 7,
4498
+ () => this.parse.tokens().flatMap((t) => [...t.leadingInvalid, t, ...t.trailingInvalid])
4499
+ )
4500
+ }, this.parse = {
4501
+ source: () => this.source,
4502
+ _: this.createQuery(
4503
+ 0,
4504
+ () => {
4505
+ const t = new Lr(this.source).lex().chain((r) => new xr(r, this.nodeIdGenerator).parse()).chain(({ ast: r, tokens: s }) => new ps(r, this.symbolIdGenerator).analyze().map(() => ({ ast: r, tokens: s })));
4506
+ return t.getErrors().length > 0 ? t : t.chain(({ ast: r, tokens: s }) => new gs(r).interpret().map((i) => ({ ast: r, tokens: s, rawDb: i })));
4507
+ }
4508
+ ),
4509
+ ast: this.createQuery(
4510
+ 1,
4511
+ () => this.parse._().getValue().ast
4512
+ ),
4513
+ errors: this.createQuery(2, () => {
4514
+ const t = [...this.parse._().getErrors()];
4515
+ return t.sort((r, s) => r.start - s.start), t;
4516
+ }),
4517
+ tokens: this.createQuery(
4518
+ 4,
4519
+ () => this.parse._().getValue().tokens
4520
+ ),
4521
+ rawDb: this.createQuery(
4522
+ 3,
4523
+ () => this.parse._().getValue().rawDb
4524
+ ),
4525
+ publicSymbolTable: this.createQuery(
4526
+ 5,
4527
+ () => this.parse._().getValue().ast.symbol.symbolTable
4528
+ )
4529
+ }, this.container = {
4530
+ stack: this.createQuery(
4531
+ 10,
4532
+ (t) => {
4533
+ const r = this.parse.tokens();
4534
+ let { index: s } = this.container.token(t);
4535
+ const { token: n } = this.container.token(t);
4536
+ if (s === void 0)
4537
+ return [this.parse.ast()];
4538
+ for (; r[s].isInvalid && s >= 0; )
4539
+ s -= 1;
4540
+ if (s === -1)
4541
+ return [this.parse.ast()];
4542
+ const i = r[s].start;
4543
+ let a = this.parse.ast();
4544
+ const o = [a];
4545
+ for (; ; ) {
4546
+ const h = Tr(a).find((b) => Ae(i, b));
4547
+ if (h === void 0 || h instanceof P)
4548
+ break;
4549
+ o.push(h), a = h;
4550
+ }
4551
+ if ((n == null ? void 0 : n.kind) === l.COLON)
4552
+ return o;
4553
+ for (; o.length > 0; ) {
4554
+ let u = !1;
4555
+ const h = C.last(o);
4556
+ if (h instanceof te) {
4557
+ const b = this.parse.source();
4558
+ for (let p = h.end; p < t; p += 1)
4559
+ b[p] === `
4560
+ ` && (o.pop(), u = !0);
4561
+ } else
4562
+ h instanceof z || h instanceof K ? this.container.token(t).token !== h.op && (o.pop(), u = !0) : h instanceof U ? h.listCloseBracket && h.end <= t && (o.pop(), u = !0) : h instanceof Q ? h.tupleCloseParen && h.end <= t && (o.pop(), u = !0) : h instanceof j ? h.blockCloseBrace && h.end <= t && (o.pop(), u = !0) : h instanceof q || h.end < t && (o.pop(), u = !0);
4563
+ if (u) {
4564
+ const b = C.last(o);
4565
+ b instanceof A && b.end <= t && o.pop();
4566
+ }
4567
+ if (!u)
4568
+ break;
4569
+ }
4570
+ return o;
4571
+ }
4572
+ ),
4573
+ token: this.createQuery(
4574
+ 11,
4575
+ (t) => {
4576
+ const r = this.token.flatStream().findIndex((s) => s.start >= t);
4577
+ return r === void 0 ? { token: void 0, index: void 0 } : r <= 0 ? { token: void 0, index: void 0 } : {
4578
+ token: this.token.flatStream()[r - 1],
4579
+ index: r - 1
4580
+ };
4581
+ }
4582
+ ),
4583
+ element: this.createQuery(
4584
+ 12,
4585
+ (t) => {
4586
+ const r = this.container.stack(t);
4587
+ for (let s = r.length - 1; s >= 0; s -= 1)
4588
+ if (r[s] instanceof A)
4589
+ return r[s];
4590
+ return this.parse.ast();
4591
+ }
4592
+ ),
4593
+ scope: this.createQuery(
4594
+ 14,
4595
+ (t) => {
4596
+ var r, s;
4597
+ return (s = (r = this.container.element(t)) == null ? void 0 : r.symbol) == null ? void 0 : s.symbolTable;
4598
+ }
4599
+ ),
4600
+ scopeKind: this.createQuery(15, (t) => {
4601
+ var s;
4602
+ if (this.container.element(t) instanceof ae)
4603
+ return 8;
4604
+ switch ((s = this.container.element(t).type) == null ? void 0 : s.value.toLowerCase()) {
4605
+ case "table":
4606
+ return 0;
4607
+ case "enum":
4608
+ return 1;
4609
+ case "ref":
4610
+ return 5;
4611
+ case "tablegroup":
4612
+ return 2;
4613
+ case "indexes":
4614
+ return 3;
4615
+ case "note":
4616
+ return 4;
4617
+ case "project":
4618
+ return 6;
4619
+ default:
4620
+ return 7;
4621
+ }
4622
+ })
4623
+ }, this.symbol = {
4624
+ // Given a stack of name and the current scope
4625
+ // Try looking up the first name in the stack in the current scope
4626
+ // and resolve the rest of the name stack as members
4627
+ // Then try to do the same with all ancestor scopes
4628
+ ofName: this.createQuery(
4629
+ 8,
4630
+ ({
4631
+ nameStack: t,
4632
+ owner: r = this.parse.ast()
4633
+ }) => {
4634
+ var n;
4635
+ if (t.length === 0)
4636
+ return [];
4637
+ const s = [];
4638
+ for (let i = r; i; i = i instanceof A ? i.parent : void 0) {
4639
+ if (!((n = i.symbol) != null && n.symbolTable))
4640
+ continue;
4641
+ const { symbolTable: a } = i.symbol;
4642
+ let o = [a], u = [];
4643
+ for (const h of t)
4644
+ u = o.flatMap(
4645
+ (b) => pr(h).flatMap((p) => {
4646
+ const f = b.get(p), _ = ee(p).unwrap_or(void 0);
4647
+ return !f || !_ ? [] : { ..._, symbol: f };
4648
+ })
4649
+ ), o = u.flatMap(
4650
+ (b) => b.symbol.symbolTable ? b.symbol.symbolTable : []
4651
+ );
4652
+ s.push(...u);
4653
+ }
4654
+ return s;
4655
+ },
4656
+ ({ nameStack: t, owner: r }) => `${t.join(".")}@${r.id}`
4657
+ ),
4658
+ members: this.createQuery(
4659
+ 9,
4660
+ (t) => t.symbolTable ? [...t.symbolTable.entries()].map(([r, s]) => ({
4661
+ ...ee(r).unwrap(),
4662
+ symbol: s
4663
+ })) : []
4664
+ )
4665
+ };
4666
+ }
4667
+ createQuery(t, r, s) {
4668
+ return (n) => {
4669
+ const i = this.cache[t], a = n && s ? s(n) : n;
4670
+ if (i !== null) {
4671
+ if (!(i instanceof Map))
4672
+ return i;
4673
+ if (i.has(a))
4674
+ return i.get(a);
4675
+ }
4676
+ const o = r(n);
4677
+ return n !== void 0 ? i instanceof Map ? i.set(a, o) : (this.cache[t] = /* @__PURE__ */ new Map(), this.cache[t].set(a, o)) : this.cache[t] = o, o;
4678
+ };
4679
+ }
4680
+ setSource(t) {
4681
+ this.source = t, this.cache = new Array(
4682
+ 16
4683
+ /* TOTAL_QUERY_COUNT */
4684
+ ).fill(null), this.nodeIdGenerator.reset(), this.symbolIdGenerator.reset();
4685
+ }
4686
+ initMonacoServices() {
4687
+ return {
4688
+ definitionProvider: new Zt(this),
4689
+ referenceProvider: new er(this),
4690
+ autocompletionProvider: new Qt(this)
4691
+ };
4692
+ }
4693
+ }
4694
+ export {
4695
+ Ss as Compiler,
4696
+ ys as serialize,
4697
+ ks as services
4698
+ };