@traqula/core 0.0.15 → 0.0.16
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/lib/{CoreFactory.d.ts → AstCoreFactory.d.ts} +1 -1
- package/lib/{CoreFactory.js → AstCoreFactory.js} +2 -2
- package/lib/AstCoreFactory.js.map +1 -0
- package/lib/generator-builder/dynamicGenerator.d.ts +7 -3
- package/lib/generator-builder/dynamicGenerator.js +50 -5
- package/lib/generator-builder/dynamicGenerator.js.map +1 -1
- package/lib/generator-builder/generatorTypes.d.ts +1 -0
- package/lib/generator-builder/generatorTypes.js.map +1 -1
- package/lib/index.cjs +755 -714
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +1 -0
- package/lib/utils.js.map +1 -1
- package/package.json +2 -2
- package/lib/CoreFactory.js.map +0 -1
package/lib/index.cjs
CHANGED
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// lib/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
AstCoreFactory: () => AstCoreFactory,
|
|
24
24
|
GeneratorBuilder: () => GeneratorBuilder,
|
|
25
25
|
IndirBuilder: () => IndirBuilder,
|
|
26
26
|
LexerBuilder: () => LexerBuilder,
|
|
@@ -29,12 +29,13 @@ __export(index_exports, {
|
|
|
29
29
|
TransformerType: () => TransformerType,
|
|
30
30
|
createToken: () => createToken2,
|
|
31
31
|
listToIndirectionMap: () => listToIndirectionMap,
|
|
32
|
+
traqulaIndentation: () => traqulaIndentation,
|
|
32
33
|
unCapitalize: () => unCapitalize
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(index_exports);
|
|
35
36
|
|
|
36
|
-
// lib/
|
|
37
|
-
var
|
|
37
|
+
// lib/AstCoreFactory.js
|
|
38
|
+
var AstCoreFactory = class {
|
|
38
39
|
wrap(val, loc) {
|
|
39
40
|
return { val, loc };
|
|
40
41
|
}
|
|
@@ -160,421 +161,114 @@ var CoreFactory = class {
|
|
|
160
161
|
}
|
|
161
162
|
};
|
|
162
163
|
|
|
163
|
-
//
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
setContext(context) {
|
|
188
|
-
this.__context = context;
|
|
189
|
-
}
|
|
190
|
-
getSafeContext() {
|
|
191
|
-
return this.__context;
|
|
164
|
+
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
165
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
166
|
+
var freeGlobal_default = freeGlobal;
|
|
167
|
+
|
|
168
|
+
// ../../node_modules/lodash-es/_root.js
|
|
169
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
170
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
171
|
+
var root_default = root;
|
|
172
|
+
|
|
173
|
+
// ../../node_modules/lodash-es/_Symbol.js
|
|
174
|
+
var Symbol2 = root_default.Symbol;
|
|
175
|
+
var Symbol_default = Symbol2;
|
|
176
|
+
|
|
177
|
+
// ../../node_modules/lodash-es/_getRawTag.js
|
|
178
|
+
var objectProto = Object.prototype;
|
|
179
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
180
|
+
var nativeObjectToString = objectProto.toString;
|
|
181
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
182
|
+
function getRawTag(value) {
|
|
183
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
184
|
+
try {
|
|
185
|
+
value[symToStringTag] = void 0;
|
|
186
|
+
var unmasked = true;
|
|
187
|
+
} catch (e) {
|
|
192
188
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
const generate = () => def.gImpl({
|
|
199
|
-
SUBRULE: this.subrule,
|
|
200
|
-
PRINT: this.print,
|
|
201
|
-
PRINT_SPACE_LEFT: this.printSpaceLeft,
|
|
202
|
-
PRINT_WORD: this.printWord,
|
|
203
|
-
PRINT_WORDS: this.printWords,
|
|
204
|
-
CATCHUP: this.catchup,
|
|
205
|
-
HANDLE_LOC: this.handleLoc
|
|
206
|
-
})(ast, this.getSafeContext(), ...arg);
|
|
207
|
-
if (this.factory.isLocalized(ast)) {
|
|
208
|
-
this.handleLoc(ast, generate);
|
|
189
|
+
var result = nativeObjectToString.call(value);
|
|
190
|
+
if (unmasked) {
|
|
191
|
+
if (isOwn) {
|
|
192
|
+
value[symToStringTag] = tag;
|
|
209
193
|
} else {
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
handleLoc = (localized, handle) => {
|
|
214
|
-
if (this.factory.isSourceLocationNoMaterialize(localized.loc)) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (this.factory.isSourceLocationStringReplace(localized.loc)) {
|
|
218
|
-
this.catchup(localized.loc.start);
|
|
219
|
-
this.print(localized.loc.newSource);
|
|
220
|
-
this.generatedUntil = localized.loc.end;
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (this.factory.isSourceLocationNodeReplace(localized.loc)) {
|
|
224
|
-
this.catchup(localized.loc.start);
|
|
225
|
-
this.generatedUntil = localized.loc.end;
|
|
226
|
-
}
|
|
227
|
-
if (this.factory.isSourceLocationSource(localized.loc)) {
|
|
228
|
-
this.catchup(localized.loc.start);
|
|
229
|
-
}
|
|
230
|
-
const ret = handle();
|
|
231
|
-
if (this.factory.isSourceLocationSource(localized.loc)) {
|
|
232
|
-
this.catchup(localized.loc.end);
|
|
233
|
-
}
|
|
234
|
-
return ret;
|
|
235
|
-
};
|
|
236
|
-
catchup = (until) => {
|
|
237
|
-
const start = this.generatedUntil;
|
|
238
|
-
if (start < until) {
|
|
239
|
-
this.print(this.origSource.slice(start, until));
|
|
240
|
-
}
|
|
241
|
-
this.generatedUntil = Math.max(this.generatedUntil, until);
|
|
242
|
-
};
|
|
243
|
-
print = (...args) => {
|
|
244
|
-
const pureArgs = args.filter((x) => x.length > 0);
|
|
245
|
-
if (pureArgs.length > 0) {
|
|
246
|
-
const [head2, ...tail] = pureArgs;
|
|
247
|
-
if (this.expectsSpace) {
|
|
248
|
-
this.expectsSpace = false;
|
|
249
|
-
const blanks = /* @__PURE__ */ new Set(["\n", " ", " "]);
|
|
250
|
-
if (this.stringBuilder.length > 0 && !(blanks.has(head2[0]) || blanks.has(this.stringBuilder.at(-1).at(-1)))) {
|
|
251
|
-
this.stringBuilder.push(" ");
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
this.stringBuilder.push(head2);
|
|
255
|
-
this.stringBuilder.push(...tail);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
printWord = (...args) => {
|
|
259
|
-
this.expectsSpace = true;
|
|
260
|
-
this.print(...args);
|
|
261
|
-
this.expectsSpace = true;
|
|
262
|
-
};
|
|
263
|
-
printSpaceLeft = (...args) => {
|
|
264
|
-
this.expectsSpace = true;
|
|
265
|
-
this.print(...args);
|
|
266
|
-
};
|
|
267
|
-
printWords = (...args) => {
|
|
268
|
-
for (const arg of args) {
|
|
269
|
-
this.printWord(arg);
|
|
194
|
+
delete value[symToStringTag];
|
|
270
195
|
}
|
|
271
|
-
};
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
// lib/generator-builder/generatorBuilder.js
|
|
275
|
-
function listToRuleDefMap(rules) {
|
|
276
|
-
const newRules = {};
|
|
277
|
-
for (const rule of rules) {
|
|
278
|
-
newRules[rule.name] = rule;
|
|
279
196
|
}
|
|
280
|
-
return
|
|
197
|
+
return result;
|
|
281
198
|
}
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
199
|
+
var getRawTag_default = getRawTag;
|
|
200
|
+
|
|
201
|
+
// ../../node_modules/lodash-es/_objectToString.js
|
|
202
|
+
var objectProto2 = Object.prototype;
|
|
203
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
204
|
+
function objectToString(value) {
|
|
205
|
+
return nativeObjectToString2.call(value);
|
|
206
|
+
}
|
|
207
|
+
var objectToString_default = objectToString;
|
|
208
|
+
|
|
209
|
+
// ../../node_modules/lodash-es/_baseGetTag.js
|
|
210
|
+
var nullTag = "[object Null]";
|
|
211
|
+
var undefinedTag = "[object Undefined]";
|
|
212
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
213
|
+
function baseGetTag(value) {
|
|
214
|
+
if (value == null) {
|
|
215
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
298
216
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
217
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
218
|
+
}
|
|
219
|
+
var baseGetTag_default = baseGetTag;
|
|
220
|
+
|
|
221
|
+
// ../../node_modules/lodash-es/isObjectLike.js
|
|
222
|
+
function isObjectLike(value) {
|
|
223
|
+
return value != null && typeof value == "object";
|
|
224
|
+
}
|
|
225
|
+
var isObjectLike_default = isObjectLike;
|
|
226
|
+
|
|
227
|
+
// ../../node_modules/lodash-es/isSymbol.js
|
|
228
|
+
var symbolTag = "[object Symbol]";
|
|
229
|
+
function isSymbol(value) {
|
|
230
|
+
return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
|
|
231
|
+
}
|
|
232
|
+
var isSymbol_default = isSymbol;
|
|
233
|
+
|
|
234
|
+
// ../../node_modules/lodash-es/_arrayMap.js
|
|
235
|
+
function arrayMap(array, iteratee) {
|
|
236
|
+
var index = -1, length = array == null ? 0 : array.length, result = Array(length);
|
|
237
|
+
while (++index < length) {
|
|
238
|
+
result[index] = iteratee(array[index], index, array);
|
|
306
239
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
var arrayMap_default = arrayMap;
|
|
243
|
+
|
|
244
|
+
// ../../node_modules/lodash-es/isArray.js
|
|
245
|
+
var isArray = Array.isArray;
|
|
246
|
+
var isArray_default = isArray;
|
|
247
|
+
|
|
248
|
+
// ../../node_modules/lodash-es/_baseToString.js
|
|
249
|
+
var INFINITY = 1 / 0;
|
|
250
|
+
var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
|
|
251
|
+
var symbolToString = symbolProto ? symbolProto.toString : void 0;
|
|
252
|
+
function baseToString(value) {
|
|
253
|
+
if (typeof value == "string") {
|
|
254
|
+
return value;
|
|
318
255
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
*/
|
|
322
|
-
addRule(rule) {
|
|
323
|
-
return this.addRuleRedundant(rule);
|
|
256
|
+
if (isArray_default(value)) {
|
|
257
|
+
return arrayMap_default(value, baseToString) + "";
|
|
324
258
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return this;
|
|
259
|
+
if (isSymbol_default(value)) {
|
|
260
|
+
return symbolToString ? symbolToString.call(value) : "";
|
|
328
261
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
* If the two builders both have a grammar rule with the same name,
|
|
340
|
-
* no error will be thrown case they map to the same ruledef object.
|
|
341
|
-
* If they map to a different object, an error will be thrown.
|
|
342
|
-
* To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
|
|
343
|
-
* this rule implementation will be used.
|
|
344
|
-
*/
|
|
345
|
-
merge(GeneratorBuilder2, overridingRules) {
|
|
346
|
-
const otherRules = { ...GeneratorBuilder2.rules };
|
|
347
|
-
const myRules = this.rules;
|
|
348
|
-
for (const rule of Object.values(myRules)) {
|
|
349
|
-
if (otherRules[rule.name] === void 0) {
|
|
350
|
-
otherRules[rule.name] = rule;
|
|
351
|
-
} else {
|
|
352
|
-
const existingRule = otherRules[rule.name];
|
|
353
|
-
if (existingRule !== rule) {
|
|
354
|
-
const override = overridingRules.find((x) => x.name === rule.name);
|
|
355
|
-
if (override) {
|
|
356
|
-
otherRules[rule.name] = override;
|
|
357
|
-
} else {
|
|
358
|
-
throw new Error(`Rule with name "${rule.name}" already exists in the GeneratorBuilder, specify an override to resolve conflict`);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
this.rules = otherRules;
|
|
364
|
-
return this;
|
|
365
|
-
}
|
|
366
|
-
build() {
|
|
367
|
-
return new DynamicGenerator(this.rules);
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// lib/indirection-builder/helpers.js
|
|
372
|
-
function listToIndirectionMap(rules) {
|
|
373
|
-
const newRules = {};
|
|
374
|
-
for (const rule of rules) {
|
|
375
|
-
newRules[rule.name] = rule;
|
|
376
|
-
}
|
|
377
|
-
return newRules;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// lib/indirection-builder/dynamicIndirected.js
|
|
381
|
-
var DynamicIndirect = class {
|
|
382
|
-
rules;
|
|
383
|
-
__context = void 0;
|
|
384
|
-
constructor(rules) {
|
|
385
|
-
this.rules = rules;
|
|
386
|
-
for (const rule of Object.values(rules)) {
|
|
387
|
-
this[rule.name] = ((context, ...args) => {
|
|
388
|
-
this.setContext(context);
|
|
389
|
-
return this.subrule(rule, ...args);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
setContext(context) {
|
|
394
|
-
this.__context = context;
|
|
395
|
-
}
|
|
396
|
-
getSafeContext() {
|
|
397
|
-
return this.__context;
|
|
398
|
-
}
|
|
399
|
-
subrule = (cstDef, ...args) => {
|
|
400
|
-
const def = this.rules[cstDef.name];
|
|
401
|
-
if (!def) {
|
|
402
|
-
throw new Error(`Rule ${cstDef.name} not found`);
|
|
403
|
-
}
|
|
404
|
-
return def.fun({
|
|
405
|
-
SUBRULE: this.subrule
|
|
406
|
-
})(this.getSafeContext(), ...args);
|
|
407
|
-
};
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
// lib/indirection-builder/IndirBuilder.js
|
|
411
|
-
var IndirBuilder = class _IndirBuilder {
|
|
412
|
-
static create(start) {
|
|
413
|
-
if (start instanceof _IndirBuilder) {
|
|
414
|
-
return new _IndirBuilder({ ...start.rules });
|
|
415
|
-
}
|
|
416
|
-
return new _IndirBuilder(listToIndirectionMap(start));
|
|
417
|
-
}
|
|
418
|
-
rules;
|
|
419
|
-
constructor(startRules) {
|
|
420
|
-
this.rules = startRules;
|
|
421
|
-
}
|
|
422
|
-
widenContext() {
|
|
423
|
-
return this;
|
|
424
|
-
}
|
|
425
|
-
typePatch() {
|
|
426
|
-
return this;
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Change the implementation of an existing indirection.
|
|
430
|
-
*/
|
|
431
|
-
patchRule(patch) {
|
|
432
|
-
const self2 = this;
|
|
433
|
-
self2.rules[patch.name] = patch;
|
|
434
|
-
return self2;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Add an indirection function. If the rule already exists, but the implementation differs, an error will be thrown.
|
|
438
|
-
*/
|
|
439
|
-
addRuleRedundant(rule) {
|
|
440
|
-
const self2 = this;
|
|
441
|
-
const rules = self2.rules;
|
|
442
|
-
if (rules[rule.name] !== void 0 && rules[rule.name] !== rule) {
|
|
443
|
-
throw new Error(`Function ${rule.name} already exists in the builder`);
|
|
444
|
-
}
|
|
445
|
-
rules[rule.name] = rule;
|
|
446
|
-
return self2;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
|
|
450
|
-
*/
|
|
451
|
-
addRule(rule) {
|
|
452
|
-
return this.addRuleRedundant(rule);
|
|
453
|
-
}
|
|
454
|
-
addMany(...rules) {
|
|
455
|
-
this.rules = { ...this.rules, ...listToIndirectionMap(rules) };
|
|
456
|
-
return this;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Delete a grammar rule by its name.
|
|
460
|
-
*/
|
|
461
|
-
deleteRule(ruleName) {
|
|
462
|
-
delete this.rules[ruleName];
|
|
463
|
-
return this;
|
|
464
|
-
}
|
|
465
|
-
build() {
|
|
466
|
-
return new DynamicIndirect(this.rules);
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
471
|
-
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
472
|
-
var freeGlobal_default = freeGlobal;
|
|
473
|
-
|
|
474
|
-
// ../../node_modules/lodash-es/_root.js
|
|
475
|
-
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
476
|
-
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
477
|
-
var root_default = root;
|
|
478
|
-
|
|
479
|
-
// ../../node_modules/lodash-es/_Symbol.js
|
|
480
|
-
var Symbol2 = root_default.Symbol;
|
|
481
|
-
var Symbol_default = Symbol2;
|
|
482
|
-
|
|
483
|
-
// ../../node_modules/lodash-es/_getRawTag.js
|
|
484
|
-
var objectProto = Object.prototype;
|
|
485
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
486
|
-
var nativeObjectToString = objectProto.toString;
|
|
487
|
-
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
488
|
-
function getRawTag(value) {
|
|
489
|
-
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
490
|
-
try {
|
|
491
|
-
value[symToStringTag] = void 0;
|
|
492
|
-
var unmasked = true;
|
|
493
|
-
} catch (e) {
|
|
494
|
-
}
|
|
495
|
-
var result = nativeObjectToString.call(value);
|
|
496
|
-
if (unmasked) {
|
|
497
|
-
if (isOwn) {
|
|
498
|
-
value[symToStringTag] = tag;
|
|
499
|
-
} else {
|
|
500
|
-
delete value[symToStringTag];
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return result;
|
|
504
|
-
}
|
|
505
|
-
var getRawTag_default = getRawTag;
|
|
506
|
-
|
|
507
|
-
// ../../node_modules/lodash-es/_objectToString.js
|
|
508
|
-
var objectProto2 = Object.prototype;
|
|
509
|
-
var nativeObjectToString2 = objectProto2.toString;
|
|
510
|
-
function objectToString(value) {
|
|
511
|
-
return nativeObjectToString2.call(value);
|
|
512
|
-
}
|
|
513
|
-
var objectToString_default = objectToString;
|
|
514
|
-
|
|
515
|
-
// ../../node_modules/lodash-es/_baseGetTag.js
|
|
516
|
-
var nullTag = "[object Null]";
|
|
517
|
-
var undefinedTag = "[object Undefined]";
|
|
518
|
-
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
519
|
-
function baseGetTag(value) {
|
|
520
|
-
if (value == null) {
|
|
521
|
-
return value === void 0 ? undefinedTag : nullTag;
|
|
522
|
-
}
|
|
523
|
-
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
524
|
-
}
|
|
525
|
-
var baseGetTag_default = baseGetTag;
|
|
526
|
-
|
|
527
|
-
// ../../node_modules/lodash-es/isObjectLike.js
|
|
528
|
-
function isObjectLike(value) {
|
|
529
|
-
return value != null && typeof value == "object";
|
|
530
|
-
}
|
|
531
|
-
var isObjectLike_default = isObjectLike;
|
|
532
|
-
|
|
533
|
-
// ../../node_modules/lodash-es/isSymbol.js
|
|
534
|
-
var symbolTag = "[object Symbol]";
|
|
535
|
-
function isSymbol(value) {
|
|
536
|
-
return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
|
|
537
|
-
}
|
|
538
|
-
var isSymbol_default = isSymbol;
|
|
539
|
-
|
|
540
|
-
// ../../node_modules/lodash-es/_arrayMap.js
|
|
541
|
-
function arrayMap(array, iteratee) {
|
|
542
|
-
var index = -1, length = array == null ? 0 : array.length, result = Array(length);
|
|
543
|
-
while (++index < length) {
|
|
544
|
-
result[index] = iteratee(array[index], index, array);
|
|
545
|
-
}
|
|
546
|
-
return result;
|
|
547
|
-
}
|
|
548
|
-
var arrayMap_default = arrayMap;
|
|
549
|
-
|
|
550
|
-
// ../../node_modules/lodash-es/isArray.js
|
|
551
|
-
var isArray = Array.isArray;
|
|
552
|
-
var isArray_default = isArray;
|
|
553
|
-
|
|
554
|
-
// ../../node_modules/lodash-es/_baseToString.js
|
|
555
|
-
var INFINITY = 1 / 0;
|
|
556
|
-
var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
|
|
557
|
-
var symbolToString = symbolProto ? symbolProto.toString : void 0;
|
|
558
|
-
function baseToString(value) {
|
|
559
|
-
if (typeof value == "string") {
|
|
560
|
-
return value;
|
|
561
|
-
}
|
|
562
|
-
if (isArray_default(value)) {
|
|
563
|
-
return arrayMap_default(value, baseToString) + "";
|
|
564
|
-
}
|
|
565
|
-
if (isSymbol_default(value)) {
|
|
566
|
-
return symbolToString ? symbolToString.call(value) : "";
|
|
567
|
-
}
|
|
568
|
-
var result = value + "";
|
|
569
|
-
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
570
|
-
}
|
|
571
|
-
var baseToString_default = baseToString;
|
|
572
|
-
|
|
573
|
-
// ../../node_modules/lodash-es/_trimmedEndIndex.js
|
|
574
|
-
var reWhitespace = /\s/;
|
|
575
|
-
function trimmedEndIndex(string) {
|
|
576
|
-
var index = string.length;
|
|
577
|
-
while (index-- && reWhitespace.test(string.charAt(index))) {
|
|
262
|
+
var result = value + "";
|
|
263
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
264
|
+
}
|
|
265
|
+
var baseToString_default = baseToString;
|
|
266
|
+
|
|
267
|
+
// ../../node_modules/lodash-es/_trimmedEndIndex.js
|
|
268
|
+
var reWhitespace = /\s/;
|
|
269
|
+
function trimmedEndIndex(string) {
|
|
270
|
+
var index = string.length;
|
|
271
|
+
while (index-- && reWhitespace.test(string.charAt(index))) {
|
|
578
272
|
}
|
|
579
273
|
return index;
|
|
580
274
|
}
|
|
@@ -9360,328 +9054,683 @@ var GastRecorder = class {
|
|
|
9360
9054
|
throw originalError;
|
|
9361
9055
|
}
|
|
9362
9056
|
}
|
|
9363
|
-
throw originalError;
|
|
9057
|
+
throw originalError;
|
|
9058
|
+
}
|
|
9059
|
+
}
|
|
9060
|
+
// Implementation of parsing DSL
|
|
9061
|
+
optionInternalRecord(actionORMethodDef, occurrence) {
|
|
9062
|
+
return recordProd.call(this, Option, actionORMethodDef, occurrence);
|
|
9063
|
+
}
|
|
9064
|
+
atLeastOneInternalRecord(occurrence, actionORMethodDef) {
|
|
9065
|
+
recordProd.call(this, RepetitionMandatory, actionORMethodDef, occurrence);
|
|
9066
|
+
}
|
|
9067
|
+
atLeastOneSepFirstInternalRecord(occurrence, options) {
|
|
9068
|
+
recordProd.call(this, RepetitionMandatoryWithSeparator, options, occurrence, HANDLE_SEPARATOR);
|
|
9069
|
+
}
|
|
9070
|
+
manyInternalRecord(occurrence, actionORMethodDef) {
|
|
9071
|
+
recordProd.call(this, Repetition, actionORMethodDef, occurrence);
|
|
9072
|
+
}
|
|
9073
|
+
manySepFirstInternalRecord(occurrence, options) {
|
|
9074
|
+
recordProd.call(this, RepetitionWithSeparator, options, occurrence, HANDLE_SEPARATOR);
|
|
9075
|
+
}
|
|
9076
|
+
orInternalRecord(altsOrOpts, occurrence) {
|
|
9077
|
+
return recordOrProd.call(this, altsOrOpts, occurrence);
|
|
9078
|
+
}
|
|
9079
|
+
subruleInternalRecord(ruleToCall, occurrence, options) {
|
|
9080
|
+
assertMethodIdxIsValid(occurrence);
|
|
9081
|
+
if (!ruleToCall || has_default(ruleToCall, "ruleName") === false) {
|
|
9082
|
+
const error = new Error(`<SUBRULE${getIdxSuffix(occurrence)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(ruleToCall)}>
|
|
9083
|
+
inside top level rule: <${this.recordingProdStack[0].name}>`);
|
|
9084
|
+
error.KNOWN_RECORDER_ERROR = true;
|
|
9085
|
+
throw error;
|
|
9086
|
+
}
|
|
9087
|
+
const prevProd = last_default(this.recordingProdStack);
|
|
9088
|
+
const ruleName = ruleToCall.ruleName;
|
|
9089
|
+
const newNoneTerminal = new NonTerminal({
|
|
9090
|
+
idx: occurrence,
|
|
9091
|
+
nonTerminalName: ruleName,
|
|
9092
|
+
label: options === null || options === void 0 ? void 0 : options.LABEL,
|
|
9093
|
+
// The resolving of the `referencedRule` property will be done once all the Rule's GASTs have been created
|
|
9094
|
+
referencedRule: void 0
|
|
9095
|
+
});
|
|
9096
|
+
prevProd.definition.push(newNoneTerminal);
|
|
9097
|
+
return this.outputCst ? RECORDING_PHASE_CSTNODE : RECORDING_NULL_OBJECT;
|
|
9098
|
+
}
|
|
9099
|
+
consumeInternalRecord(tokType, occurrence, options) {
|
|
9100
|
+
assertMethodIdxIsValid(occurrence);
|
|
9101
|
+
if (!hasShortKeyProperty(tokType)) {
|
|
9102
|
+
const error = new Error(`<CONSUME${getIdxSuffix(occurrence)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(tokType)}>
|
|
9103
|
+
inside top level rule: <${this.recordingProdStack[0].name}>`);
|
|
9104
|
+
error.KNOWN_RECORDER_ERROR = true;
|
|
9105
|
+
throw error;
|
|
9106
|
+
}
|
|
9107
|
+
const prevProd = last_default(this.recordingProdStack);
|
|
9108
|
+
const newNoneTerminal = new Terminal({
|
|
9109
|
+
idx: occurrence,
|
|
9110
|
+
terminalType: tokType,
|
|
9111
|
+
label: options === null || options === void 0 ? void 0 : options.LABEL
|
|
9112
|
+
});
|
|
9113
|
+
prevProd.definition.push(newNoneTerminal);
|
|
9114
|
+
return RECORDING_PHASE_TOKEN;
|
|
9115
|
+
}
|
|
9116
|
+
};
|
|
9117
|
+
function recordProd(prodConstructor, mainProdArg, occurrence, handleSep = false) {
|
|
9118
|
+
assertMethodIdxIsValid(occurrence);
|
|
9119
|
+
const prevProd = last_default(this.recordingProdStack);
|
|
9120
|
+
const grammarAction = isFunction_default(mainProdArg) ? mainProdArg : mainProdArg.DEF;
|
|
9121
|
+
const newProd = new prodConstructor({ definition: [], idx: occurrence });
|
|
9122
|
+
if (handleSep) {
|
|
9123
|
+
newProd.separator = mainProdArg.SEP;
|
|
9124
|
+
}
|
|
9125
|
+
if (has_default(mainProdArg, "MAX_LOOKAHEAD")) {
|
|
9126
|
+
newProd.maxLookahead = mainProdArg.MAX_LOOKAHEAD;
|
|
9127
|
+
}
|
|
9128
|
+
this.recordingProdStack.push(newProd);
|
|
9129
|
+
grammarAction.call(this);
|
|
9130
|
+
prevProd.definition.push(newProd);
|
|
9131
|
+
this.recordingProdStack.pop();
|
|
9132
|
+
return RECORDING_NULL_OBJECT;
|
|
9133
|
+
}
|
|
9134
|
+
function recordOrProd(mainProdArg, occurrence) {
|
|
9135
|
+
assertMethodIdxIsValid(occurrence);
|
|
9136
|
+
const prevProd = last_default(this.recordingProdStack);
|
|
9137
|
+
const hasOptions = isArray_default(mainProdArg) === false;
|
|
9138
|
+
const alts = hasOptions === false ? mainProdArg : mainProdArg.DEF;
|
|
9139
|
+
const newOrProd = new Alternation({
|
|
9140
|
+
definition: [],
|
|
9141
|
+
idx: occurrence,
|
|
9142
|
+
ignoreAmbiguities: hasOptions && mainProdArg.IGNORE_AMBIGUITIES === true
|
|
9143
|
+
});
|
|
9144
|
+
if (has_default(mainProdArg, "MAX_LOOKAHEAD")) {
|
|
9145
|
+
newOrProd.maxLookahead = mainProdArg.MAX_LOOKAHEAD;
|
|
9146
|
+
}
|
|
9147
|
+
const hasPredicates = some_default(alts, (currAlt) => isFunction_default(currAlt.GATE));
|
|
9148
|
+
newOrProd.hasPredicates = hasPredicates;
|
|
9149
|
+
prevProd.definition.push(newOrProd);
|
|
9150
|
+
forEach_default(alts, (currAlt) => {
|
|
9151
|
+
const currAltFlat = new Alternative({ definition: [] });
|
|
9152
|
+
newOrProd.definition.push(currAltFlat);
|
|
9153
|
+
if (has_default(currAlt, "IGNORE_AMBIGUITIES")) {
|
|
9154
|
+
currAltFlat.ignoreAmbiguities = currAlt.IGNORE_AMBIGUITIES;
|
|
9155
|
+
} else if (has_default(currAlt, "GATE")) {
|
|
9156
|
+
currAltFlat.ignoreAmbiguities = true;
|
|
9157
|
+
}
|
|
9158
|
+
this.recordingProdStack.push(currAltFlat);
|
|
9159
|
+
currAlt.ALT.call(this);
|
|
9160
|
+
this.recordingProdStack.pop();
|
|
9161
|
+
});
|
|
9162
|
+
return RECORDING_NULL_OBJECT;
|
|
9163
|
+
}
|
|
9164
|
+
function getIdxSuffix(idx) {
|
|
9165
|
+
return idx === 0 ? "" : `${idx}`;
|
|
9166
|
+
}
|
|
9167
|
+
function assertMethodIdxIsValid(idx) {
|
|
9168
|
+
if (idx < 0 || idx > MAX_METHOD_IDX) {
|
|
9169
|
+
const error = new Error(
|
|
9170
|
+
// The stack trace will contain all the needed details
|
|
9171
|
+
`Invalid DSL Method idx value: <${idx}>
|
|
9172
|
+
Idx value must be a none negative value smaller than ${MAX_METHOD_IDX + 1}`
|
|
9173
|
+
);
|
|
9174
|
+
error.KNOWN_RECORDER_ERROR = true;
|
|
9175
|
+
throw error;
|
|
9176
|
+
}
|
|
9177
|
+
}
|
|
9178
|
+
|
|
9179
|
+
// ../../node_modules/chevrotain/lib/src/parse/parser/traits/perf_tracer.js
|
|
9180
|
+
var PerformanceTracer = class {
|
|
9181
|
+
initPerformanceTracer(config) {
|
|
9182
|
+
if (has_default(config, "traceInitPerf")) {
|
|
9183
|
+
const userTraceInitPerf = config.traceInitPerf;
|
|
9184
|
+
const traceIsNumber = typeof userTraceInitPerf === "number";
|
|
9185
|
+
this.traceInitMaxIdent = traceIsNumber ? userTraceInitPerf : Infinity;
|
|
9186
|
+
this.traceInitPerf = traceIsNumber ? userTraceInitPerf > 0 : userTraceInitPerf;
|
|
9187
|
+
} else {
|
|
9188
|
+
this.traceInitMaxIdent = 0;
|
|
9189
|
+
this.traceInitPerf = DEFAULT_PARSER_CONFIG.traceInitPerf;
|
|
9190
|
+
}
|
|
9191
|
+
this.traceInitIndent = -1;
|
|
9192
|
+
}
|
|
9193
|
+
TRACE_INIT(phaseDesc, phaseImpl) {
|
|
9194
|
+
if (this.traceInitPerf === true) {
|
|
9195
|
+
this.traceInitIndent++;
|
|
9196
|
+
const indent = new Array(this.traceInitIndent + 1).join(" ");
|
|
9197
|
+
if (this.traceInitIndent < this.traceInitMaxIdent) {
|
|
9198
|
+
console.log(`${indent}--> <${phaseDesc}>`);
|
|
9199
|
+
}
|
|
9200
|
+
const { time, value } = timer(phaseImpl);
|
|
9201
|
+
const traceMethod = time > 10 ? console.warn : console.log;
|
|
9202
|
+
if (this.traceInitIndent < this.traceInitMaxIdent) {
|
|
9203
|
+
traceMethod(`${indent}<-- <${phaseDesc}> time: ${time}ms`);
|
|
9204
|
+
}
|
|
9205
|
+
this.traceInitIndent--;
|
|
9206
|
+
return value;
|
|
9207
|
+
} else {
|
|
9208
|
+
return phaseImpl();
|
|
9209
|
+
}
|
|
9210
|
+
}
|
|
9211
|
+
};
|
|
9212
|
+
|
|
9213
|
+
// ../../node_modules/chevrotain/lib/src/parse/parser/utils/apply_mixins.js
|
|
9214
|
+
function applyMixins(derivedCtor, baseCtors) {
|
|
9215
|
+
baseCtors.forEach((baseCtor) => {
|
|
9216
|
+
const baseProto = baseCtor.prototype;
|
|
9217
|
+
Object.getOwnPropertyNames(baseProto).forEach((propName) => {
|
|
9218
|
+
if (propName === "constructor") {
|
|
9219
|
+
return;
|
|
9220
|
+
}
|
|
9221
|
+
const basePropDescriptor = Object.getOwnPropertyDescriptor(baseProto, propName);
|
|
9222
|
+
if (basePropDescriptor && (basePropDescriptor.get || basePropDescriptor.set)) {
|
|
9223
|
+
Object.defineProperty(derivedCtor.prototype, propName, basePropDescriptor);
|
|
9224
|
+
} else {
|
|
9225
|
+
derivedCtor.prototype[propName] = baseCtor.prototype[propName];
|
|
9226
|
+
}
|
|
9227
|
+
});
|
|
9228
|
+
});
|
|
9229
|
+
}
|
|
9230
|
+
|
|
9231
|
+
// ../../node_modules/chevrotain/lib/src/parse/parser/parser.js
|
|
9232
|
+
var END_OF_FILE = createTokenInstance(EOF, "", NaN, NaN, NaN, NaN, NaN, NaN);
|
|
9233
|
+
Object.freeze(END_OF_FILE);
|
|
9234
|
+
var DEFAULT_PARSER_CONFIG = Object.freeze({
|
|
9235
|
+
recoveryEnabled: false,
|
|
9236
|
+
maxLookahead: 3,
|
|
9237
|
+
dynamicTokensEnabled: false,
|
|
9238
|
+
outputCst: true,
|
|
9239
|
+
errorMessageProvider: defaultParserErrorProvider,
|
|
9240
|
+
nodeLocationTracking: "none",
|
|
9241
|
+
traceInitPerf: false,
|
|
9242
|
+
skipValidations: false
|
|
9243
|
+
});
|
|
9244
|
+
var DEFAULT_RULE_CONFIG = Object.freeze({
|
|
9245
|
+
recoveryValueFunc: () => void 0,
|
|
9246
|
+
resyncEnabled: true
|
|
9247
|
+
});
|
|
9248
|
+
var ParserDefinitionErrorType;
|
|
9249
|
+
(function(ParserDefinitionErrorType2) {
|
|
9250
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["INVALID_RULE_NAME"] = 0] = "INVALID_RULE_NAME";
|
|
9251
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["DUPLICATE_RULE_NAME"] = 1] = "DUPLICATE_RULE_NAME";
|
|
9252
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["INVALID_RULE_OVERRIDE"] = 2] = "INVALID_RULE_OVERRIDE";
|
|
9253
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["DUPLICATE_PRODUCTIONS"] = 3] = "DUPLICATE_PRODUCTIONS";
|
|
9254
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["UNRESOLVED_SUBRULE_REF"] = 4] = "UNRESOLVED_SUBRULE_REF";
|
|
9255
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["LEFT_RECURSION"] = 5] = "LEFT_RECURSION";
|
|
9256
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["NONE_LAST_EMPTY_ALT"] = 6] = "NONE_LAST_EMPTY_ALT";
|
|
9257
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["AMBIGUOUS_ALTS"] = 7] = "AMBIGUOUS_ALTS";
|
|
9258
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["CONFLICT_TOKENS_RULES_NAMESPACE"] = 8] = "CONFLICT_TOKENS_RULES_NAMESPACE";
|
|
9259
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["INVALID_TOKEN_NAME"] = 9] = "INVALID_TOKEN_NAME";
|
|
9260
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["NO_NON_EMPTY_LOOKAHEAD"] = 10] = "NO_NON_EMPTY_LOOKAHEAD";
|
|
9261
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["AMBIGUOUS_PREFIX_ALTS"] = 11] = "AMBIGUOUS_PREFIX_ALTS";
|
|
9262
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["TOO_MANY_ALTS"] = 12] = "TOO_MANY_ALTS";
|
|
9263
|
+
ParserDefinitionErrorType2[ParserDefinitionErrorType2["CUSTOM_LOOKAHEAD_VALIDATION"] = 13] = "CUSTOM_LOOKAHEAD_VALIDATION";
|
|
9264
|
+
})(ParserDefinitionErrorType || (ParserDefinitionErrorType = {}));
|
|
9265
|
+
var Parser = class _Parser {
|
|
9266
|
+
/**
|
|
9267
|
+
* @deprecated use the **instance** method with the same name instead
|
|
9268
|
+
*/
|
|
9269
|
+
static performSelfAnalysis(parserInstance) {
|
|
9270
|
+
throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.");
|
|
9271
|
+
}
|
|
9272
|
+
performSelfAnalysis() {
|
|
9273
|
+
this.TRACE_INIT("performSelfAnalysis", () => {
|
|
9274
|
+
let defErrorsMsgs;
|
|
9275
|
+
this.selfAnalysisDone = true;
|
|
9276
|
+
const className = this.className;
|
|
9277
|
+
this.TRACE_INIT("toFastProps", () => {
|
|
9278
|
+
toFastProperties(this);
|
|
9279
|
+
});
|
|
9280
|
+
this.TRACE_INIT("Grammar Recording", () => {
|
|
9281
|
+
try {
|
|
9282
|
+
this.enableRecording();
|
|
9283
|
+
forEach_default(this.definedRulesNames, (currRuleName) => {
|
|
9284
|
+
const wrappedRule = this[currRuleName];
|
|
9285
|
+
const originalGrammarAction = wrappedRule["originalGrammarAction"];
|
|
9286
|
+
let recordedRuleGast;
|
|
9287
|
+
this.TRACE_INIT(`${currRuleName} Rule`, () => {
|
|
9288
|
+
recordedRuleGast = this.topLevelRuleRecord(currRuleName, originalGrammarAction);
|
|
9289
|
+
});
|
|
9290
|
+
this.gastProductionsCache[currRuleName] = recordedRuleGast;
|
|
9291
|
+
});
|
|
9292
|
+
} finally {
|
|
9293
|
+
this.disableRecording();
|
|
9294
|
+
}
|
|
9295
|
+
});
|
|
9296
|
+
let resolverErrors = [];
|
|
9297
|
+
this.TRACE_INIT("Grammar Resolving", () => {
|
|
9298
|
+
resolverErrors = resolveGrammar2({
|
|
9299
|
+
rules: values_default(this.gastProductionsCache)
|
|
9300
|
+
});
|
|
9301
|
+
this.definitionErrors = this.definitionErrors.concat(resolverErrors);
|
|
9302
|
+
});
|
|
9303
|
+
this.TRACE_INIT("Grammar Validations", () => {
|
|
9304
|
+
if (isEmpty_default(resolverErrors) && this.skipValidations === false) {
|
|
9305
|
+
const validationErrors = validateGrammar2({
|
|
9306
|
+
rules: values_default(this.gastProductionsCache),
|
|
9307
|
+
tokenTypes: values_default(this.tokensMap),
|
|
9308
|
+
errMsgProvider: defaultGrammarValidatorErrorProvider,
|
|
9309
|
+
grammarName: className
|
|
9310
|
+
});
|
|
9311
|
+
const lookaheadValidationErrors = validateLookahead({
|
|
9312
|
+
lookaheadStrategy: this.lookaheadStrategy,
|
|
9313
|
+
rules: values_default(this.gastProductionsCache),
|
|
9314
|
+
tokenTypes: values_default(this.tokensMap),
|
|
9315
|
+
grammarName: className
|
|
9316
|
+
});
|
|
9317
|
+
this.definitionErrors = this.definitionErrors.concat(validationErrors, lookaheadValidationErrors);
|
|
9318
|
+
}
|
|
9319
|
+
});
|
|
9320
|
+
if (isEmpty_default(this.definitionErrors)) {
|
|
9321
|
+
if (this.recoveryEnabled) {
|
|
9322
|
+
this.TRACE_INIT("computeAllProdsFollows", () => {
|
|
9323
|
+
const allFollows = computeAllProdsFollows(values_default(this.gastProductionsCache));
|
|
9324
|
+
this.resyncFollows = allFollows;
|
|
9325
|
+
});
|
|
9326
|
+
}
|
|
9327
|
+
this.TRACE_INIT("ComputeLookaheadFunctions", () => {
|
|
9328
|
+
var _a, _b;
|
|
9329
|
+
(_b = (_a = this.lookaheadStrategy).initialize) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
9330
|
+
rules: values_default(this.gastProductionsCache)
|
|
9331
|
+
});
|
|
9332
|
+
this.preComputeLookaheadFunctions(values_default(this.gastProductionsCache));
|
|
9333
|
+
});
|
|
9334
|
+
}
|
|
9335
|
+
if (!_Parser.DEFER_DEFINITION_ERRORS_HANDLING && !isEmpty_default(this.definitionErrors)) {
|
|
9336
|
+
defErrorsMsgs = map_default(this.definitionErrors, (defError) => defError.message);
|
|
9337
|
+
throw new Error(`Parser Definition Errors detected:
|
|
9338
|
+
${defErrorsMsgs.join("\n-------------------------------\n")}`);
|
|
9339
|
+
}
|
|
9340
|
+
});
|
|
9341
|
+
}
|
|
9342
|
+
constructor(tokenVocabulary, config) {
|
|
9343
|
+
this.definitionErrors = [];
|
|
9344
|
+
this.selfAnalysisDone = false;
|
|
9345
|
+
const that = this;
|
|
9346
|
+
that.initErrorHandler(config);
|
|
9347
|
+
that.initLexerAdapter();
|
|
9348
|
+
that.initLooksAhead(config);
|
|
9349
|
+
that.initRecognizerEngine(tokenVocabulary, config);
|
|
9350
|
+
that.initRecoverable(config);
|
|
9351
|
+
that.initTreeBuilder(config);
|
|
9352
|
+
that.initContentAssist();
|
|
9353
|
+
that.initGastRecorder(config);
|
|
9354
|
+
that.initPerformanceTracer(config);
|
|
9355
|
+
if (has_default(config, "ignoredIssues")) {
|
|
9356
|
+
throw new Error("The <ignoredIssues> IParserConfig property has been deprecated.\n Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.\n See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES\n For further details.");
|
|
9357
|
+
}
|
|
9358
|
+
this.skipValidations = has_default(config, "skipValidations") ? config.skipValidations : DEFAULT_PARSER_CONFIG.skipValidations;
|
|
9359
|
+
}
|
|
9360
|
+
};
|
|
9361
|
+
Parser.DEFER_DEFINITION_ERRORS_HANDLING = false;
|
|
9362
|
+
applyMixins(Parser, [
|
|
9363
|
+
Recoverable,
|
|
9364
|
+
LooksAhead,
|
|
9365
|
+
TreeBuilder,
|
|
9366
|
+
LexerAdapter,
|
|
9367
|
+
RecognizerEngine,
|
|
9368
|
+
RecognizerApi,
|
|
9369
|
+
ErrorHandler,
|
|
9370
|
+
ContentAssist,
|
|
9371
|
+
GastRecorder,
|
|
9372
|
+
PerformanceTracer
|
|
9373
|
+
]);
|
|
9374
|
+
var EmbeddedActionsParser = class extends Parser {
|
|
9375
|
+
constructor(tokenVocabulary, config = DEFAULT_PARSER_CONFIG) {
|
|
9376
|
+
const configClone = clone_default(config);
|
|
9377
|
+
configClone.outputCst = false;
|
|
9378
|
+
super(tokenVocabulary, configClone);
|
|
9379
|
+
}
|
|
9380
|
+
};
|
|
9381
|
+
|
|
9382
|
+
// lib/utils.js
|
|
9383
|
+
function unCapitalize(str) {
|
|
9384
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
9385
|
+
}
|
|
9386
|
+
function createToken2(config) {
|
|
9387
|
+
return createToken(config);
|
|
9388
|
+
}
|
|
9389
|
+
var traqulaIndentation = "When you use this string, you expect traqula to handle indentation after every newline";
|
|
9390
|
+
|
|
9391
|
+
// lib/generator-builder/dynamicGenerator.js
|
|
9392
|
+
var DynamicGenerator = class {
|
|
9393
|
+
rules;
|
|
9394
|
+
factory = new AstCoreFactory();
|
|
9395
|
+
__context = void 0;
|
|
9396
|
+
origSource = "";
|
|
9397
|
+
generatedUntil = 0;
|
|
9398
|
+
expectsSpace;
|
|
9399
|
+
stringBuilder = [];
|
|
9400
|
+
constructor(rules) {
|
|
9401
|
+
this.rules = rules;
|
|
9402
|
+
for (const rule of Object.values(rules)) {
|
|
9403
|
+
this[rule.name] = ((input, context, args) => {
|
|
9404
|
+
this.expectsSpace = false;
|
|
9405
|
+
this.stringBuilder.length = 0;
|
|
9406
|
+
this.origSource = context.origSource;
|
|
9407
|
+
this.generatedUntil = context?.offset ?? 0;
|
|
9408
|
+
this.setContext(context);
|
|
9409
|
+
this.subrule(rule, input, args);
|
|
9410
|
+
this.catchup(this.origSource.length);
|
|
9411
|
+
return this.stringBuilder.join("");
|
|
9412
|
+
});
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
setContext(context) {
|
|
9416
|
+
this.__context = context;
|
|
9417
|
+
}
|
|
9418
|
+
getSafeContext() {
|
|
9419
|
+
return this.__context;
|
|
9420
|
+
}
|
|
9421
|
+
subrule = (cstDef, ast, ...arg) => {
|
|
9422
|
+
const def = this.rules[cstDef.name];
|
|
9423
|
+
if (!def) {
|
|
9424
|
+
throw new Error(`Rule ${cstDef.name} not found`);
|
|
9425
|
+
}
|
|
9426
|
+
const generate = () => def.gImpl({
|
|
9427
|
+
SUBRULE: this.subrule,
|
|
9428
|
+
PRINT: this.print,
|
|
9429
|
+
PRINT_SPACE_LEFT: this.printSpaceLeft,
|
|
9430
|
+
PRINT_WORD: this.printWord,
|
|
9431
|
+
PRINT_WORDS: this.printWords,
|
|
9432
|
+
PRINT_ON_EMPTY: this.printOnEmpty,
|
|
9433
|
+
CATCHUP: this.catchup,
|
|
9434
|
+
HANDLE_LOC: this.handleLoc
|
|
9435
|
+
})(ast, this.getSafeContext(), ...arg);
|
|
9436
|
+
if (this.factory.isLocalized(ast)) {
|
|
9437
|
+
this.handleLoc(ast, generate);
|
|
9438
|
+
} else {
|
|
9439
|
+
generate();
|
|
9440
|
+
}
|
|
9441
|
+
};
|
|
9442
|
+
handleLoc = (localized, handle) => {
|
|
9443
|
+
if (this.factory.isSourceLocationNoMaterialize(localized.loc)) {
|
|
9444
|
+
return;
|
|
9445
|
+
}
|
|
9446
|
+
if (this.factory.isSourceLocationStringReplace(localized.loc)) {
|
|
9447
|
+
this.catchup(localized.loc.start);
|
|
9448
|
+
this.print(localized.loc.newSource);
|
|
9449
|
+
this.generatedUntil = localized.loc.end;
|
|
9450
|
+
return;
|
|
9451
|
+
}
|
|
9452
|
+
if (this.factory.isSourceLocationNodeReplace(localized.loc)) {
|
|
9453
|
+
this.catchup(localized.loc.start);
|
|
9454
|
+
this.generatedUntil = localized.loc.end;
|
|
9455
|
+
}
|
|
9456
|
+
if (this.factory.isSourceLocationSource(localized.loc)) {
|
|
9457
|
+
this.catchup(localized.loc.start);
|
|
9458
|
+
}
|
|
9459
|
+
const ret = handle();
|
|
9460
|
+
if (this.factory.isSourceLocationSource(localized.loc)) {
|
|
9461
|
+
this.catchup(localized.loc.end);
|
|
9462
|
+
}
|
|
9463
|
+
return ret;
|
|
9464
|
+
};
|
|
9465
|
+
catchup = (until) => {
|
|
9466
|
+
const start = this.generatedUntil;
|
|
9467
|
+
if (start < until) {
|
|
9468
|
+
this.print(this.origSource.slice(start, until));
|
|
9469
|
+
}
|
|
9470
|
+
this.generatedUntil = Math.max(this.generatedUntil, until);
|
|
9471
|
+
};
|
|
9472
|
+
print = (...args) => {
|
|
9473
|
+
const pureArgs = args.filter((x) => x.length > 0);
|
|
9474
|
+
if (pureArgs.length > 0) {
|
|
9475
|
+
const head2 = pureArgs[0];
|
|
9476
|
+
if (this.expectsSpace) {
|
|
9477
|
+
this.expectsSpace = false;
|
|
9478
|
+
const blanks = /* @__PURE__ */ new Set(["\n", " ", " "]);
|
|
9479
|
+
if (this.stringBuilder.length > 0 && !(blanks.has(head2[0]) || blanks.has(this.stringBuilder.at(-1).at(-1)))) {
|
|
9480
|
+
this.stringBuilder.push(" ");
|
|
9481
|
+
}
|
|
9482
|
+
}
|
|
9483
|
+
const context = this.getSafeContext();
|
|
9484
|
+
if (context[traqulaIndentation] && typeof context[traqulaIndentation] === "number") {
|
|
9485
|
+
const indent = context[traqulaIndentation];
|
|
9486
|
+
for (const str of pureArgs) {
|
|
9487
|
+
const [noNl, ...postNl] = str.split("\n");
|
|
9488
|
+
this.stringBuilder.push(noNl);
|
|
9489
|
+
for (const subStr of postNl.map((line) => line.trimStart())) {
|
|
9490
|
+
this.stringBuilder.push("\n", " ".repeat(indent));
|
|
9491
|
+
if (subStr.length > 0) {
|
|
9492
|
+
this.stringBuilder.push(subStr);
|
|
9493
|
+
}
|
|
9494
|
+
}
|
|
9495
|
+
}
|
|
9496
|
+
} else {
|
|
9497
|
+
this.stringBuilder.push(...pureArgs);
|
|
9498
|
+
}
|
|
9364
9499
|
}
|
|
9500
|
+
};
|
|
9501
|
+
printWord = (...args) => {
|
|
9502
|
+
this.expectsSpace = true;
|
|
9503
|
+
this.print(...args);
|
|
9504
|
+
this.expectsSpace = true;
|
|
9505
|
+
};
|
|
9506
|
+
printSpaceLeft = (...args) => {
|
|
9507
|
+
this.expectsSpace = true;
|
|
9508
|
+
this.print(...args);
|
|
9509
|
+
};
|
|
9510
|
+
printWords = (...args) => {
|
|
9511
|
+
for (const arg of args) {
|
|
9512
|
+
this.printWord(arg);
|
|
9513
|
+
}
|
|
9514
|
+
};
|
|
9515
|
+
printOnEmpty = (...args) => {
|
|
9516
|
+
let counter = this.stringBuilder.length - 1;
|
|
9517
|
+
let onEmpty = true;
|
|
9518
|
+
const isEmptyTest = /^[ \t\n]*$/u;
|
|
9519
|
+
while (counter >= 0 && onEmpty) {
|
|
9520
|
+
const cur = this.stringBuilder[counter];
|
|
9521
|
+
const indexOfNl = cur.lastIndexOf("\n");
|
|
9522
|
+
if (indexOfNl >= 0) {
|
|
9523
|
+
onEmpty = isEmptyTest.test(cur.slice(indexOfNl));
|
|
9524
|
+
if (onEmpty) {
|
|
9525
|
+
const newVal = cur.slice(0, indexOfNl);
|
|
9526
|
+
if (newVal) {
|
|
9527
|
+
this.stringBuilder[counter] = cur.slice(0, indexOfNl);
|
|
9528
|
+
} else {
|
|
9529
|
+
this.stringBuilder.splice(counter, 1);
|
|
9530
|
+
}
|
|
9531
|
+
}
|
|
9532
|
+
break;
|
|
9533
|
+
}
|
|
9534
|
+
onEmpty = isEmptyTest.test(cur);
|
|
9535
|
+
counter--;
|
|
9536
|
+
}
|
|
9537
|
+
this.print("\n", ...args);
|
|
9538
|
+
};
|
|
9539
|
+
};
|
|
9540
|
+
|
|
9541
|
+
// lib/generator-builder/generatorBuilder.js
|
|
9542
|
+
function listToRuleDefMap(rules) {
|
|
9543
|
+
const newRules = {};
|
|
9544
|
+
for (const rule of rules) {
|
|
9545
|
+
newRules[rule.name] = rule;
|
|
9365
9546
|
}
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
recordProd.call(this, RepetitionMandatoryWithSeparator, options, occurrence, HANDLE_SEPARATOR);
|
|
9547
|
+
return newRules;
|
|
9548
|
+
}
|
|
9549
|
+
var GeneratorBuilder = class _GeneratorBuilder {
|
|
9550
|
+
static create(start) {
|
|
9551
|
+
if (start instanceof _GeneratorBuilder) {
|
|
9552
|
+
return new _GeneratorBuilder({ ...start.rules });
|
|
9553
|
+
}
|
|
9554
|
+
return new _GeneratorBuilder(listToRuleDefMap(start));
|
|
9375
9555
|
}
|
|
9376
|
-
|
|
9377
|
-
|
|
9556
|
+
rules;
|
|
9557
|
+
constructor(startRules) {
|
|
9558
|
+
this.rules = startRules;
|
|
9378
9559
|
}
|
|
9379
|
-
|
|
9380
|
-
|
|
9560
|
+
widenContext() {
|
|
9561
|
+
return this;
|
|
9381
9562
|
}
|
|
9382
|
-
|
|
9383
|
-
return
|
|
9563
|
+
typePatch() {
|
|
9564
|
+
return this;
|
|
9384
9565
|
}
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
}
|
|
9393
|
-
const prevProd = last_default(this.recordingProdStack);
|
|
9394
|
-
const ruleName = ruleToCall.ruleName;
|
|
9395
|
-
const newNoneTerminal = new NonTerminal({
|
|
9396
|
-
idx: occurrence,
|
|
9397
|
-
nonTerminalName: ruleName,
|
|
9398
|
-
label: options === null || options === void 0 ? void 0 : options.LABEL,
|
|
9399
|
-
// The resolving of the `referencedRule` property will be done once all the Rule's GASTs have been created
|
|
9400
|
-
referencedRule: void 0
|
|
9401
|
-
});
|
|
9402
|
-
prevProd.definition.push(newNoneTerminal);
|
|
9403
|
-
return this.outputCst ? RECORDING_PHASE_CSTNODE : RECORDING_NULL_OBJECT;
|
|
9566
|
+
/**
|
|
9567
|
+
* Change the implementation of an existing generator rule.
|
|
9568
|
+
*/
|
|
9569
|
+
patchRule(patch) {
|
|
9570
|
+
const self2 = this;
|
|
9571
|
+
self2.rules[patch.name] = patch;
|
|
9572
|
+
return self2;
|
|
9404
9573
|
}
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9574
|
+
/**
|
|
9575
|
+
* Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.
|
|
9576
|
+
*/
|
|
9577
|
+
addRuleRedundant(rule) {
|
|
9578
|
+
const self2 = this;
|
|
9579
|
+
const rules = self2.rules;
|
|
9580
|
+
if (rules[rule.name] !== void 0 && rules[rule.name] !== rule) {
|
|
9581
|
+
throw new Error(`Rule ${rule.name} already exists in the GeneratorBuilder`);
|
|
9412
9582
|
}
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
idx: occurrence,
|
|
9416
|
-
terminalType: tokType,
|
|
9417
|
-
label: options === null || options === void 0 ? void 0 : options.LABEL
|
|
9418
|
-
});
|
|
9419
|
-
prevProd.definition.push(newNoneTerminal);
|
|
9420
|
-
return RECORDING_PHASE_TOKEN;
|
|
9421
|
-
}
|
|
9422
|
-
};
|
|
9423
|
-
function recordProd(prodConstructor, mainProdArg, occurrence, handleSep = false) {
|
|
9424
|
-
assertMethodIdxIsValid(occurrence);
|
|
9425
|
-
const prevProd = last_default(this.recordingProdStack);
|
|
9426
|
-
const grammarAction = isFunction_default(mainProdArg) ? mainProdArg : mainProdArg.DEF;
|
|
9427
|
-
const newProd = new prodConstructor({ definition: [], idx: occurrence });
|
|
9428
|
-
if (handleSep) {
|
|
9429
|
-
newProd.separator = mainProdArg.SEP;
|
|
9430
|
-
}
|
|
9431
|
-
if (has_default(mainProdArg, "MAX_LOOKAHEAD")) {
|
|
9432
|
-
newProd.maxLookahead = mainProdArg.MAX_LOOKAHEAD;
|
|
9583
|
+
rules[rule.name] = rule;
|
|
9584
|
+
return self2;
|
|
9433
9585
|
}
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
}
|
|
9440
|
-
function recordOrProd(mainProdArg, occurrence) {
|
|
9441
|
-
assertMethodIdxIsValid(occurrence);
|
|
9442
|
-
const prevProd = last_default(this.recordingProdStack);
|
|
9443
|
-
const hasOptions = isArray_default(mainProdArg) === false;
|
|
9444
|
-
const alts = hasOptions === false ? mainProdArg : mainProdArg.DEF;
|
|
9445
|
-
const newOrProd = new Alternation({
|
|
9446
|
-
definition: [],
|
|
9447
|
-
idx: occurrence,
|
|
9448
|
-
ignoreAmbiguities: hasOptions && mainProdArg.IGNORE_AMBIGUITIES === true
|
|
9449
|
-
});
|
|
9450
|
-
if (has_default(mainProdArg, "MAX_LOOKAHEAD")) {
|
|
9451
|
-
newOrProd.maxLookahead = mainProdArg.MAX_LOOKAHEAD;
|
|
9586
|
+
/**
|
|
9587
|
+
* Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
|
|
9588
|
+
*/
|
|
9589
|
+
addRule(rule) {
|
|
9590
|
+
return this.addRuleRedundant(rule);
|
|
9452
9591
|
}
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
forEach_default(alts, (currAlt) => {
|
|
9457
|
-
const currAltFlat = new Alternative({ definition: [] });
|
|
9458
|
-
newOrProd.definition.push(currAltFlat);
|
|
9459
|
-
if (has_default(currAlt, "IGNORE_AMBIGUITIES")) {
|
|
9460
|
-
currAltFlat.ignoreAmbiguities = currAlt.IGNORE_AMBIGUITIES;
|
|
9461
|
-
} else if (has_default(currAlt, "GATE")) {
|
|
9462
|
-
currAltFlat.ignoreAmbiguities = true;
|
|
9463
|
-
}
|
|
9464
|
-
this.recordingProdStack.push(currAltFlat);
|
|
9465
|
-
currAlt.ALT.call(this);
|
|
9466
|
-
this.recordingProdStack.pop();
|
|
9467
|
-
});
|
|
9468
|
-
return RECORDING_NULL_OBJECT;
|
|
9469
|
-
}
|
|
9470
|
-
function getIdxSuffix(idx) {
|
|
9471
|
-
return idx === 0 ? "" : `${idx}`;
|
|
9472
|
-
}
|
|
9473
|
-
function assertMethodIdxIsValid(idx) {
|
|
9474
|
-
if (idx < 0 || idx > MAX_METHOD_IDX) {
|
|
9475
|
-
const error = new Error(
|
|
9476
|
-
// The stack trace will contain all the needed details
|
|
9477
|
-
`Invalid DSL Method idx value: <${idx}>
|
|
9478
|
-
Idx value must be a none negative value smaller than ${MAX_METHOD_IDX + 1}`
|
|
9479
|
-
);
|
|
9480
|
-
error.KNOWN_RECORDER_ERROR = true;
|
|
9481
|
-
throw error;
|
|
9592
|
+
addMany(...rules) {
|
|
9593
|
+
this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
|
|
9594
|
+
return this;
|
|
9482
9595
|
}
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
const userTraceInitPerf = config.traceInitPerf;
|
|
9490
|
-
const traceIsNumber = typeof userTraceInitPerf === "number";
|
|
9491
|
-
this.traceInitMaxIdent = traceIsNumber ? userTraceInitPerf : Infinity;
|
|
9492
|
-
this.traceInitPerf = traceIsNumber ? userTraceInitPerf > 0 : userTraceInitPerf;
|
|
9493
|
-
} else {
|
|
9494
|
-
this.traceInitMaxIdent = 0;
|
|
9495
|
-
this.traceInitPerf = DEFAULT_PARSER_CONFIG.traceInitPerf;
|
|
9496
|
-
}
|
|
9497
|
-
this.traceInitIndent = -1;
|
|
9596
|
+
/**
|
|
9597
|
+
* Delete a grammar rule by its name.
|
|
9598
|
+
*/
|
|
9599
|
+
deleteRule(ruleName) {
|
|
9600
|
+
delete this.rules[ruleName];
|
|
9601
|
+
return this;
|
|
9498
9602
|
}
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9603
|
+
/**
|
|
9604
|
+
* Merge this grammar GeneratorBuilder with another.
|
|
9605
|
+
* It is best to merge the bigger grammar with the smaller one.
|
|
9606
|
+
* If the two builders both have a grammar rule with the same name,
|
|
9607
|
+
* no error will be thrown case they map to the same ruledef object.
|
|
9608
|
+
* If they map to a different object, an error will be thrown.
|
|
9609
|
+
* To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
|
|
9610
|
+
* this rule implementation will be used.
|
|
9611
|
+
*/
|
|
9612
|
+
merge(GeneratorBuilder2, overridingRules) {
|
|
9613
|
+
const otherRules = { ...GeneratorBuilder2.rules };
|
|
9614
|
+
const myRules = this.rules;
|
|
9615
|
+
for (const rule of Object.values(myRules)) {
|
|
9616
|
+
if (otherRules[rule.name] === void 0) {
|
|
9617
|
+
otherRules[rule.name] = rule;
|
|
9618
|
+
} else {
|
|
9619
|
+
const existingRule = otherRules[rule.name];
|
|
9620
|
+
if (existingRule !== rule) {
|
|
9621
|
+
const override = overridingRules.find((x) => x.name === rule.name);
|
|
9622
|
+
if (override) {
|
|
9623
|
+
otherRules[rule.name] = override;
|
|
9624
|
+
} else {
|
|
9625
|
+
throw new Error(`Rule with name "${rule.name}" already exists in the GeneratorBuilder, specify an override to resolve conflict`);
|
|
9626
|
+
}
|
|
9627
|
+
}
|
|
9510
9628
|
}
|
|
9511
|
-
this.traceInitIndent--;
|
|
9512
|
-
return value;
|
|
9513
|
-
} else {
|
|
9514
|
-
return phaseImpl();
|
|
9515
9629
|
}
|
|
9630
|
+
this.rules = otherRules;
|
|
9631
|
+
return this;
|
|
9632
|
+
}
|
|
9633
|
+
build() {
|
|
9634
|
+
return new DynamicGenerator(this.rules);
|
|
9516
9635
|
}
|
|
9517
9636
|
};
|
|
9518
9637
|
|
|
9519
|
-
//
|
|
9520
|
-
function
|
|
9521
|
-
|
|
9522
|
-
|
|
9523
|
-
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
}
|
|
9527
|
-
const basePropDescriptor = Object.getOwnPropertyDescriptor(baseProto, propName);
|
|
9528
|
-
if (basePropDescriptor && (basePropDescriptor.get || basePropDescriptor.set)) {
|
|
9529
|
-
Object.defineProperty(derivedCtor.prototype, propName, basePropDescriptor);
|
|
9530
|
-
} else {
|
|
9531
|
-
derivedCtor.prototype[propName] = baseCtor.prototype[propName];
|
|
9532
|
-
}
|
|
9533
|
-
});
|
|
9534
|
-
});
|
|
9638
|
+
// lib/indirection-builder/helpers.js
|
|
9639
|
+
function listToIndirectionMap(rules) {
|
|
9640
|
+
const newRules = {};
|
|
9641
|
+
for (const rule of rules) {
|
|
9642
|
+
newRules[rule.name] = rule;
|
|
9643
|
+
}
|
|
9644
|
+
return newRules;
|
|
9535
9645
|
}
|
|
9536
9646
|
|
|
9537
|
-
//
|
|
9538
|
-
var
|
|
9539
|
-
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
}
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9647
|
+
// lib/indirection-builder/dynamicIndirected.js
|
|
9648
|
+
var DynamicIndirect = class {
|
|
9649
|
+
rules;
|
|
9650
|
+
__context = void 0;
|
|
9651
|
+
constructor(rules) {
|
|
9652
|
+
this.rules = rules;
|
|
9653
|
+
for (const rule of Object.values(rules)) {
|
|
9654
|
+
this[rule.name] = ((context, ...args) => {
|
|
9655
|
+
this.setContext(context);
|
|
9656
|
+
return this.subrule(rule, ...args);
|
|
9657
|
+
});
|
|
9658
|
+
}
|
|
9659
|
+
}
|
|
9660
|
+
setContext(context) {
|
|
9661
|
+
this.__context = context;
|
|
9662
|
+
}
|
|
9663
|
+
getSafeContext() {
|
|
9664
|
+
return this.__context;
|
|
9665
|
+
}
|
|
9666
|
+
subrule = (cstDef, ...args) => {
|
|
9667
|
+
const def = this.rules[cstDef.name];
|
|
9668
|
+
if (!def) {
|
|
9669
|
+
throw new Error(`Rule ${cstDef.name} not found`);
|
|
9670
|
+
}
|
|
9671
|
+
return def.fun({
|
|
9672
|
+
SUBRULE: this.subrule
|
|
9673
|
+
})(this.getSafeContext(), ...args);
|
|
9674
|
+
};
|
|
9675
|
+
};
|
|
9676
|
+
|
|
9677
|
+
// lib/indirection-builder/IndirBuilder.js
|
|
9678
|
+
var IndirBuilder = class _IndirBuilder {
|
|
9679
|
+
static create(start) {
|
|
9680
|
+
if (start instanceof _IndirBuilder) {
|
|
9681
|
+
return new _IndirBuilder({ ...start.rules });
|
|
9682
|
+
}
|
|
9683
|
+
return new _IndirBuilder(listToIndirectionMap(start));
|
|
9684
|
+
}
|
|
9685
|
+
rules;
|
|
9686
|
+
constructor(startRules) {
|
|
9687
|
+
this.rules = startRules;
|
|
9688
|
+
}
|
|
9689
|
+
widenContext() {
|
|
9690
|
+
return this;
|
|
9691
|
+
}
|
|
9692
|
+
typePatch() {
|
|
9693
|
+
return this;
|
|
9694
|
+
}
|
|
9572
9695
|
/**
|
|
9573
|
-
*
|
|
9696
|
+
* Change the implementation of an existing indirection.
|
|
9574
9697
|
*/
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
this.TRACE_INIT("performSelfAnalysis", () => {
|
|
9580
|
-
let defErrorsMsgs;
|
|
9581
|
-
this.selfAnalysisDone = true;
|
|
9582
|
-
const className = this.className;
|
|
9583
|
-
this.TRACE_INIT("toFastProps", () => {
|
|
9584
|
-
toFastProperties(this);
|
|
9585
|
-
});
|
|
9586
|
-
this.TRACE_INIT("Grammar Recording", () => {
|
|
9587
|
-
try {
|
|
9588
|
-
this.enableRecording();
|
|
9589
|
-
forEach_default(this.definedRulesNames, (currRuleName) => {
|
|
9590
|
-
const wrappedRule = this[currRuleName];
|
|
9591
|
-
const originalGrammarAction = wrappedRule["originalGrammarAction"];
|
|
9592
|
-
let recordedRuleGast;
|
|
9593
|
-
this.TRACE_INIT(`${currRuleName} Rule`, () => {
|
|
9594
|
-
recordedRuleGast = this.topLevelRuleRecord(currRuleName, originalGrammarAction);
|
|
9595
|
-
});
|
|
9596
|
-
this.gastProductionsCache[currRuleName] = recordedRuleGast;
|
|
9597
|
-
});
|
|
9598
|
-
} finally {
|
|
9599
|
-
this.disableRecording();
|
|
9600
|
-
}
|
|
9601
|
-
});
|
|
9602
|
-
let resolverErrors = [];
|
|
9603
|
-
this.TRACE_INIT("Grammar Resolving", () => {
|
|
9604
|
-
resolverErrors = resolveGrammar2({
|
|
9605
|
-
rules: values_default(this.gastProductionsCache)
|
|
9606
|
-
});
|
|
9607
|
-
this.definitionErrors = this.definitionErrors.concat(resolverErrors);
|
|
9608
|
-
});
|
|
9609
|
-
this.TRACE_INIT("Grammar Validations", () => {
|
|
9610
|
-
if (isEmpty_default(resolverErrors) && this.skipValidations === false) {
|
|
9611
|
-
const validationErrors = validateGrammar2({
|
|
9612
|
-
rules: values_default(this.gastProductionsCache),
|
|
9613
|
-
tokenTypes: values_default(this.tokensMap),
|
|
9614
|
-
errMsgProvider: defaultGrammarValidatorErrorProvider,
|
|
9615
|
-
grammarName: className
|
|
9616
|
-
});
|
|
9617
|
-
const lookaheadValidationErrors = validateLookahead({
|
|
9618
|
-
lookaheadStrategy: this.lookaheadStrategy,
|
|
9619
|
-
rules: values_default(this.gastProductionsCache),
|
|
9620
|
-
tokenTypes: values_default(this.tokensMap),
|
|
9621
|
-
grammarName: className
|
|
9622
|
-
});
|
|
9623
|
-
this.definitionErrors = this.definitionErrors.concat(validationErrors, lookaheadValidationErrors);
|
|
9624
|
-
}
|
|
9625
|
-
});
|
|
9626
|
-
if (isEmpty_default(this.definitionErrors)) {
|
|
9627
|
-
if (this.recoveryEnabled) {
|
|
9628
|
-
this.TRACE_INIT("computeAllProdsFollows", () => {
|
|
9629
|
-
const allFollows = computeAllProdsFollows(values_default(this.gastProductionsCache));
|
|
9630
|
-
this.resyncFollows = allFollows;
|
|
9631
|
-
});
|
|
9632
|
-
}
|
|
9633
|
-
this.TRACE_INIT("ComputeLookaheadFunctions", () => {
|
|
9634
|
-
var _a, _b;
|
|
9635
|
-
(_b = (_a = this.lookaheadStrategy).initialize) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
9636
|
-
rules: values_default(this.gastProductionsCache)
|
|
9637
|
-
});
|
|
9638
|
-
this.preComputeLookaheadFunctions(values_default(this.gastProductionsCache));
|
|
9639
|
-
});
|
|
9640
|
-
}
|
|
9641
|
-
if (!_Parser.DEFER_DEFINITION_ERRORS_HANDLING && !isEmpty_default(this.definitionErrors)) {
|
|
9642
|
-
defErrorsMsgs = map_default(this.definitionErrors, (defError) => defError.message);
|
|
9643
|
-
throw new Error(`Parser Definition Errors detected:
|
|
9644
|
-
${defErrorsMsgs.join("\n-------------------------------\n")}`);
|
|
9645
|
-
}
|
|
9646
|
-
});
|
|
9698
|
+
patchRule(patch) {
|
|
9699
|
+
const self2 = this;
|
|
9700
|
+
self2.rules[patch.name] = patch;
|
|
9701
|
+
return self2;
|
|
9647
9702
|
}
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
|
|
9655
|
-
|
|
9656
|
-
that.initRecoverable(config);
|
|
9657
|
-
that.initTreeBuilder(config);
|
|
9658
|
-
that.initContentAssist();
|
|
9659
|
-
that.initGastRecorder(config);
|
|
9660
|
-
that.initPerformanceTracer(config);
|
|
9661
|
-
if (has_default(config, "ignoredIssues")) {
|
|
9662
|
-
throw new Error("The <ignoredIssues> IParserConfig property has been deprecated.\n Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.\n See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES\n For further details.");
|
|
9703
|
+
/**
|
|
9704
|
+
* Add an indirection function. If the rule already exists, but the implementation differs, an error will be thrown.
|
|
9705
|
+
*/
|
|
9706
|
+
addRuleRedundant(rule) {
|
|
9707
|
+
const self2 = this;
|
|
9708
|
+
const rules = self2.rules;
|
|
9709
|
+
if (rules[rule.name] !== void 0 && rules[rule.name] !== rule) {
|
|
9710
|
+
throw new Error(`Function ${rule.name} already exists in the builder`);
|
|
9663
9711
|
}
|
|
9664
|
-
|
|
9712
|
+
rules[rule.name] = rule;
|
|
9713
|
+
return self2;
|
|
9665
9714
|
}
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9715
|
+
/**
|
|
9716
|
+
* Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
|
|
9717
|
+
*/
|
|
9718
|
+
addRule(rule) {
|
|
9719
|
+
return this.addRuleRedundant(rule);
|
|
9720
|
+
}
|
|
9721
|
+
addMany(...rules) {
|
|
9722
|
+
this.rules = { ...this.rules, ...listToIndirectionMap(rules) };
|
|
9723
|
+
return this;
|
|
9724
|
+
}
|
|
9725
|
+
/**
|
|
9726
|
+
* Delete a grammar rule by its name.
|
|
9727
|
+
*/
|
|
9728
|
+
deleteRule(ruleName) {
|
|
9729
|
+
delete this.rules[ruleName];
|
|
9730
|
+
return this;
|
|
9731
|
+
}
|
|
9732
|
+
build() {
|
|
9733
|
+
return new DynamicIndirect(this.rules);
|
|
9685
9734
|
}
|
|
9686
9735
|
};
|
|
9687
9736
|
|
|
@@ -10047,14 +10096,6 @@ ${firstError.message}`);
|
|
|
10047
10096
|
}
|
|
10048
10097
|
};
|
|
10049
10098
|
|
|
10050
|
-
// lib/utils.js
|
|
10051
|
-
function unCapitalize(str) {
|
|
10052
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
10053
|
-
}
|
|
10054
|
-
function createToken2(config) {
|
|
10055
|
-
return createToken(config);
|
|
10056
|
-
}
|
|
10057
|
-
|
|
10058
10099
|
// lib/Transformers.js
|
|
10059
10100
|
var TransformerType = class {
|
|
10060
10101
|
safeObjectVisit(value, mapper) {
|