@aeriajs/compiler 0.0.61 → 0.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast.d.ts +1 -0
- package/dist/ast.js +4 -6
- package/dist/codegen/generateContracts.js +15 -19
- package/dist/codegen/generateExports.js +5 -9
- package/dist/codegen/generateJSCollections.js +13 -17
- package/dist/codegen/generateTSCollections.js +13 -17
- package/dist/codegen/index.js +4 -20
- package/dist/codegen/utils.js +25 -37
- package/dist/codegen.js +8 -45
- package/dist/compile.js +19 -58
- package/dist/diagnostic.js +1 -5
- package/dist/guards.js +3 -41
- package/dist/index.js +7 -23
- package/dist/lexer.js +48 -52
- package/dist/parser.js +267 -297
- package/dist/semantic.js +31 -68
- package/dist/token.js +1 -4
- package/dist/types.js +1 -2
- package/dist/utils.js +1 -4
- package/package.json +6 -9
- package/dist/ast.mjs +0 -24
- package/dist/codegen/generateContracts.mjs +0 -85
- package/dist/codegen/generateExports.mjs +0 -42
- package/dist/codegen/generateJSCollections.mjs +0 -103
- package/dist/codegen/generateTSCollections.mjs +0 -114
- package/dist/codegen/index.mjs +0 -5
- package/dist/codegen/utils.mjs +0 -161
- package/dist/codegen.mjs +0 -54
- package/dist/compile.mjs +0 -69
- package/dist/diagnostic.mjs +0 -18
- package/dist/guards.mjs +0 -8
- package/dist/index.mjs +0 -8
- package/dist/lexer.mjs +0 -375
- package/dist/parser.mjs +0 -1297
- package/dist/semantic.mjs +0 -202
- package/dist/token.mjs +0 -24
- package/dist/types.mjs +0 -1
- package/dist/utils.mjs +0 -12
package/dist/parser.mjs
DELETED
|
@@ -1,1297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { DESCRIPTION_PRESETS, LAYOUT_NAMES, PROPERTY_ARRAY_ELEMENTS, PROPERTY_FORMATS, PROPERTY_INPUT_ELEMENTS, PROPERTY_INPUT_TYPES } from "@aeriajs/types";
|
|
3
|
-
import { icons } from "@phosphor-icons/core";
|
|
4
|
-
import * as AST from "./ast.mjs";
|
|
5
|
-
import * as guards from "./guards.mjs";
|
|
6
|
-
import * as lexer from "./lexer.mjs";
|
|
7
|
-
import { TokenType } from "./token.mjs";
|
|
8
|
-
import { Diagnostic } from "./diagnostic.mjs";
|
|
9
|
-
import { DEFAULT_EXPORT_SYMBOLS } from "./utils.mjs";
|
|
10
|
-
const MAX_ERROR_MESSAGE_ITEMS = 20;
|
|
11
|
-
const ICON_NAMES = icons.map((icon) => icon.name);
|
|
12
|
-
export const locationMap = /* @__PURE__ */ new WeakMap();
|
|
13
|
-
export const memoTable = {
|
|
14
|
-
defaultExportSymbols: DEFAULT_EXPORT_SYMBOLS
|
|
15
|
-
};
|
|
16
|
-
const isFileProperty = (property) => {
|
|
17
|
-
return property.$ref === "File";
|
|
18
|
-
};
|
|
19
|
-
const checkForValidRoles = (roles, symbols) => {
|
|
20
|
-
if (memoTable.roles) {
|
|
21
|
-
for (const [i, role] of roles.entries()) {
|
|
22
|
-
const symbol = symbols[i];
|
|
23
|
-
if (!memoTable.roles.includes(role)) {
|
|
24
|
-
const location = locationMap.get(symbol);
|
|
25
|
-
throw new Diagnostic(`invalid role "${role}"`, location);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return roles;
|
|
30
|
-
};
|
|
31
|
-
export const parse = (tokens) => {
|
|
32
|
-
let index = 0;
|
|
33
|
-
const ast = {
|
|
34
|
-
kind: "program",
|
|
35
|
-
collections: [],
|
|
36
|
-
contracts: [],
|
|
37
|
-
functionsets: []
|
|
38
|
-
};
|
|
39
|
-
const errors = [];
|
|
40
|
-
const advance = () => index++;
|
|
41
|
-
const rollback = () => index--;
|
|
42
|
-
const next = () => {
|
|
43
|
-
const token = tokens[index + 1];
|
|
44
|
-
if (!token) {
|
|
45
|
-
throw new Diagnostic("unexpected EOF", current().location);
|
|
46
|
-
}
|
|
47
|
-
return token;
|
|
48
|
-
};
|
|
49
|
-
const previous = () => {
|
|
50
|
-
const token = tokens[index - 1];
|
|
51
|
-
if (!token) {
|
|
52
|
-
throw new Diagnostic("invalid position");
|
|
53
|
-
}
|
|
54
|
-
return token;
|
|
55
|
-
};
|
|
56
|
-
const current = () => {
|
|
57
|
-
const token = tokens[index];
|
|
58
|
-
if (!token) {
|
|
59
|
-
throw new Diagnostic("unexpected EOF", previous().location);
|
|
60
|
-
}
|
|
61
|
-
return token;
|
|
62
|
-
};
|
|
63
|
-
const foldBrackets = () => {
|
|
64
|
-
if (match(TokenType.LeftBracket)) {
|
|
65
|
-
advance();
|
|
66
|
-
while (!match(TokenType.RightBracket)) {
|
|
67
|
-
foldBrackets();
|
|
68
|
-
advance();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const match = (expected, value) => {
|
|
73
|
-
const token = current();
|
|
74
|
-
if (token.type === expected) {
|
|
75
|
-
if (value !== void 0) {
|
|
76
|
-
return Array.isArray(value) ? value.includes(token.value) : token.value === value;
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
return false;
|
|
81
|
-
};
|
|
82
|
-
const consume = (expected, value) => {
|
|
83
|
-
const token = current();
|
|
84
|
-
if (match(expected, value)) {
|
|
85
|
-
advance();
|
|
86
|
-
return token;
|
|
87
|
-
}
|
|
88
|
-
let expectedValue;
|
|
89
|
-
if (value) {
|
|
90
|
-
expectedValue = Array.isArray(value) ? value.slice(0, MAX_ERROR_MESSAGE_ITEMS).map((elem) => `"${elem}"`).join(" | ") : `"${value}"`;
|
|
91
|
-
}
|
|
92
|
-
if (Array.isArray(value) && value.length > MAX_ERROR_MESSAGE_ITEMS) {
|
|
93
|
-
expectedValue += " | ...";
|
|
94
|
-
}
|
|
95
|
-
throw new Diagnostic(
|
|
96
|
-
expectedValue ? `expected ${expected} with value ${expectedValue} but found ${token.type} with value "${token.value}" instead` : `expected ${expected} but found ${token.type} instead`,
|
|
97
|
-
token.location
|
|
98
|
-
);
|
|
99
|
-
};
|
|
100
|
-
const recover = (keywords) => {
|
|
101
|
-
let token;
|
|
102
|
-
while (token = tokens[++index]) {
|
|
103
|
-
if (token.type === TokenType.Keyword && keywords.includes(token.value)) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const parseArray = (types) => {
|
|
109
|
-
const array = [];
|
|
110
|
-
const symbols = [];
|
|
111
|
-
const { location: openingLocation } = consume(TokenType.LeftSquareBracket);
|
|
112
|
-
if (match(TokenType.RightSquareBracket)) {
|
|
113
|
-
consume(TokenType.RightSquareBracket);
|
|
114
|
-
return {
|
|
115
|
-
value: [],
|
|
116
|
-
symbols: []
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
let type;
|
|
120
|
-
for (const typeCandidate of types) {
|
|
121
|
-
if (match(typeCandidate)) {
|
|
122
|
-
type = typeCandidate;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (!type) {
|
|
127
|
-
throw new Diagnostic(`array got an invalid type, accepted ones are: ${types.join(" | ")}`, openingLocation);
|
|
128
|
-
}
|
|
129
|
-
while (!match(TokenType.RightSquareBracket)) {
|
|
130
|
-
const { value, location } = consume(type);
|
|
131
|
-
const elemSymbol = Symbol();
|
|
132
|
-
array.push(value);
|
|
133
|
-
symbols.push(elemSymbol);
|
|
134
|
-
locationMap.set(elemSymbol, location);
|
|
135
|
-
if (match(TokenType.Comma)) {
|
|
136
|
-
consume(TokenType.Comma);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
consume(TokenType.RightSquareBracket);
|
|
140
|
-
return {
|
|
141
|
-
value: array,
|
|
142
|
-
symbols
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
const parseArrayBlock = (value) => {
|
|
146
|
-
const array = [];
|
|
147
|
-
const symbols = [];
|
|
148
|
-
consume(TokenType.LeftBracket);
|
|
149
|
-
while (!match(TokenType.RightBracket)) {
|
|
150
|
-
const { value: identifier, location } = consume(TokenType.Identifier, value);
|
|
151
|
-
const elemSymbol = Symbol();
|
|
152
|
-
array.push(identifier);
|
|
153
|
-
symbols.push(elemSymbol);
|
|
154
|
-
locationMap.set(elemSymbol, location);
|
|
155
|
-
if (match(TokenType.Comma)) {
|
|
156
|
-
consume(TokenType.Comma);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
consume(TokenType.RightBracket);
|
|
160
|
-
return {
|
|
161
|
-
value: array,
|
|
162
|
-
symbols
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
const parseArrayBlockWithAttributes = (allowedAttributes, cb) => {
|
|
166
|
-
const array = {};
|
|
167
|
-
const symbols = [];
|
|
168
|
-
let hasAttributes = false;
|
|
169
|
-
consume(TokenType.LeftBracket);
|
|
170
|
-
while (!match(TokenType.RightBracket)) {
|
|
171
|
-
const { value: identifier, location } = consume(TokenType.Identifier);
|
|
172
|
-
array[identifier] = true;
|
|
173
|
-
const elemSymbol = Symbol();
|
|
174
|
-
symbols.push(elemSymbol);
|
|
175
|
-
locationMap.set(elemSymbol, location);
|
|
176
|
-
if (match(TokenType.AttributeName)) {
|
|
177
|
-
hasAttributes = true;
|
|
178
|
-
}
|
|
179
|
-
while (match(TokenType.AttributeName)) {
|
|
180
|
-
array[identifier] = {};
|
|
181
|
-
const { value: attributeName } = consume(TokenType.AttributeName, allowedAttributes);
|
|
182
|
-
cb(attributeName, array, identifier);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
consume(TokenType.RightBracket);
|
|
186
|
-
const value = hasAttributes ? array : Object.keys(array);
|
|
187
|
-
return {
|
|
188
|
-
value,
|
|
189
|
-
symbols
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
const parsePropertyAttributeValue = (attributeName, property, location) => {
|
|
193
|
-
const consumeBoolean = () => {
|
|
194
|
-
if (match(TokenType.Boolean)) {
|
|
195
|
-
const { value } = consume(TokenType.Boolean);
|
|
196
|
-
return value;
|
|
197
|
-
}
|
|
198
|
-
return true;
|
|
199
|
-
};
|
|
200
|
-
if ("enum" in property && attributeName === "values") {
|
|
201
|
-
property.enum = parseArray([
|
|
202
|
-
TokenType.QuotedString,
|
|
203
|
-
TokenType.Number
|
|
204
|
-
]).value;
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if ("const" in property && attributeName === "value") {
|
|
208
|
-
const token = current();
|
|
209
|
-
advance();
|
|
210
|
-
switch (token.type) {
|
|
211
|
-
case TokenType.Number:
|
|
212
|
-
case TokenType.Boolean:
|
|
213
|
-
case TokenType.Null:
|
|
214
|
-
case TokenType.QuotedString: {
|
|
215
|
-
property.const = token.value;
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
default: {
|
|
219
|
-
throw new Diagnostic(`const received invalid value: "${token.value}"`, location);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
switch (attributeName) {
|
|
224
|
-
case "icon": {
|
|
225
|
-
const { value } = consume(TokenType.QuotedString, ICON_NAMES);
|
|
226
|
-
property[attributeName] = value;
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
case "hint":
|
|
230
|
-
case "description": {
|
|
231
|
-
const { value } = consume(TokenType.QuotedString);
|
|
232
|
-
property[attributeName] = value;
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
case "hidden":
|
|
236
|
-
case "translate": {
|
|
237
|
-
property[attributeName] = consumeBoolean();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if ("$ref" in property) {
|
|
242
|
-
switch (attributeName) {
|
|
243
|
-
case "purge":
|
|
244
|
-
case "inline": {
|
|
245
|
-
property[attributeName] = consumeBoolean();
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
case "select":
|
|
249
|
-
case "form":
|
|
250
|
-
case "populate":
|
|
251
|
-
case "indexes": {
|
|
252
|
-
property[attributeName] = parseArray([TokenType.Identifier]).value;
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
case "populateDepth": {
|
|
256
|
-
const { value } = consume(TokenType.Number);
|
|
257
|
-
property[attributeName] = value;
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
case "constraints": {
|
|
261
|
-
const constraintTerms = [];
|
|
262
|
-
rollback();
|
|
263
|
-
property[attributeName] = parseCondition(constraintTerms);
|
|
264
|
-
property[AST.LOCATION_SYMBOL].contraintTerms = constraintTerms;
|
|
265
|
-
rollback();
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
if (isFileProperty(property)) {
|
|
270
|
-
switch (attributeName) {
|
|
271
|
-
case "extensions":
|
|
272
|
-
case "accept": {
|
|
273
|
-
property[attributeName] = parseArray([TokenType.QuotedString]).value;
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if ("type" in property) {
|
|
280
|
-
switch (property.type) {
|
|
281
|
-
case "string": {
|
|
282
|
-
switch (attributeName) {
|
|
283
|
-
case "format": {
|
|
284
|
-
const { value } = consume(TokenType.QuotedString, PROPERTY_FORMATS);
|
|
285
|
-
property[attributeName] = value;
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
case "mask": {
|
|
289
|
-
if (match(TokenType.LeftSquareBracket)) {
|
|
290
|
-
property[attributeName] = parseArray([TokenType.QuotedString]).value;
|
|
291
|
-
return;
|
|
292
|
-
} else {
|
|
293
|
-
const { value } = consume(TokenType.QuotedString);
|
|
294
|
-
property[attributeName] = value;
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
case "maskedValue": {
|
|
299
|
-
const { value } = consume(TokenType.Boolean);
|
|
300
|
-
property[attributeName] = value;
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
case "minLength":
|
|
304
|
-
case "maxLength": {
|
|
305
|
-
const { value } = consume(TokenType.Number);
|
|
306
|
-
property[attributeName] = value;
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
case "inputType": {
|
|
310
|
-
const { value } = consume(TokenType.QuotedString, PROPERTY_INPUT_TYPES);
|
|
311
|
-
property[attributeName] = value;
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
case "element": {
|
|
315
|
-
const { value } = consume(TokenType.QuotedString, PROPERTY_INPUT_ELEMENTS);
|
|
316
|
-
property[attributeName] = value;
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
case "placeholder": {
|
|
320
|
-
const { value } = consume(TokenType.QuotedString);
|
|
321
|
-
property[attributeName] = value;
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
case "integer":
|
|
328
|
-
case "number": {
|
|
329
|
-
switch (attributeName) {
|
|
330
|
-
case "exclusiveMinimum":
|
|
331
|
-
case "exclusiveMaximum":
|
|
332
|
-
case "minimum":
|
|
333
|
-
case "maximum": {
|
|
334
|
-
const { value } = consume(TokenType.Number);
|
|
335
|
-
property[attributeName] = value;
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
case "placeholder": {
|
|
339
|
-
const { value } = consume(TokenType.QuotedString);
|
|
340
|
-
property[attributeName] = value;
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case "array": {
|
|
347
|
-
switch (attributeName) {
|
|
348
|
-
case "uniqueItems": {
|
|
349
|
-
const { value } = consume(TokenType.Boolean);
|
|
350
|
-
property[attributeName] = value;
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
case "element": {
|
|
354
|
-
const { value } = consume(TokenType.QuotedString, PROPERTY_ARRAY_ELEMENTS);
|
|
355
|
-
property[attributeName] = value;
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
throw new Diagnostic(`invalid attribute name "${attributeName}"`, location);
|
|
363
|
-
};
|
|
364
|
-
const parsePropertyType = (options = {
|
|
365
|
-
allowModifiers: false
|
|
366
|
-
}) => {
|
|
367
|
-
let property;
|
|
368
|
-
let nestedProperties;
|
|
369
|
-
let nestedAdditionalProperties;
|
|
370
|
-
let modifierToken;
|
|
371
|
-
const typeSymbol = Symbol();
|
|
372
|
-
if (options.allowModifiers) {
|
|
373
|
-
const nextToken = next();
|
|
374
|
-
const currentTokenValue = current().value;
|
|
375
|
-
if (match(TokenType.Identifier) && typeof currentTokenValue === "string" && guards.isValidPropertyModifier(currentTokenValue) && (nextToken.type === TokenType.LeftBracket || nextToken.type === TokenType.LeftSquareBracket || nextToken.type === TokenType.Identifier)) {
|
|
376
|
-
modifierToken = consume(TokenType.Identifier);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
if (match(TokenType.LeftSquareBracket)) {
|
|
380
|
-
consume(TokenType.LeftSquareBracket);
|
|
381
|
-
const arrayProperty = {
|
|
382
|
-
type: "array"
|
|
383
|
-
};
|
|
384
|
-
while (!match(TokenType.RightSquareBracket)) {
|
|
385
|
-
const attributeSymbol = Symbol();
|
|
386
|
-
arrayProperty[AST.LOCATION_SYMBOL] ??= {
|
|
387
|
-
type: typeSymbol,
|
|
388
|
-
attributes: {},
|
|
389
|
-
arrays: {}
|
|
390
|
-
};
|
|
391
|
-
if (match(TokenType.Range)) {
|
|
392
|
-
const { value: rangeSeparator } = consume(TokenType.Range);
|
|
393
|
-
let attributeName2;
|
|
394
|
-
const minItems = rangeSeparator[0];
|
|
395
|
-
if (!isNaN(minItems)) {
|
|
396
|
-
attributeName2 = "minItems";
|
|
397
|
-
arrayProperty[attributeName2] = minItems, arrayProperty[AST.LOCATION_SYMBOL].attributes[attributeName2] = attributeSymbol;
|
|
398
|
-
}
|
|
399
|
-
const maxItems = rangeSeparator[1];
|
|
400
|
-
if (!isNaN(maxItems)) {
|
|
401
|
-
attributeName2 = "maxItems";
|
|
402
|
-
arrayProperty[attributeName2] = maxItems;
|
|
403
|
-
arrayProperty[AST.LOCATION_SYMBOL].attributes[attributeName2] = attributeSymbol;
|
|
404
|
-
}
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
const { value: attributeName, location } = consume(TokenType.AttributeName);
|
|
408
|
-
if (match(TokenType.LeftParens)) {
|
|
409
|
-
consume(TokenType.LeftParens);
|
|
410
|
-
locationMap.set(attributeSymbol, next().location);
|
|
411
|
-
arrayProperty[AST.LOCATION_SYMBOL].attributes[attributeName] = attributeSymbol;
|
|
412
|
-
parsePropertyAttributeValue(attributeName, arrayProperty, location);
|
|
413
|
-
consume(TokenType.RightParens);
|
|
414
|
-
} else {
|
|
415
|
-
parsePropertyAttributeValue(attributeName, arrayProperty, location);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
consume(TokenType.RightSquareBracket);
|
|
419
|
-
const { property: items, nestedProperties: nestedProperties2 } = parsePropertyType(options);
|
|
420
|
-
property = {
|
|
421
|
-
...arrayProperty,
|
|
422
|
-
items
|
|
423
|
-
};
|
|
424
|
-
locationMap.set(typeSymbol, current().location);
|
|
425
|
-
return {
|
|
426
|
-
kind: "property",
|
|
427
|
-
property,
|
|
428
|
-
nestedProperties: nestedProperties2
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
locationMap.set(typeSymbol, current().location);
|
|
432
|
-
if (match(TokenType.LeftBracket)) {
|
|
433
|
-
consume(TokenType.LeftBracket);
|
|
434
|
-
property = {
|
|
435
|
-
type: "object",
|
|
436
|
-
properties: {},
|
|
437
|
-
[AST.LOCATION_SYMBOL]: {
|
|
438
|
-
type: typeSymbol,
|
|
439
|
-
attributes: {},
|
|
440
|
-
arrays: {}
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
while (!match(TokenType.RightBracket)) {
|
|
444
|
-
const { value: keyword, location } = consume(TokenType.Keyword, lexer.COLLECTION_KEYWORDS);
|
|
445
|
-
switch (keyword) {
|
|
446
|
-
case "writable":
|
|
447
|
-
case "required": {
|
|
448
|
-
const { value, symbols } = parseArrayBlock();
|
|
449
|
-
property[keyword] = value;
|
|
450
|
-
property[AST.LOCATION_SYMBOL].arrays[keyword] = symbols;
|
|
451
|
-
break;
|
|
452
|
-
}
|
|
453
|
-
case "properties": {
|
|
454
|
-
nestedProperties = parsePropertiesBlock(options);
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
case "additionalProperties": {
|
|
458
|
-
if (match(TokenType.Boolean)) {
|
|
459
|
-
nestedAdditionalProperties = consume(TokenType.Boolean).value;
|
|
460
|
-
} else {
|
|
461
|
-
nestedAdditionalProperties = parsePropertyType();
|
|
462
|
-
}
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
default:
|
|
466
|
-
throw new Diagnostic(`invalid keyword "${keyword}"`, location);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
consume(TokenType.RightBracket);
|
|
470
|
-
} else {
|
|
471
|
-
const { value: identifier } = consume(TokenType.Identifier);
|
|
472
|
-
if (guards.isNativePropertyType(identifier)) {
|
|
473
|
-
switch (identifier) {
|
|
474
|
-
case "enum": {
|
|
475
|
-
property = {
|
|
476
|
-
enum: []
|
|
477
|
-
};
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
case "const": {
|
|
481
|
-
property = {
|
|
482
|
-
const: null
|
|
483
|
-
};
|
|
484
|
-
break;
|
|
485
|
-
}
|
|
486
|
-
case "date": {
|
|
487
|
-
property = {
|
|
488
|
-
type: "string",
|
|
489
|
-
format: "date"
|
|
490
|
-
};
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
case "datetime": {
|
|
494
|
-
property = {
|
|
495
|
-
type: "string",
|
|
496
|
-
format: "date-time"
|
|
497
|
-
};
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
default:
|
|
501
|
-
property = {
|
|
502
|
-
type: AST.PropertyType[identifier]
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
} else {
|
|
506
|
-
property = {
|
|
507
|
-
$ref: identifier,
|
|
508
|
-
[AST.LOCATION_SYMBOL]: {
|
|
509
|
-
type: typeSymbol,
|
|
510
|
-
attributes: {},
|
|
511
|
-
arrays: {}
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
while (match(TokenType.AttributeName)) {
|
|
517
|
-
const { value: attributeName, location } = consume(TokenType.AttributeName);
|
|
518
|
-
if (match(TokenType.LeftParens)) {
|
|
519
|
-
consume(TokenType.LeftParens);
|
|
520
|
-
const attributeSymbol = Symbol();
|
|
521
|
-
locationMap.set(attributeSymbol, next().location);
|
|
522
|
-
property[AST.LOCATION_SYMBOL] ??= {
|
|
523
|
-
type: typeSymbol,
|
|
524
|
-
attributes: {},
|
|
525
|
-
arrays: {}
|
|
526
|
-
};
|
|
527
|
-
property[AST.LOCATION_SYMBOL].attributes[attributeName] = attributeSymbol;
|
|
528
|
-
parsePropertyAttributeValue(attributeName, property, location);
|
|
529
|
-
consume(TokenType.RightParens);
|
|
530
|
-
} else {
|
|
531
|
-
parsePropertyAttributeValue(attributeName, property, location);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
const node = {
|
|
535
|
-
kind: "property",
|
|
536
|
-
property,
|
|
537
|
-
nestedProperties,
|
|
538
|
-
nestedAdditionalProperties
|
|
539
|
-
};
|
|
540
|
-
if (modifierToken) {
|
|
541
|
-
node.modifier = modifierToken.value;
|
|
542
|
-
}
|
|
543
|
-
return node;
|
|
544
|
-
};
|
|
545
|
-
const parsePropertiesBlock = (options = {
|
|
546
|
-
allowModifiers: false
|
|
547
|
-
}) => {
|
|
548
|
-
consume(TokenType.LeftBracket);
|
|
549
|
-
const properties = {};
|
|
550
|
-
while (!match(TokenType.RightBracket)) {
|
|
551
|
-
try {
|
|
552
|
-
const { value: propName } = consume(TokenType.Identifier);
|
|
553
|
-
properties[propName] = parsePropertyType(options);
|
|
554
|
-
if (match(TokenType.Comma)) {
|
|
555
|
-
consume(TokenType.Comma);
|
|
556
|
-
}
|
|
557
|
-
} catch (err) {
|
|
558
|
-
if (err instanceof Diagnostic) {
|
|
559
|
-
errors.push(err);
|
|
560
|
-
recoverLoop: for (; ; ) {
|
|
561
|
-
switch (current().type) {
|
|
562
|
-
case TokenType.RightBracket:
|
|
563
|
-
case TokenType.Identifier: {
|
|
564
|
-
break recoverLoop;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
while (match(TokenType.AttributeName)) {
|
|
568
|
-
advance();
|
|
569
|
-
if (match(TokenType.LeftParens)) {
|
|
570
|
-
advance();
|
|
571
|
-
while (!match(TokenType.RightParens)) {
|
|
572
|
-
advance();
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
advance();
|
|
577
|
-
foldBrackets();
|
|
578
|
-
}
|
|
579
|
-
continue;
|
|
580
|
-
}
|
|
581
|
-
throw err;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
consume(TokenType.RightBracket);
|
|
585
|
-
return properties;
|
|
586
|
-
};
|
|
587
|
-
const parseMultiplePropertyTypes = (options = {
|
|
588
|
-
allowModifiers: false
|
|
589
|
-
}) => {
|
|
590
|
-
if (match(TokenType.Pipe)) {
|
|
591
|
-
consume(TokenType.Pipe);
|
|
592
|
-
const properties = [];
|
|
593
|
-
while (index < tokens.length) {
|
|
594
|
-
properties.push(parsePropertyType(options));
|
|
595
|
-
if (match(TokenType.Pipe)) {
|
|
596
|
-
consume(TokenType.Pipe);
|
|
597
|
-
} else {
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return properties;
|
|
602
|
-
}
|
|
603
|
-
return parsePropertyType(options);
|
|
604
|
-
};
|
|
605
|
-
const parseAccessCondition = (options = {
|
|
606
|
-
arrayBlock: false
|
|
607
|
-
}) => {
|
|
608
|
-
if (match(TokenType.Boolean)) {
|
|
609
|
-
const { value } = consume(TokenType.Boolean);
|
|
610
|
-
return value;
|
|
611
|
-
} else if (match(TokenType.QuotedString, [
|
|
612
|
-
"unauthenticated",
|
|
613
|
-
"unauthenticated-only"
|
|
614
|
-
])) {
|
|
615
|
-
const { value } = consume(TokenType.QuotedString, [
|
|
616
|
-
"unauthenticated",
|
|
617
|
-
"unauthenticated-only"
|
|
618
|
-
]);
|
|
619
|
-
return value;
|
|
620
|
-
} else {
|
|
621
|
-
const { value, symbols } = options.arrayBlock ? parseArrayBlock() : parseArray([TokenType.QuotedString]);
|
|
622
|
-
return checkForValidRoles(value, symbols);
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
const parseCollection = () => {
|
|
626
|
-
consume(TokenType.Keyword, "collection");
|
|
627
|
-
const { value: name } = consume(TokenType.Identifier);
|
|
628
|
-
const node = {
|
|
629
|
-
kind: "collection",
|
|
630
|
-
name,
|
|
631
|
-
properties: {},
|
|
632
|
-
[AST.LOCATION_SYMBOL]: {
|
|
633
|
-
arrays: {}
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
if (match(TokenType.Keyword, "extends")) {
|
|
637
|
-
consume(TokenType.Keyword);
|
|
638
|
-
const { value: packageName } = match(TokenType.QuotedString) ? consume(TokenType.QuotedString) : consume(TokenType.Identifier);
|
|
639
|
-
consume(TokenType.Dot);
|
|
640
|
-
const { value: symbolName } = consume(TokenType.Identifier);
|
|
641
|
-
node.extends = {
|
|
642
|
-
packageName,
|
|
643
|
-
importPath: packageName,
|
|
644
|
-
symbolName: symbolName[0].toLowerCase() + symbolName.slice(1)
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
consume(TokenType.LeftBracket);
|
|
648
|
-
while (!match(TokenType.RightBracket)) {
|
|
649
|
-
const { value: keyword } = consume(TokenType.Keyword, lexer.COLLECTION_KEYWORDS);
|
|
650
|
-
try {
|
|
651
|
-
switch (keyword) {
|
|
652
|
-
case "middlewares": {
|
|
653
|
-
node.middlewares = parseArrayBlock().value;
|
|
654
|
-
break;
|
|
655
|
-
}
|
|
656
|
-
case "owned": {
|
|
657
|
-
if (match(TokenType.Boolean)) {
|
|
658
|
-
node.owned = consume(TokenType.Boolean).value;
|
|
659
|
-
} else {
|
|
660
|
-
node.owned = consume(TokenType.QuotedString, [
|
|
661
|
-
"always",
|
|
662
|
-
"on-write"
|
|
663
|
-
]).value;
|
|
664
|
-
}
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
case "icon": {
|
|
668
|
-
const { value } = consume(TokenType.QuotedString, ICON_NAMES);
|
|
669
|
-
node[keyword] = value;
|
|
670
|
-
break;
|
|
671
|
-
}
|
|
672
|
-
case "properties": {
|
|
673
|
-
node[keyword] = parsePropertiesBlock();
|
|
674
|
-
break;
|
|
675
|
-
}
|
|
676
|
-
case "functions": {
|
|
677
|
-
const { functions, functionSets } = parseFunctionsBlock();
|
|
678
|
-
node.functions = functions;
|
|
679
|
-
node.functionSets = functionSets;
|
|
680
|
-
break;
|
|
681
|
-
}
|
|
682
|
-
case "individualActions":
|
|
683
|
-
case "actions": {
|
|
684
|
-
node[keyword] = parseActionsBlock();
|
|
685
|
-
break;
|
|
686
|
-
}
|
|
687
|
-
case "required": {
|
|
688
|
-
const { value, symbols } = parseArrayBlockWithAttributes(["if"], (attributeName, array, identifier) => {
|
|
689
|
-
switch (attributeName) {
|
|
690
|
-
case "if": {
|
|
691
|
-
const ifTerms = [];
|
|
692
|
-
array[identifier] = parseCondition(ifTerms);
|
|
693
|
-
node[AST.LOCATION_SYMBOL].requiredTerms = ifTerms;
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
node.required = value;
|
|
699
|
-
node[AST.LOCATION_SYMBOL].required = symbols;
|
|
700
|
-
break;
|
|
701
|
-
}
|
|
702
|
-
case "presets": {
|
|
703
|
-
const { value, symbols } = parseArrayBlock(DESCRIPTION_PRESETS);
|
|
704
|
-
node[keyword] = value;
|
|
705
|
-
node[AST.LOCATION_SYMBOL].arrays[keyword] = symbols;
|
|
706
|
-
break;
|
|
707
|
-
}
|
|
708
|
-
case "indexes":
|
|
709
|
-
case "form":
|
|
710
|
-
case "table":
|
|
711
|
-
case "tableMeta":
|
|
712
|
-
case "unique":
|
|
713
|
-
case "filters": {
|
|
714
|
-
const { value, symbols } = parseArrayBlock();
|
|
715
|
-
node[keyword] = value;
|
|
716
|
-
node[AST.LOCATION_SYMBOL].arrays[keyword] = symbols;
|
|
717
|
-
break;
|
|
718
|
-
}
|
|
719
|
-
case "search": {
|
|
720
|
-
const { options, indexesSymbols } = parseSearchBlock();
|
|
721
|
-
node[keyword] = options;
|
|
722
|
-
node[AST.LOCATION_SYMBOL].searchIndexes = indexesSymbols;
|
|
723
|
-
break;
|
|
724
|
-
}
|
|
725
|
-
case "layout": {
|
|
726
|
-
node[keyword] = parseLayoutBlock();
|
|
727
|
-
break;
|
|
728
|
-
}
|
|
729
|
-
case "formLayout": {
|
|
730
|
-
node[keyword] = parseFormLayoutBlock();
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
} catch (err) {
|
|
735
|
-
if (err instanceof Diagnostic) {
|
|
736
|
-
errors.push(err);
|
|
737
|
-
recover(lexer.COLLECTION_KEYWORDS);
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
throw err;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
consume(TokenType.RightBracket);
|
|
744
|
-
return node;
|
|
745
|
-
};
|
|
746
|
-
const parseContract = () => {
|
|
747
|
-
consume(TokenType.Keyword, "contract");
|
|
748
|
-
const { value: name } = consume(TokenType.Identifier);
|
|
749
|
-
consume(TokenType.LeftBracket);
|
|
750
|
-
const node = {
|
|
751
|
-
kind: "contract",
|
|
752
|
-
name
|
|
753
|
-
};
|
|
754
|
-
while (!match(TokenType.RightBracket)) {
|
|
755
|
-
const { value: keyword } = consume(TokenType.Keyword, lexer.CONTRACT_KEYWORDS);
|
|
756
|
-
switch (keyword) {
|
|
757
|
-
case "roles": {
|
|
758
|
-
node.roles = parseAccessCondition({
|
|
759
|
-
arrayBlock: true
|
|
760
|
-
});
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
763
|
-
case "payload": {
|
|
764
|
-
node.payload = parsePropertyType({
|
|
765
|
-
allowModifiers: true
|
|
766
|
-
});
|
|
767
|
-
break;
|
|
768
|
-
}
|
|
769
|
-
case "query": {
|
|
770
|
-
node.query = parsePropertyType({
|
|
771
|
-
allowModifiers: true
|
|
772
|
-
});
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
case "response": {
|
|
776
|
-
node.response = parseMultiplePropertyTypes({
|
|
777
|
-
allowModifiers: true
|
|
778
|
-
});
|
|
779
|
-
break;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
consume(TokenType.RightBracket);
|
|
784
|
-
return node;
|
|
785
|
-
};
|
|
786
|
-
const parseFunctionsBlock = () => {
|
|
787
|
-
consume(TokenType.LeftBracket);
|
|
788
|
-
const functions = [];
|
|
789
|
-
const functionSets = [];
|
|
790
|
-
while (!match(TokenType.RightBracket)) {
|
|
791
|
-
try {
|
|
792
|
-
if (match(TokenType.MacroName)) {
|
|
793
|
-
const { value: macroName } = consume(TokenType.MacroName, ["include"]);
|
|
794
|
-
switch (macroName) {
|
|
795
|
-
case "include": {
|
|
796
|
-
const { value: functionSetName, location } = consume(TokenType.Identifier);
|
|
797
|
-
const functionSetSymbol = Symbol();
|
|
798
|
-
locationMap.set(functionSetSymbol, location);
|
|
799
|
-
functionSets.push([
|
|
800
|
-
functionSetName,
|
|
801
|
-
functionSetSymbol
|
|
802
|
-
]);
|
|
803
|
-
consume(TokenType.RightParens);
|
|
804
|
-
break;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
let functionNode;
|
|
810
|
-
if (current().type === TokenType.Identifier && next().type === TokenType.Dot) {
|
|
811
|
-
const { value: packageName } = match(TokenType.QuotedString) ? consume(TokenType.QuotedString) : consume(TokenType.Identifier);
|
|
812
|
-
consume(TokenType.Dot);
|
|
813
|
-
const { value: symbolName } = consume(TokenType.Identifier);
|
|
814
|
-
functionNode = {
|
|
815
|
-
kind: "function",
|
|
816
|
-
name: symbolName,
|
|
817
|
-
exportSymbol: {
|
|
818
|
-
packageName,
|
|
819
|
-
importPath: packageName,
|
|
820
|
-
symbolName
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
} else {
|
|
824
|
-
const { value: functionName } = consume(TokenType.Identifier);
|
|
825
|
-
let exportSymbol;
|
|
826
|
-
if (memoTable.defaultExportSymbols && functionName in memoTable.defaultExportSymbols) {
|
|
827
|
-
const packageName = memoTable.defaultExportSymbols[functionName];
|
|
828
|
-
exportSymbol = {
|
|
829
|
-
packageName,
|
|
830
|
-
importPath: packageName,
|
|
831
|
-
symbolName: functionName
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
functionNode = {
|
|
835
|
-
kind: "function",
|
|
836
|
-
name: functionName,
|
|
837
|
-
exportSymbol
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
functions.push(functionNode);
|
|
841
|
-
while (match(TokenType.AttributeName, "expose")) {
|
|
842
|
-
consume(TokenType.AttributeName, "expose");
|
|
843
|
-
if (match(TokenType.LeftParens)) {
|
|
844
|
-
consume(TokenType.LeftParens);
|
|
845
|
-
functionNode.accessCondition = parseAccessCondition();
|
|
846
|
-
consume(TokenType.RightParens);
|
|
847
|
-
} else {
|
|
848
|
-
functionNode.accessCondition = true;
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
} catch (err) {
|
|
852
|
-
if (err instanceof Diagnostic) {
|
|
853
|
-
let token;
|
|
854
|
-
while (token = tokens[++index]) {
|
|
855
|
-
if (token.type === TokenType.Identifier || token.type === TokenType.RightBracket) {
|
|
856
|
-
break;
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
errors.push(err);
|
|
860
|
-
continue;
|
|
861
|
-
}
|
|
862
|
-
throw err;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
consume(TokenType.RightBracket);
|
|
866
|
-
return {
|
|
867
|
-
functions,
|
|
868
|
-
functionSets
|
|
869
|
-
};
|
|
870
|
-
};
|
|
871
|
-
const parseFunctionSet = () => {
|
|
872
|
-
consume(TokenType.Keyword, "functionset");
|
|
873
|
-
const { value: name } = consume(TokenType.Identifier);
|
|
874
|
-
const { functions, functionSets } = parseFunctionsBlock();
|
|
875
|
-
const node = {
|
|
876
|
-
kind: "functionset",
|
|
877
|
-
name,
|
|
878
|
-
functions,
|
|
879
|
-
functionSets
|
|
880
|
-
};
|
|
881
|
-
return node;
|
|
882
|
-
};
|
|
883
|
-
const parseActionsBlock = () => {
|
|
884
|
-
const actions = {};
|
|
885
|
-
consume(TokenType.LeftBracket);
|
|
886
|
-
while (!match(TokenType.RightBracket)) {
|
|
887
|
-
const { value: actionName } = consume(TokenType.Identifier);
|
|
888
|
-
consume(TokenType.LeftBracket);
|
|
889
|
-
const baseSlots = {};
|
|
890
|
-
const slots = {
|
|
891
|
-
route: {
|
|
892
|
-
route: {
|
|
893
|
-
name: ""
|
|
894
|
-
}
|
|
895
|
-
},
|
|
896
|
-
function: {},
|
|
897
|
-
event: {}
|
|
898
|
-
};
|
|
899
|
-
let actionType;
|
|
900
|
-
while (!match(TokenType.RightBracket)) {
|
|
901
|
-
const { value: keyword } = consume(TokenType.Keyword, lexer.COLLECTION_ACTIONS_KEYWORDS);
|
|
902
|
-
switch (keyword) {
|
|
903
|
-
case "icon": {
|
|
904
|
-
const { value } = consume(TokenType.QuotedString, ICON_NAMES);
|
|
905
|
-
baseSlots[keyword] = value;
|
|
906
|
-
break;
|
|
907
|
-
}
|
|
908
|
-
case "label": {
|
|
909
|
-
const { value } = consume(TokenType.QuotedString);
|
|
910
|
-
baseSlots[keyword] = value;
|
|
911
|
-
break;
|
|
912
|
-
}
|
|
913
|
-
case "ask":
|
|
914
|
-
case "button":
|
|
915
|
-
case "translate": {
|
|
916
|
-
const { value } = consume(TokenType.Boolean);
|
|
917
|
-
baseSlots[keyword] = value;
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
case "roles": {
|
|
921
|
-
const { value, symbols } = parseArray([TokenType.Identifier]);
|
|
922
|
-
const roles = checkForValidRoles(value, symbols);
|
|
923
|
-
baseSlots[keyword] = roles;
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
926
|
-
case "requires": {
|
|
927
|
-
const { value } = parseArrayBlock();
|
|
928
|
-
baseSlots[keyword] = value;
|
|
929
|
-
break;
|
|
930
|
-
}
|
|
931
|
-
case "route": {
|
|
932
|
-
const { value } = consume(TokenType.QuotedString);
|
|
933
|
-
actionType = "route";
|
|
934
|
-
slots.route.route.name = value;
|
|
935
|
-
break;
|
|
936
|
-
}
|
|
937
|
-
case "setItem":
|
|
938
|
-
case "fetchItem":
|
|
939
|
-
case "clearItem": {
|
|
940
|
-
const { value } = consume(TokenType.Boolean);
|
|
941
|
-
slots.route.route[keyword] = value;
|
|
942
|
-
break;
|
|
943
|
-
}
|
|
944
|
-
case "function": {
|
|
945
|
-
const { value } = consume(TokenType.QuotedString);
|
|
946
|
-
actionType = "function";
|
|
947
|
-
slots.function.function = value;
|
|
948
|
-
break;
|
|
949
|
-
}
|
|
950
|
-
case "effect": {
|
|
951
|
-
const { value } = consume(TokenType.QuotedString);
|
|
952
|
-
slots.function.effect = value;
|
|
953
|
-
break;
|
|
954
|
-
}
|
|
955
|
-
case "selection": {
|
|
956
|
-
const { value } = consume(TokenType.Boolean);
|
|
957
|
-
slots.function.selection = value;
|
|
958
|
-
break;
|
|
959
|
-
}
|
|
960
|
-
case "event": {
|
|
961
|
-
const { value } = consume(TokenType.QuotedString);
|
|
962
|
-
actionType = "event";
|
|
963
|
-
slots.event.event = value;
|
|
964
|
-
break;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
if (actionType) {
|
|
969
|
-
actions[actionName] = {
|
|
970
|
-
...baseSlots,
|
|
971
|
-
...slots[actionType]
|
|
972
|
-
};
|
|
973
|
-
} else {
|
|
974
|
-
actions[actionName] = baseSlots;
|
|
975
|
-
}
|
|
976
|
-
consume(TokenType.RightBracket);
|
|
977
|
-
}
|
|
978
|
-
consume(TokenType.RightBracket);
|
|
979
|
-
return actions;
|
|
980
|
-
};
|
|
981
|
-
const parseSearchBlock = () => {
|
|
982
|
-
const searchSlots = {};
|
|
983
|
-
const { location } = consume(TokenType.LeftBracket);
|
|
984
|
-
let indexesSymbols;
|
|
985
|
-
while (!match(TokenType.RightBracket)) {
|
|
986
|
-
const { value: keyword } = consume(TokenType.Keyword, lexer.COLLECTION_SEARCH_KEYWORDS);
|
|
987
|
-
switch (keyword) {
|
|
988
|
-
case "indexes": {
|
|
989
|
-
const { value, symbols } = parseArrayBlock();
|
|
990
|
-
searchSlots[keyword] = value;
|
|
991
|
-
indexesSymbols = symbols;
|
|
992
|
-
break;
|
|
993
|
-
}
|
|
994
|
-
case "placeholder": {
|
|
995
|
-
const { value } = consume(TokenType.QuotedString);
|
|
996
|
-
searchSlots[keyword] = value;
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
case "exactMatches": {
|
|
1000
|
-
const { value } = consume(TokenType.Boolean);
|
|
1001
|
-
searchSlots[keyword] = value;
|
|
1002
|
-
break;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
const { indexes } = searchSlots;
|
|
1007
|
-
if (!indexes) {
|
|
1008
|
-
throw new Diagnostic('"indexes" option is required', location);
|
|
1009
|
-
}
|
|
1010
|
-
consume(TokenType.RightBracket);
|
|
1011
|
-
const options = {
|
|
1012
|
-
...searchSlots,
|
|
1013
|
-
indexes
|
|
1014
|
-
};
|
|
1015
|
-
return {
|
|
1016
|
-
options,
|
|
1017
|
-
indexesSymbols
|
|
1018
|
-
};
|
|
1019
|
-
};
|
|
1020
|
-
const parseLayoutBlock = () => {
|
|
1021
|
-
let name;
|
|
1022
|
-
const options = {};
|
|
1023
|
-
const optionsSymbols = {};
|
|
1024
|
-
const { location } = consume(TokenType.LeftBracket);
|
|
1025
|
-
while (!match(TokenType.RightBracket)) {
|
|
1026
|
-
const { value: keyword } = consume(TokenType.Keyword, lexer.COLLECTION_LAYOUT_KEYWORDS);
|
|
1027
|
-
switch (keyword) {
|
|
1028
|
-
case "name": {
|
|
1029
|
-
name = consume(TokenType.QuotedString, LAYOUT_NAMES).value;
|
|
1030
|
-
break;
|
|
1031
|
-
}
|
|
1032
|
-
case "options":
|
|
1033
|
-
{
|
|
1034
|
-
consume(TokenType.LeftBracket);
|
|
1035
|
-
while (!match(TokenType.RightBracket)) {
|
|
1036
|
-
const { value: optionsKeyword } = consume(TokenType.Keyword, lexer.COLLECTION_LAYOUT_OPTIONS_KEYWORDS);
|
|
1037
|
-
switch (optionsKeyword) {
|
|
1038
|
-
case "active":
|
|
1039
|
-
case "title":
|
|
1040
|
-
case "picture":
|
|
1041
|
-
case "badge": {
|
|
1042
|
-
const { value, location: location2 } = consume(TokenType.Identifier);
|
|
1043
|
-
const symbol = Symbol();
|
|
1044
|
-
options[optionsKeyword] = value;
|
|
1045
|
-
optionsSymbols[optionsKeyword] = symbol;
|
|
1046
|
-
locationMap.set(symbol, location2);
|
|
1047
|
-
break;
|
|
1048
|
-
}
|
|
1049
|
-
case "information": {
|
|
1050
|
-
if (match(TokenType.LeftBracket)) {
|
|
1051
|
-
const { value, symbols } = parseArrayBlock();
|
|
1052
|
-
options[optionsKeyword] = value;
|
|
1053
|
-
optionsSymbols[optionsKeyword] = symbols;
|
|
1054
|
-
} else {
|
|
1055
|
-
const { value, location: location2 } = consume(TokenType.Identifier);
|
|
1056
|
-
const symbol = Symbol();
|
|
1057
|
-
options[optionsKeyword] = value;
|
|
1058
|
-
optionsSymbols[optionsKeyword] = symbol;
|
|
1059
|
-
locationMap.set(symbol, location2);
|
|
1060
|
-
}
|
|
1061
|
-
break;
|
|
1062
|
-
}
|
|
1063
|
-
case "translateBadge": {
|
|
1064
|
-
const { value } = consume(TokenType.Boolean);
|
|
1065
|
-
options[optionsKeyword] = value;
|
|
1066
|
-
break;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
consume(TokenType.RightBracket);
|
|
1072
|
-
break;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
if (!name) {
|
|
1076
|
-
throw new Diagnostic('layout must have a "name" property', location);
|
|
1077
|
-
}
|
|
1078
|
-
consume(TokenType.RightBracket);
|
|
1079
|
-
return {
|
|
1080
|
-
kind: "layout",
|
|
1081
|
-
name,
|
|
1082
|
-
options,
|
|
1083
|
-
[AST.LOCATION_SYMBOL]: {
|
|
1084
|
-
options: optionsSymbols
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
};
|
|
1088
|
-
const parseFormLayoutBlock = () => {
|
|
1089
|
-
const fields = {};
|
|
1090
|
-
const node = {
|
|
1091
|
-
kind: "formLayout",
|
|
1092
|
-
fields,
|
|
1093
|
-
[AST.LOCATION_SYMBOL]: {
|
|
1094
|
-
fields: {}
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
consume(TokenType.LeftBracket);
|
|
1098
|
-
while (!match(TokenType.RightBracket)) {
|
|
1099
|
-
const { value: keyword, location: keywordLocation } = consume(TokenType.Keyword, lexer.COLLECTION_FORM_LAYOUT_KEYWORDS);
|
|
1100
|
-
switch (keyword) {
|
|
1101
|
-
case "fields": {
|
|
1102
|
-
consume(TokenType.LeftBracket);
|
|
1103
|
-
while (!match(TokenType.RightBracket)) {
|
|
1104
|
-
const { value: identifier, location: identifierLocation } = consume(TokenType.Identifier);
|
|
1105
|
-
const identifierSymbol = Symbol();
|
|
1106
|
-
locationMap.set(identifierSymbol, identifierLocation);
|
|
1107
|
-
fields[identifier] ??= {};
|
|
1108
|
-
node[AST.LOCATION_SYMBOL].fields[identifier] = {
|
|
1109
|
-
name: identifierSymbol,
|
|
1110
|
-
field: {}
|
|
1111
|
-
};
|
|
1112
|
-
consume(TokenType.LeftBracket);
|
|
1113
|
-
while (!match(TokenType.RightBracket)) {
|
|
1114
|
-
const { value: keyword2, location: keywordLocation2 } = consume(TokenType.Keyword, lexer.COLLECTION_FORM_LAYOUT_KEYWORDS);
|
|
1115
|
-
switch (keyword2) {
|
|
1116
|
-
case "if": {
|
|
1117
|
-
const ifTerms = [];
|
|
1118
|
-
fields[identifier].if = parseCondition(ifTerms);
|
|
1119
|
-
node[AST.LOCATION_SYMBOL].terms = ifTerms;
|
|
1120
|
-
break;
|
|
1121
|
-
}
|
|
1122
|
-
case "span":
|
|
1123
|
-
case "verticalSpacing": {
|
|
1124
|
-
fields[identifier].span = consume(TokenType.Number).value;
|
|
1125
|
-
break;
|
|
1126
|
-
}
|
|
1127
|
-
case "separator": {
|
|
1128
|
-
fields[identifier].separator = match(TokenType.Boolean) ? consume(TokenType.Boolean).value : consume(TokenType.QuotedString, [
|
|
1129
|
-
"top",
|
|
1130
|
-
"bottom"
|
|
1131
|
-
]).value;
|
|
1132
|
-
break;
|
|
1133
|
-
}
|
|
1134
|
-
default: {
|
|
1135
|
-
throw new Diagnostic(`invalid keyword "${keyword2}"`, keywordLocation2);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
consume(TokenType.RightBracket);
|
|
1140
|
-
}
|
|
1141
|
-
consume(TokenType.RightBracket);
|
|
1142
|
-
break;
|
|
1143
|
-
}
|
|
1144
|
-
default: {
|
|
1145
|
-
throw new Diagnostic(`invalid keyword "${keyword}"`, keywordLocation);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
consume(TokenType.RightBracket);
|
|
1150
|
-
return node;
|
|
1151
|
-
};
|
|
1152
|
-
const parseCondition = (symbols = []) => {
|
|
1153
|
-
if (match(TokenType.LeftParens)) {
|
|
1154
|
-
consume(TokenType.LeftParens);
|
|
1155
|
-
let operatorType, newOp = operatorType;
|
|
1156
|
-
const conditions = [];
|
|
1157
|
-
while (!match(TokenType.RightParens)) {
|
|
1158
|
-
conditions.push(parseCondition(symbols));
|
|
1159
|
-
if (match(TokenType.RightParens)) {
|
|
1160
|
-
break;
|
|
1161
|
-
}
|
|
1162
|
-
const { value: operatorSymbol2, location: location2 } = consume(TokenType.Operator);
|
|
1163
|
-
switch (operatorSymbol2) {
|
|
1164
|
-
case "&&":
|
|
1165
|
-
newOp = "and";
|
|
1166
|
-
break;
|
|
1167
|
-
case "||":
|
|
1168
|
-
newOp = "or";
|
|
1169
|
-
break;
|
|
1170
|
-
default: {
|
|
1171
|
-
throw new Diagnostic(`unsupported operator: "${operatorSymbol2}"`, location2);
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
if (operatorType && operatorType !== newOp) {
|
|
1175
|
-
throw new Diagnostic('having "and" or "or" in the same expression is not supported, please use parenthesis', location2);
|
|
1176
|
-
}
|
|
1177
|
-
operatorType = newOp;
|
|
1178
|
-
}
|
|
1179
|
-
consume(TokenType.RightParens);
|
|
1180
|
-
switch (operatorType) {
|
|
1181
|
-
case "and": {
|
|
1182
|
-
return {
|
|
1183
|
-
and: conditions
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
case "or": {
|
|
1187
|
-
return {
|
|
1188
|
-
or: conditions
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
default: {
|
|
1192
|
-
return conditions[0];
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
if (match(TokenType.Operator, "!")) {
|
|
1197
|
-
consume(TokenType.Operator);
|
|
1198
|
-
return {
|
|
1199
|
-
not: parseCondition(symbols)
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
const { value: term1, location: term1Location } = consume(TokenType.Identifier);
|
|
1203
|
-
const term1Symbol = Symbol();
|
|
1204
|
-
locationMap.set(term1Symbol, term1Location);
|
|
1205
|
-
symbols.push([
|
|
1206
|
-
term1,
|
|
1207
|
-
term1Symbol
|
|
1208
|
-
]);
|
|
1209
|
-
if (!match(TokenType.Operator, lexer.FINAL_OPERATORS)) {
|
|
1210
|
-
return {
|
|
1211
|
-
operator: "truthy",
|
|
1212
|
-
term1
|
|
1213
|
-
};
|
|
1214
|
-
}
|
|
1215
|
-
const { value: operatorSymbol, location } = consume(TokenType.Operator);
|
|
1216
|
-
let term2;
|
|
1217
|
-
if (match(TokenType.LeftParens)) {
|
|
1218
|
-
term2 = parseCondition(symbols);
|
|
1219
|
-
} else if (match(TokenType.LeftSquareBracket)) {
|
|
1220
|
-
term2 = parseArray([
|
|
1221
|
-
TokenType.QuotedString,
|
|
1222
|
-
TokenType.Number
|
|
1223
|
-
]).value;
|
|
1224
|
-
} else {
|
|
1225
|
-
term2 = current().value;
|
|
1226
|
-
advance();
|
|
1227
|
-
}
|
|
1228
|
-
let operator;
|
|
1229
|
-
switch (operatorSymbol) {
|
|
1230
|
-
case "==":
|
|
1231
|
-
operator = "equal";
|
|
1232
|
-
break;
|
|
1233
|
-
case "in":
|
|
1234
|
-
operator = "in";
|
|
1235
|
-
break;
|
|
1236
|
-
case ">=":
|
|
1237
|
-
operator = "gte";
|
|
1238
|
-
break;
|
|
1239
|
-
case "<=":
|
|
1240
|
-
operator = "lte";
|
|
1241
|
-
break;
|
|
1242
|
-
case ">":
|
|
1243
|
-
operator = "gt";
|
|
1244
|
-
break;
|
|
1245
|
-
case "<":
|
|
1246
|
-
operator = "lt";
|
|
1247
|
-
break;
|
|
1248
|
-
default: {
|
|
1249
|
-
throw new Diagnostic(`unsupported operator: "${operatorSymbol}"`, location);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
return {
|
|
1253
|
-
operator,
|
|
1254
|
-
term1,
|
|
1255
|
-
term2
|
|
1256
|
-
};
|
|
1257
|
-
};
|
|
1258
|
-
while (index < tokens.length) {
|
|
1259
|
-
const { value: declType, location } = current();
|
|
1260
|
-
try {
|
|
1261
|
-
switch (declType) {
|
|
1262
|
-
case "collection": {
|
|
1263
|
-
const collection = parseCollection();
|
|
1264
|
-
if (collection.name === "User") {
|
|
1265
|
-
const { properties } = collection;
|
|
1266
|
-
if ("roles" in properties && "items" in properties.roles.property && "enum" in properties.roles.property.items) {
|
|
1267
|
-
memoTable.roles = properties.roles.property.items.enum;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
ast.collections.push(collection);
|
|
1271
|
-
break;
|
|
1272
|
-
}
|
|
1273
|
-
case "contract": {
|
|
1274
|
-
ast.contracts.push(parseContract());
|
|
1275
|
-
break;
|
|
1276
|
-
}
|
|
1277
|
-
case "functionset": {
|
|
1278
|
-
ast.functionsets.push(parseFunctionSet());
|
|
1279
|
-
break;
|
|
1280
|
-
}
|
|
1281
|
-
default:
|
|
1282
|
-
throw new Diagnostic(`invalid declaration type: "${declType}"`, location);
|
|
1283
|
-
}
|
|
1284
|
-
} catch (err) {
|
|
1285
|
-
if (err instanceof Diagnostic) {
|
|
1286
|
-
errors.push(err);
|
|
1287
|
-
recover(lexer.TOPLEVEL_KEYWORDS);
|
|
1288
|
-
continue;
|
|
1289
|
-
}
|
|
1290
|
-
throw err;
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
return {
|
|
1294
|
-
ast,
|
|
1295
|
-
errors
|
|
1296
|
-
};
|
|
1297
|
-
};
|