@traqula/core 0.0.1-alpha.148 → 0.0.1-alpha.176
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/README.md +44 -22
- package/lib/generator-builder/builderTypes.d.ts +20 -0
- package/lib/generator-builder/builderTypes.js.map +1 -0
- package/lib/generator-builder/dynamicGenerator.d.ts +7 -0
- package/lib/generator-builder/dynamicGenerator.js +28 -0
- package/lib/generator-builder/dynamicGenerator.js.map +1 -0
- package/lib/generator-builder/generatorBuilder.d.ts +58 -0
- package/lib/generator-builder/generatorBuilder.js +101 -0
- package/lib/generator-builder/generatorBuilder.js.map +1 -0
- package/lib/generator-builder/generatorTypes.d.ts +27 -0
- package/lib/generator-builder/generatorTypes.js +2 -0
- package/lib/generator-builder/generatorTypes.js.map +1 -0
- package/lib/index.cjs +379 -320
- package/lib/index.d.ts +7 -6
- package/lib/index.js +11 -6
- package/lib/index.js.map +1 -1
- package/lib/lexer-builder/LexerBuilder.d.ts +7 -9
- package/lib/lexer-builder/LexerBuilder.js +12 -4
- package/lib/lexer-builder/LexerBuilder.js.map +1 -1
- package/lib/parser-builder/builderTypes.d.ts +24 -0
- package/lib/parser-builder/builderTypes.js +2 -0
- package/lib/parser-builder/builderTypes.js.map +1 -0
- package/lib/parser-builder/dynamicParser.d.ts +9 -0
- package/lib/parser-builder/dynamicParser.js +113 -0
- package/lib/parser-builder/dynamicParser.js.map +1 -0
- package/lib/parser-builder/parserBuilder.d.ts +73 -0
- package/lib/parser-builder/parserBuilder.js +161 -0
- package/lib/parser-builder/parserBuilder.js.map +1 -0
- package/lib/{grammar-builder → parser-builder}/ruleDefTypes.d.ts +5 -5
- package/lib/parser-builder/ruleDefTypes.js.map +1 -0
- package/lib/utils.d.ts +17 -0
- package/lib/utils.js +8 -0
- package/lib/utils.js.map +1 -0
- package/package.json +6 -6
- package/lib/Wildcard.d.ts +0 -9
- package/lib/Wildcard.js +0 -19
- package/lib/Wildcard.js.map +0 -1
- package/lib/grammar-builder/builderTypes.d.ts +0 -28
- package/lib/grammar-builder/builderTypes.js.map +0 -1
- package/lib/grammar-builder/parserBuilder.d.ts +0 -68
- package/lib/grammar-builder/parserBuilder.js +0 -283
- package/lib/grammar-builder/parserBuilder.js.map +0 -1
- package/lib/grammar-builder/ruleDefTypes.js.map +0 -1
- package/lib/grammar-helpers/utils.d.ts +0 -16
- package/lib/grammar-helpers/utils.js +0 -53
- package/lib/grammar-helpers/utils.js.map +0 -1
- package/lib/lexer-helper/utils.d.ts +0 -6
- package/lib/lexer-helper/utils.js +0 -5
- package/lib/lexer-helper/utils.js.map +0 -1
- /package/lib/{grammar-builder → generator-builder}/builderTypes.js +0 -0
- /package/lib/{grammar-builder → parser-builder}/ruleDefTypes.js +0 -0
package/lib/index.cjs
CHANGED
|
@@ -20,16 +20,135 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// lib/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
24
|
-
CommonIRIs: () => CommonIRIs,
|
|
23
|
+
GeneratorBuilder: () => GeneratorBuilder,
|
|
25
24
|
LexerBuilder: () => LexerBuilder,
|
|
26
|
-
|
|
25
|
+
ParserBuilder: () => ParserBuilder,
|
|
27
26
|
createToken: () => createToken2,
|
|
28
|
-
resolveIRI: () => resolveIRI,
|
|
29
27
|
unCapitalize: () => unCapitalize
|
|
30
28
|
});
|
|
31
29
|
module.exports = __toCommonJS(index_exports);
|
|
32
30
|
|
|
31
|
+
// lib/generator-builder/dynamicGenerator.ts
|
|
32
|
+
var DynamicGenerator = class {
|
|
33
|
+
constructor(rules) {
|
|
34
|
+
this.__context = void 0;
|
|
35
|
+
const selfRef = {
|
|
36
|
+
SUBRULE: (cstDef, input, arg) => {
|
|
37
|
+
const def = rules[cstDef.name];
|
|
38
|
+
if (!def) {
|
|
39
|
+
throw new Error(`Rule ${cstDef.name} not found`);
|
|
40
|
+
}
|
|
41
|
+
return def.gImpl(selfRef)(input, this.getSafeContext(), arg);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
for (const rule of Object.values(rules)) {
|
|
45
|
+
this[rule.name] = (input, context, args) => {
|
|
46
|
+
this.setContext(context);
|
|
47
|
+
return rule.gImpl(selfRef)(input, this.getSafeContext(), args);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
setContext(context) {
|
|
52
|
+
this.__context = context;
|
|
53
|
+
}
|
|
54
|
+
getSafeContext() {
|
|
55
|
+
return this.__context;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// lib/generator-builder/generatorBuilder.ts
|
|
60
|
+
function listToRuleDefMap(rules) {
|
|
61
|
+
const newRules = {};
|
|
62
|
+
for (const rule of rules) {
|
|
63
|
+
newRules[rule.name] = rule;
|
|
64
|
+
}
|
|
65
|
+
return newRules;
|
|
66
|
+
}
|
|
67
|
+
var GeneratorBuilder = class _GeneratorBuilder {
|
|
68
|
+
static createBuilder(start) {
|
|
69
|
+
if (start instanceof _GeneratorBuilder) {
|
|
70
|
+
return new _GeneratorBuilder({ ...start.rules });
|
|
71
|
+
}
|
|
72
|
+
return new _GeneratorBuilder(listToRuleDefMap(start));
|
|
73
|
+
}
|
|
74
|
+
constructor(startRules) {
|
|
75
|
+
this.rules = startRules;
|
|
76
|
+
}
|
|
77
|
+
typePatch() {
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Change the implementation of an existing generator rule.
|
|
82
|
+
*/
|
|
83
|
+
patchRule(patch) {
|
|
84
|
+
const self2 = this;
|
|
85
|
+
self2.rules[patch.name] = patch;
|
|
86
|
+
return self2;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.
|
|
90
|
+
*/
|
|
91
|
+
addRuleRedundant(rule) {
|
|
92
|
+
const self2 = this;
|
|
93
|
+
const rules = self2.rules;
|
|
94
|
+
if (rules[rule.name] !== void 0 && rules[rule.name] !== rule) {
|
|
95
|
+
throw new Error(`Rule ${rule.name} already exists in the GeneratorBuilder`);
|
|
96
|
+
}
|
|
97
|
+
rules[rule.name] = rule;
|
|
98
|
+
return self2;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
|
|
102
|
+
*/
|
|
103
|
+
addRule(rule) {
|
|
104
|
+
return this.addRuleRedundant(rule);
|
|
105
|
+
}
|
|
106
|
+
addMany(...rules) {
|
|
107
|
+
this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Delete a grammar rule by its name.
|
|
112
|
+
*/
|
|
113
|
+
deleteRule(ruleName) {
|
|
114
|
+
delete this.rules[ruleName];
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Merge this grammar GeneratorBuilder with another.
|
|
119
|
+
* It is best to merge the bigger grammar with the smaller one.
|
|
120
|
+
* If the two builders both have a grammar rule with the same name,
|
|
121
|
+
* no error will be thrown case they map to the same ruledef object.
|
|
122
|
+
* If they map to a different object, an error will be thrown.
|
|
123
|
+
* To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
|
|
124
|
+
* this rule implementation will be used.
|
|
125
|
+
*/
|
|
126
|
+
merge(GeneratorBuilder2, overridingRules) {
|
|
127
|
+
const otherRules = { ...GeneratorBuilder2.rules };
|
|
128
|
+
const myRules = this.rules;
|
|
129
|
+
for (const rule of Object.values(myRules)) {
|
|
130
|
+
if (otherRules[rule.name] === void 0) {
|
|
131
|
+
otherRules[rule.name] = rule;
|
|
132
|
+
} else {
|
|
133
|
+
const existingRule = otherRules[rule.name];
|
|
134
|
+
if (existingRule !== rule) {
|
|
135
|
+
const override = overridingRules.find((x) => x.name === rule.name);
|
|
136
|
+
if (override) {
|
|
137
|
+
otherRules[rule.name] = override;
|
|
138
|
+
} else {
|
|
139
|
+
throw new Error(`Rule with name "${rule.name}" already exists in the GeneratorBuilder, specify an override to resolve conflict`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this.rules = otherRules;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
build() {
|
|
148
|
+
return new DynamicGenerator(this.rules);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
33
152
|
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
34
153
|
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
35
154
|
var freeGlobal_default = freeGlobal;
|
|
@@ -9248,28 +9367,235 @@ var EmbeddedActionsParser = class extends Parser {
|
|
|
9248
9367
|
}
|
|
9249
9368
|
};
|
|
9250
9369
|
|
|
9251
|
-
// lib/
|
|
9252
|
-
|
|
9370
|
+
// lib/lexer-builder/LexerBuilder.ts
|
|
9371
|
+
var LexerBuilder = class _LexerBuilder {
|
|
9372
|
+
static create(starter) {
|
|
9373
|
+
return new _LexerBuilder(starter);
|
|
9374
|
+
}
|
|
9375
|
+
constructor(starter) {
|
|
9376
|
+
this.tokens = starter?.tokens ? [...starter.tokens] : [];
|
|
9377
|
+
}
|
|
9378
|
+
merge(merge, overwrite = []) {
|
|
9379
|
+
const extraTokens = merge.tokens.filter((token) => {
|
|
9380
|
+
const overwriteToken = overwrite.find((t) => t.name === token.name);
|
|
9381
|
+
if (overwriteToken) {
|
|
9382
|
+
return false;
|
|
9383
|
+
}
|
|
9384
|
+
const match = this.tokens.find((t) => t.name === token.name);
|
|
9385
|
+
if (match) {
|
|
9386
|
+
if (match !== token) {
|
|
9387
|
+
throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);
|
|
9388
|
+
}
|
|
9389
|
+
return false;
|
|
9390
|
+
}
|
|
9391
|
+
return true;
|
|
9392
|
+
});
|
|
9393
|
+
this.tokens.push(...extraTokens);
|
|
9394
|
+
return this;
|
|
9395
|
+
}
|
|
9396
|
+
add(...token) {
|
|
9397
|
+
this.tokens.push(...token);
|
|
9398
|
+
return this;
|
|
9399
|
+
}
|
|
9400
|
+
addBefore(before, ...token) {
|
|
9401
|
+
const index = this.tokens.indexOf(before);
|
|
9402
|
+
if (index === -1) {
|
|
9403
|
+
throw new Error("Token not found");
|
|
9404
|
+
}
|
|
9405
|
+
this.tokens.splice(index, 0, ...token);
|
|
9406
|
+
return this;
|
|
9407
|
+
}
|
|
9408
|
+
moveBeforeOrAfter(beforeOrAfter, before, ...tokens) {
|
|
9409
|
+
const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === "before" ? 0 : 1);
|
|
9410
|
+
if (beforeIndex === -1) {
|
|
9411
|
+
throw new Error("BeforeToken not found");
|
|
9412
|
+
}
|
|
9413
|
+
for (const token of tokens) {
|
|
9414
|
+
const tokenIndex = this.tokens.indexOf(token);
|
|
9415
|
+
if (tokenIndex === -1) {
|
|
9416
|
+
throw new Error("Token not found");
|
|
9417
|
+
}
|
|
9418
|
+
this.tokens.splice(tokenIndex, 1);
|
|
9419
|
+
this.tokens.splice(beforeIndex, 0, token);
|
|
9420
|
+
}
|
|
9421
|
+
return this;
|
|
9422
|
+
}
|
|
9423
|
+
moveBefore(before, ...tokens) {
|
|
9424
|
+
return this.moveBeforeOrAfter("before", before, ...tokens);
|
|
9425
|
+
}
|
|
9426
|
+
moveAfter(after, ...tokens) {
|
|
9427
|
+
return this.moveBeforeOrAfter("after", after, ...tokens);
|
|
9428
|
+
}
|
|
9429
|
+
addAfter(after, ...token) {
|
|
9430
|
+
const index = this.tokens.indexOf(after);
|
|
9431
|
+
if (index === -1) {
|
|
9432
|
+
throw new Error("Token not found");
|
|
9433
|
+
}
|
|
9434
|
+
this.tokens.splice(index + 1, 0, ...token);
|
|
9435
|
+
return this;
|
|
9436
|
+
}
|
|
9437
|
+
delete(...token) {
|
|
9438
|
+
for (const t of token) {
|
|
9439
|
+
const index = this.tokens.indexOf(t);
|
|
9440
|
+
if (index === -1) {
|
|
9441
|
+
throw new Error("Token not found");
|
|
9442
|
+
}
|
|
9443
|
+
this.tokens.splice(index, 1);
|
|
9444
|
+
}
|
|
9445
|
+
return this;
|
|
9446
|
+
}
|
|
9447
|
+
build(lexerConfig) {
|
|
9448
|
+
return new Lexer(this.tokens, {
|
|
9449
|
+
positionTracking: "onlyStart",
|
|
9450
|
+
recoveryEnabled: false,
|
|
9451
|
+
// SafeMode: true,
|
|
9452
|
+
// SkipValidations: true,
|
|
9453
|
+
ensureOptimizations: true,
|
|
9454
|
+
...lexerConfig
|
|
9455
|
+
});
|
|
9456
|
+
}
|
|
9457
|
+
get tokenVocabulary() {
|
|
9458
|
+
return this.tokens;
|
|
9459
|
+
}
|
|
9460
|
+
};
|
|
9461
|
+
|
|
9462
|
+
// lib/parser-builder/dynamicParser.ts
|
|
9463
|
+
var DynamicParser = class extends EmbeddedActionsParser {
|
|
9464
|
+
setContext(context) {
|
|
9465
|
+
this.context = context;
|
|
9466
|
+
}
|
|
9467
|
+
constructor(rules, tokenVocabulary, config = {}) {
|
|
9468
|
+
super(tokenVocabulary, {
|
|
9469
|
+
// RecoveryEnabled: true,
|
|
9470
|
+
maxLookahead: 2,
|
|
9471
|
+
// SkipValidations: true,
|
|
9472
|
+
...config
|
|
9473
|
+
});
|
|
9474
|
+
this.context = void 0;
|
|
9475
|
+
const selfRef = this.constructSelfRef();
|
|
9476
|
+
const implArgs = {
|
|
9477
|
+
...selfRef,
|
|
9478
|
+
cache: /* @__PURE__ */ new WeakMap()
|
|
9479
|
+
};
|
|
9480
|
+
for (const rule of Object.values(rules)) {
|
|
9481
|
+
this[rule.name] = this.RULE(rule.name, rule.impl(implArgs));
|
|
9482
|
+
}
|
|
9483
|
+
this.performSelfAnalysis();
|
|
9484
|
+
}
|
|
9485
|
+
constructSelfRef() {
|
|
9486
|
+
const subRuleImpl = (chevrotainSubrule) => (cstDef, arg) => chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] });
|
|
9487
|
+
return {
|
|
9488
|
+
CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),
|
|
9489
|
+
CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),
|
|
9490
|
+
CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),
|
|
9491
|
+
CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),
|
|
9492
|
+
CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),
|
|
9493
|
+
CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),
|
|
9494
|
+
CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),
|
|
9495
|
+
CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),
|
|
9496
|
+
CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),
|
|
9497
|
+
CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),
|
|
9498
|
+
OPTION: (actionORMethodDef) => this.OPTION(actionORMethodDef),
|
|
9499
|
+
OPTION1: (actionORMethodDef) => this.OPTION1(actionORMethodDef),
|
|
9500
|
+
OPTION2: (actionORMethodDef) => this.OPTION2(actionORMethodDef),
|
|
9501
|
+
OPTION3: (actionORMethodDef) => this.OPTION3(actionORMethodDef),
|
|
9502
|
+
OPTION4: (actionORMethodDef) => this.OPTION4(actionORMethodDef),
|
|
9503
|
+
OPTION5: (actionORMethodDef) => this.OPTION5(actionORMethodDef),
|
|
9504
|
+
OPTION6: (actionORMethodDef) => this.OPTION6(actionORMethodDef),
|
|
9505
|
+
OPTION7: (actionORMethodDef) => this.OPTION7(actionORMethodDef),
|
|
9506
|
+
OPTION8: (actionORMethodDef) => this.OPTION8(actionORMethodDef),
|
|
9507
|
+
OPTION9: (actionORMethodDef) => this.OPTION9(actionORMethodDef),
|
|
9508
|
+
OR: (altsOrOpts) => this.OR(altsOrOpts),
|
|
9509
|
+
OR1: (altsOrOpts) => this.OR1(altsOrOpts),
|
|
9510
|
+
OR2: (altsOrOpts) => this.OR2(altsOrOpts),
|
|
9511
|
+
OR3: (altsOrOpts) => this.OR3(altsOrOpts),
|
|
9512
|
+
OR4: (altsOrOpts) => this.OR4(altsOrOpts),
|
|
9513
|
+
OR5: (altsOrOpts) => this.OR5(altsOrOpts),
|
|
9514
|
+
OR6: (altsOrOpts) => this.OR6(altsOrOpts),
|
|
9515
|
+
OR7: (altsOrOpts) => this.OR7(altsOrOpts),
|
|
9516
|
+
OR8: (altsOrOpts) => this.OR8(altsOrOpts),
|
|
9517
|
+
OR9: (altsOrOpts) => this.OR9(altsOrOpts),
|
|
9518
|
+
MANY: (actionORMethodDef) => this.MANY(actionORMethodDef),
|
|
9519
|
+
MANY1: (actionORMethodDef) => this.MANY1(actionORMethodDef),
|
|
9520
|
+
MANY2: (actionORMethodDef) => this.MANY2(actionORMethodDef),
|
|
9521
|
+
MANY3: (actionORMethodDef) => this.MANY3(actionORMethodDef),
|
|
9522
|
+
MANY4: (actionORMethodDef) => this.MANY4(actionORMethodDef),
|
|
9523
|
+
MANY5: (actionORMethodDef) => this.MANY5(actionORMethodDef),
|
|
9524
|
+
MANY6: (actionORMethodDef) => this.MANY6(actionORMethodDef),
|
|
9525
|
+
MANY7: (actionORMethodDef) => this.MANY7(actionORMethodDef),
|
|
9526
|
+
MANY8: (actionORMethodDef) => this.MANY8(actionORMethodDef),
|
|
9527
|
+
MANY9: (actionORMethodDef) => this.MANY9(actionORMethodDef),
|
|
9528
|
+
MANY_SEP: (options) => this.MANY_SEP(options),
|
|
9529
|
+
MANY_SEP1: (options) => this.MANY_SEP1(options),
|
|
9530
|
+
MANY_SEP2: (options) => this.MANY_SEP2(options),
|
|
9531
|
+
MANY_SEP3: (options) => this.MANY_SEP3(options),
|
|
9532
|
+
MANY_SEP4: (options) => this.MANY_SEP4(options),
|
|
9533
|
+
MANY_SEP5: (options) => this.MANY_SEP5(options),
|
|
9534
|
+
MANY_SEP6: (options) => this.MANY_SEP6(options),
|
|
9535
|
+
MANY_SEP7: (options) => this.MANY_SEP7(options),
|
|
9536
|
+
MANY_SEP8: (options) => this.MANY_SEP8(options),
|
|
9537
|
+
MANY_SEP9: (options) => this.MANY_SEP9(options),
|
|
9538
|
+
AT_LEAST_ONE: (actionORMethodDef) => this.AT_LEAST_ONE(actionORMethodDef),
|
|
9539
|
+
AT_LEAST_ONE1: (actionORMethodDef) => this.AT_LEAST_ONE1(actionORMethodDef),
|
|
9540
|
+
AT_LEAST_ONE2: (actionORMethodDef) => this.AT_LEAST_ONE2(actionORMethodDef),
|
|
9541
|
+
AT_LEAST_ONE3: (actionORMethodDef) => this.AT_LEAST_ONE3(actionORMethodDef),
|
|
9542
|
+
AT_LEAST_ONE4: (actionORMethodDef) => this.AT_LEAST_ONE4(actionORMethodDef),
|
|
9543
|
+
AT_LEAST_ONE5: (actionORMethodDef) => this.AT_LEAST_ONE5(actionORMethodDef),
|
|
9544
|
+
AT_LEAST_ONE6: (actionORMethodDef) => this.AT_LEAST_ONE6(actionORMethodDef),
|
|
9545
|
+
AT_LEAST_ONE7: (actionORMethodDef) => this.AT_LEAST_ONE7(actionORMethodDef),
|
|
9546
|
+
AT_LEAST_ONE8: (actionORMethodDef) => this.AT_LEAST_ONE8(actionORMethodDef),
|
|
9547
|
+
AT_LEAST_ONE9: (actionORMethodDef) => this.AT_LEAST_ONE9(actionORMethodDef),
|
|
9548
|
+
AT_LEAST_ONE_SEP: (options) => this.AT_LEAST_ONE_SEP(options),
|
|
9549
|
+
AT_LEAST_ONE_SEP1: (options) => this.AT_LEAST_ONE_SEP1(options),
|
|
9550
|
+
AT_LEAST_ONE_SEP2: (options) => this.AT_LEAST_ONE_SEP2(options),
|
|
9551
|
+
AT_LEAST_ONE_SEP3: (options) => this.AT_LEAST_ONE_SEP3(options),
|
|
9552
|
+
AT_LEAST_ONE_SEP4: (options) => this.AT_LEAST_ONE_SEP4(options),
|
|
9553
|
+
AT_LEAST_ONE_SEP5: (options) => this.AT_LEAST_ONE_SEP5(options),
|
|
9554
|
+
AT_LEAST_ONE_SEP6: (options) => this.AT_LEAST_ONE_SEP6(options),
|
|
9555
|
+
AT_LEAST_ONE_SEP7: (options) => this.AT_LEAST_ONE_SEP7(options),
|
|
9556
|
+
AT_LEAST_ONE_SEP8: (options) => this.AT_LEAST_ONE_SEP8(options),
|
|
9557
|
+
AT_LEAST_ONE_SEP9: (options) => this.AT_LEAST_ONE_SEP9(options),
|
|
9558
|
+
ACTION: (func) => this.ACTION(func),
|
|
9559
|
+
BACKTRACK: (cstDef, ...args) => this.BACKTRACK(this[cstDef.name], { ARGS: args }),
|
|
9560
|
+
SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),
|
|
9561
|
+
SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),
|
|
9562
|
+
SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),
|
|
9563
|
+
SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),
|
|
9564
|
+
SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),
|
|
9565
|
+
SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),
|
|
9566
|
+
SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),
|
|
9567
|
+
SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),
|
|
9568
|
+
SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),
|
|
9569
|
+
SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args))
|
|
9570
|
+
};
|
|
9571
|
+
}
|
|
9572
|
+
};
|
|
9573
|
+
|
|
9574
|
+
// lib/parser-builder/parserBuilder.ts
|
|
9575
|
+
function listToRuleDefMap2(rules) {
|
|
9253
9576
|
const newRules = {};
|
|
9254
9577
|
for (const rule of rules) {
|
|
9255
9578
|
newRules[rule.name] = rule;
|
|
9256
9579
|
}
|
|
9257
9580
|
return newRules;
|
|
9258
9581
|
}
|
|
9259
|
-
var
|
|
9582
|
+
var ParserBuilder = class _ParserBuilder {
|
|
9260
9583
|
/**
|
|
9261
9584
|
* Create a builder from some initial grammar rules or an existing builder.
|
|
9262
9585
|
* If a builder is provided, a new copy will be created.
|
|
9263
9586
|
*/
|
|
9264
9587
|
static createBuilder(start) {
|
|
9265
|
-
if (start instanceof
|
|
9266
|
-
return new
|
|
9588
|
+
if (start instanceof _ParserBuilder) {
|
|
9589
|
+
return new _ParserBuilder({ ...start.rules });
|
|
9267
9590
|
}
|
|
9268
|
-
return new
|
|
9591
|
+
return new _ParserBuilder(listToRuleDefMap2(start));
|
|
9269
9592
|
}
|
|
9270
9593
|
constructor(startRules) {
|
|
9271
9594
|
this.rules = startRules;
|
|
9272
9595
|
}
|
|
9596
|
+
typePatch() {
|
|
9597
|
+
return this;
|
|
9598
|
+
}
|
|
9273
9599
|
/**
|
|
9274
9600
|
* Change the implementation of an existing grammar rule.
|
|
9275
9601
|
*/
|
|
@@ -9297,7 +9623,7 @@ var Builder = class _Builder {
|
|
|
9297
9623
|
return this.addRuleRedundant(rule);
|
|
9298
9624
|
}
|
|
9299
9625
|
addMany(...rules) {
|
|
9300
|
-
this.rules = { ...this.rules, ...
|
|
9626
|
+
this.rules = { ...this.rules, ...listToRuleDefMap2(rules) };
|
|
9301
9627
|
return this;
|
|
9302
9628
|
}
|
|
9303
9629
|
/**
|
|
@@ -9310,9 +9636,11 @@ var Builder = class _Builder {
|
|
|
9310
9636
|
/**
|
|
9311
9637
|
* Merge this grammar builder with another.
|
|
9312
9638
|
* It is best to merge the bigger grammar with the smaller one.
|
|
9313
|
-
* If the two builders both have a grammar rule with the same name,
|
|
9639
|
+
* If the two builders both have a grammar rule with the same name,
|
|
9640
|
+
* no error will be thrown case they map to the same ruledef object.
|
|
9314
9641
|
* If they map to a different object, an error will be thrown.
|
|
9315
|
-
* To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
|
|
9642
|
+
* To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
|
|
9643
|
+
* this rule implementation will be used.
|
|
9316
9644
|
*/
|
|
9317
9645
|
merge(builder, overridingRules) {
|
|
9318
9646
|
const otherRules = { ...builder.rules };
|
|
@@ -9335,44 +9663,50 @@ var Builder = class _Builder {
|
|
|
9335
9663
|
this.rules = otherRules;
|
|
9336
9664
|
return this;
|
|
9337
9665
|
}
|
|
9338
|
-
|
|
9339
|
-
const
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9666
|
+
defaultErrorHandler(input, errors) {
|
|
9667
|
+
const firstError = errors[0];
|
|
9668
|
+
const messageBuilder = ["Parse error"];
|
|
9669
|
+
const lineIdx = firstError.token.startLine;
|
|
9670
|
+
if (lineIdx !== void 0) {
|
|
9671
|
+
const errorLine = input.split("\n")[lineIdx - 1];
|
|
9672
|
+
messageBuilder.push(` on line ${lineIdx}
|
|
9673
|
+
${errorLine}`);
|
|
9674
|
+
const columnIdx = firstError.token.startColumn;
|
|
9675
|
+
if (columnIdx !== void 0) {
|
|
9676
|
+
messageBuilder.push(`
|
|
9677
|
+
${"-".repeat(columnIdx - 1)}^`);
|
|
9678
|
+
}
|
|
9679
|
+
}
|
|
9680
|
+
messageBuilder.push(`
|
|
9681
|
+
${firstError.message}`);
|
|
9682
|
+
throw new Error(messageBuilder.join(""));
|
|
9683
|
+
}
|
|
9684
|
+
build({
|
|
9685
|
+
tokenVocabulary,
|
|
9686
|
+
parserConfig = {},
|
|
9687
|
+
lexerConfig = {},
|
|
9688
|
+
queryPreProcessor = (s) => s,
|
|
9689
|
+
errorHandler
|
|
9690
|
+
}) {
|
|
9691
|
+
const lexer = LexerBuilder.create().add(...tokenVocabulary).build(lexerConfig);
|
|
9692
|
+
const parser = this.consume({
|
|
9693
|
+
tokenVocabulary,
|
|
9694
|
+
config: parserConfig
|
|
9346
9695
|
});
|
|
9347
|
-
const parser = this.consume({ tokenVocabulary, config: parserConfig });
|
|
9348
9696
|
const selfSufficientParser = {};
|
|
9349
9697
|
for (const rule of Object.values(this.rules)) {
|
|
9350
9698
|
selfSufficientParser[rule.name] = (input, context, arg) => {
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
(_, unicode4, unicode8) => {
|
|
9354
|
-
if (unicode4) {
|
|
9355
|
-
const charCode2 = Number.parseInt(unicode4, 16);
|
|
9356
|
-
return String.fromCodePoint(charCode2);
|
|
9357
|
-
}
|
|
9358
|
-
const charCode = Number.parseInt(unicode8, 16);
|
|
9359
|
-
if (charCode < 65535) {
|
|
9360
|
-
return String.fromCodePoint(charCode);
|
|
9361
|
-
}
|
|
9362
|
-
const substractedCharCode = charCode - 65536;
|
|
9363
|
-
return String.fromCodePoint(55296 + (substractedCharCode >> 10), 56320 + (substractedCharCode & 1023));
|
|
9364
|
-
}
|
|
9365
|
-
);
|
|
9366
|
-
if (/[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/u.test(input)) {
|
|
9367
|
-
throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
|
|
9368
|
-
}
|
|
9369
|
-
const lexResult = lexer.tokenize(input);
|
|
9699
|
+
const processedInput = queryPreProcessor(input);
|
|
9700
|
+
const lexResult = lexer.tokenize(processedInput);
|
|
9370
9701
|
parser.input = lexResult.tokens;
|
|
9371
9702
|
parser.setContext(context);
|
|
9372
9703
|
const result = parser[rule.name](context, arg);
|
|
9373
9704
|
if (parser.errors.length > 0) {
|
|
9374
|
-
|
|
9375
|
-
|
|
9705
|
+
if (errorHandler) {
|
|
9706
|
+
errorHandler(parser.errors);
|
|
9707
|
+
} else {
|
|
9708
|
+
this.defaultErrorHandler(processedInput, parser.errors);
|
|
9709
|
+
}
|
|
9376
9710
|
}
|
|
9377
9711
|
return result;
|
|
9378
9712
|
};
|
|
@@ -9380,292 +9714,17 @@ ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
|
|
|
9380
9714
|
return selfSufficientParser;
|
|
9381
9715
|
}
|
|
9382
9716
|
consume({ tokenVocabulary, config = {} }) {
|
|
9383
|
-
|
|
9384
|
-
class MyParser extends EmbeddedActionsParser {
|
|
9385
|
-
getSafeContext() {
|
|
9386
|
-
if (this.context === void 0) {
|
|
9387
|
-
throw new Error("context was not correctly set");
|
|
9388
|
-
}
|
|
9389
|
-
return this.context;
|
|
9390
|
-
}
|
|
9391
|
-
setContext(context) {
|
|
9392
|
-
this.context = context;
|
|
9393
|
-
}
|
|
9394
|
-
constructor() {
|
|
9395
|
-
super(tokenVocabulary, {
|
|
9396
|
-
// RecoveryEnabled: true,
|
|
9397
|
-
maxLookahead: 2,
|
|
9398
|
-
// SkipValidations: true,
|
|
9399
|
-
...config
|
|
9400
|
-
});
|
|
9401
|
-
this.context = void 0;
|
|
9402
|
-
const selfRef = this.getSelfRef();
|
|
9403
|
-
const implArgs = {
|
|
9404
|
-
...selfRef,
|
|
9405
|
-
cache: /* @__PURE__ */ new WeakMap()
|
|
9406
|
-
};
|
|
9407
|
-
for (const rule of Object.values(rules)) {
|
|
9408
|
-
this[rule.name] = this.RULE(rule.name, rule.impl(implArgs));
|
|
9409
|
-
}
|
|
9410
|
-
this.performSelfAnalysis();
|
|
9411
|
-
}
|
|
9412
|
-
getSelfRef() {
|
|
9413
|
-
const subRuleImpl = (chevrotainSubrule) => {
|
|
9414
|
-
return (cstDef, arg) => {
|
|
9415
|
-
return chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] });
|
|
9416
|
-
};
|
|
9417
|
-
};
|
|
9418
|
-
return {
|
|
9419
|
-
CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),
|
|
9420
|
-
CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),
|
|
9421
|
-
CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),
|
|
9422
|
-
CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),
|
|
9423
|
-
CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),
|
|
9424
|
-
CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),
|
|
9425
|
-
CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),
|
|
9426
|
-
CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),
|
|
9427
|
-
CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),
|
|
9428
|
-
CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),
|
|
9429
|
-
OPTION: (actionORMethodDef) => this.OPTION(actionORMethodDef),
|
|
9430
|
-
OPTION1: (actionORMethodDef) => this.OPTION1(actionORMethodDef),
|
|
9431
|
-
OPTION2: (actionORMethodDef) => this.OPTION2(actionORMethodDef),
|
|
9432
|
-
OPTION3: (actionORMethodDef) => this.OPTION3(actionORMethodDef),
|
|
9433
|
-
OPTION4: (actionORMethodDef) => this.OPTION4(actionORMethodDef),
|
|
9434
|
-
OPTION5: (actionORMethodDef) => this.OPTION5(actionORMethodDef),
|
|
9435
|
-
OPTION6: (actionORMethodDef) => this.OPTION6(actionORMethodDef),
|
|
9436
|
-
OPTION7: (actionORMethodDef) => this.OPTION7(actionORMethodDef),
|
|
9437
|
-
OPTION8: (actionORMethodDef) => this.OPTION8(actionORMethodDef),
|
|
9438
|
-
OPTION9: (actionORMethodDef) => this.OPTION9(actionORMethodDef),
|
|
9439
|
-
OR: (altsOrOpts) => this.OR(altsOrOpts),
|
|
9440
|
-
OR1: (altsOrOpts) => this.OR1(altsOrOpts),
|
|
9441
|
-
OR2: (altsOrOpts) => this.OR2(altsOrOpts),
|
|
9442
|
-
OR3: (altsOrOpts) => this.OR3(altsOrOpts),
|
|
9443
|
-
OR4: (altsOrOpts) => this.OR4(altsOrOpts),
|
|
9444
|
-
OR5: (altsOrOpts) => this.OR5(altsOrOpts),
|
|
9445
|
-
OR6: (altsOrOpts) => this.OR6(altsOrOpts),
|
|
9446
|
-
OR7: (altsOrOpts) => this.OR7(altsOrOpts),
|
|
9447
|
-
OR8: (altsOrOpts) => this.OR8(altsOrOpts),
|
|
9448
|
-
OR9: (altsOrOpts) => this.OR9(altsOrOpts),
|
|
9449
|
-
MANY: (actionORMethodDef) => this.MANY(actionORMethodDef),
|
|
9450
|
-
MANY1: (actionORMethodDef) => this.MANY1(actionORMethodDef),
|
|
9451
|
-
MANY2: (actionORMethodDef) => this.MANY2(actionORMethodDef),
|
|
9452
|
-
MANY3: (actionORMethodDef) => this.MANY3(actionORMethodDef),
|
|
9453
|
-
MANY4: (actionORMethodDef) => this.MANY4(actionORMethodDef),
|
|
9454
|
-
MANY5: (actionORMethodDef) => this.MANY5(actionORMethodDef),
|
|
9455
|
-
MANY6: (actionORMethodDef) => this.MANY6(actionORMethodDef),
|
|
9456
|
-
MANY7: (actionORMethodDef) => this.MANY7(actionORMethodDef),
|
|
9457
|
-
MANY8: (actionORMethodDef) => this.MANY8(actionORMethodDef),
|
|
9458
|
-
MANY9: (actionORMethodDef) => this.MANY9(actionORMethodDef),
|
|
9459
|
-
MANY_SEP: (options) => this.MANY_SEP(options),
|
|
9460
|
-
MANY_SEP1: (options) => this.MANY_SEP1(options),
|
|
9461
|
-
MANY_SEP2: (options) => this.MANY_SEP2(options),
|
|
9462
|
-
MANY_SEP3: (options) => this.MANY_SEP3(options),
|
|
9463
|
-
MANY_SEP4: (options) => this.MANY_SEP4(options),
|
|
9464
|
-
MANY_SEP5: (options) => this.MANY_SEP5(options),
|
|
9465
|
-
MANY_SEP6: (options) => this.MANY_SEP6(options),
|
|
9466
|
-
MANY_SEP7: (options) => this.MANY_SEP7(options),
|
|
9467
|
-
MANY_SEP8: (options) => this.MANY_SEP8(options),
|
|
9468
|
-
MANY_SEP9: (options) => this.MANY_SEP9(options),
|
|
9469
|
-
AT_LEAST_ONE: (actionORMethodDef) => this.AT_LEAST_ONE(actionORMethodDef),
|
|
9470
|
-
AT_LEAST_ONE1: (actionORMethodDef) => this.AT_LEAST_ONE1(actionORMethodDef),
|
|
9471
|
-
AT_LEAST_ONE2: (actionORMethodDef) => this.AT_LEAST_ONE2(actionORMethodDef),
|
|
9472
|
-
AT_LEAST_ONE3: (actionORMethodDef) => this.AT_LEAST_ONE3(actionORMethodDef),
|
|
9473
|
-
AT_LEAST_ONE4: (actionORMethodDef) => this.AT_LEAST_ONE4(actionORMethodDef),
|
|
9474
|
-
AT_LEAST_ONE5: (actionORMethodDef) => this.AT_LEAST_ONE5(actionORMethodDef),
|
|
9475
|
-
AT_LEAST_ONE6: (actionORMethodDef) => this.AT_LEAST_ONE6(actionORMethodDef),
|
|
9476
|
-
AT_LEAST_ONE7: (actionORMethodDef) => this.AT_LEAST_ONE7(actionORMethodDef),
|
|
9477
|
-
AT_LEAST_ONE8: (actionORMethodDef) => this.AT_LEAST_ONE8(actionORMethodDef),
|
|
9478
|
-
AT_LEAST_ONE9: (actionORMethodDef) => this.AT_LEAST_ONE9(actionORMethodDef),
|
|
9479
|
-
AT_LEAST_ONE_SEP: (options) => this.AT_LEAST_ONE_SEP(options),
|
|
9480
|
-
AT_LEAST_ONE_SEP1: (options) => this.AT_LEAST_ONE_SEP1(options),
|
|
9481
|
-
AT_LEAST_ONE_SEP2: (options) => this.AT_LEAST_ONE_SEP2(options),
|
|
9482
|
-
AT_LEAST_ONE_SEP3: (options) => this.AT_LEAST_ONE_SEP3(options),
|
|
9483
|
-
AT_LEAST_ONE_SEP4: (options) => this.AT_LEAST_ONE_SEP4(options),
|
|
9484
|
-
AT_LEAST_ONE_SEP5: (options) => this.AT_LEAST_ONE_SEP5(options),
|
|
9485
|
-
AT_LEAST_ONE_SEP6: (options) => this.AT_LEAST_ONE_SEP6(options),
|
|
9486
|
-
AT_LEAST_ONE_SEP7: (options) => this.AT_LEAST_ONE_SEP7(options),
|
|
9487
|
-
AT_LEAST_ONE_SEP8: (options) => this.AT_LEAST_ONE_SEP8(options),
|
|
9488
|
-
AT_LEAST_ONE_SEP9: (options) => this.AT_LEAST_ONE_SEP9(options),
|
|
9489
|
-
ACTION: (func) => this.ACTION(func),
|
|
9490
|
-
BACKTRACK: (cstDef, ...args) => {
|
|
9491
|
-
try {
|
|
9492
|
-
return this.BACKTRACK(this[cstDef.name], { ARGS: args });
|
|
9493
|
-
} catch (error) {
|
|
9494
|
-
throw error;
|
|
9495
|
-
}
|
|
9496
|
-
},
|
|
9497
|
-
SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),
|
|
9498
|
-
SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),
|
|
9499
|
-
SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),
|
|
9500
|
-
SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),
|
|
9501
|
-
SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),
|
|
9502
|
-
SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),
|
|
9503
|
-
SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),
|
|
9504
|
-
SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),
|
|
9505
|
-
SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),
|
|
9506
|
-
SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args))
|
|
9507
|
-
};
|
|
9508
|
-
}
|
|
9509
|
-
}
|
|
9510
|
-
return new MyParser();
|
|
9717
|
+
return new DynamicParser(this.rules, tokenVocabulary, config);
|
|
9511
9718
|
}
|
|
9512
9719
|
};
|
|
9513
9720
|
|
|
9514
|
-
// lib/
|
|
9515
|
-
var CommonIRIs = /* @__PURE__ */ ((CommonIRIs2) => {
|
|
9516
|
-
CommonIRIs2["BOOLEAN"] = "http://www.w3.org/2001/XMLSchema#boolean";
|
|
9517
|
-
CommonIRIs2["INTEGER"] = "http://www.w3.org/2001/XMLSchema#integer";
|
|
9518
|
-
CommonIRIs2["DECIMAL"] = "http://www.w3.org/2001/XMLSchema#decimal";
|
|
9519
|
-
CommonIRIs2["DOUBLE"] = "http://www.w3.org/2001/XMLSchema#double";
|
|
9520
|
-
CommonIRIs2["FIRST"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";
|
|
9521
|
-
CommonIRIs2["REST"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";
|
|
9522
|
-
CommonIRIs2["NIL"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
|
|
9523
|
-
CommonIRIs2["TYPE"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
|
|
9524
|
-
CommonIRIs2["REIFIES"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies";
|
|
9525
|
-
return CommonIRIs2;
|
|
9526
|
-
})(CommonIRIs || {});
|
|
9721
|
+
// lib/utils.ts
|
|
9527
9722
|
function unCapitalize(str) {
|
|
9528
9723
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
9529
9724
|
}
|
|
9530
|
-
function resolveIRI(iri, base) {
|
|
9531
|
-
if (/^[a-z][\d+.a-z-]*:/iu.test(iri)) {
|
|
9532
|
-
return iri;
|
|
9533
|
-
}
|
|
9534
|
-
if (!base) {
|
|
9535
|
-
throw new Error(`Cannot resolve relative IRI ${iri} because no base IRI was set.`);
|
|
9536
|
-
}
|
|
9537
|
-
switch (iri[0]) {
|
|
9538
|
-
// An empty relative IRI indicates the base IRI
|
|
9539
|
-
case void 0:
|
|
9540
|
-
return base;
|
|
9541
|
-
// Resolve relative fragment IRIs against the base IRI
|
|
9542
|
-
case "#":
|
|
9543
|
-
return base + iri;
|
|
9544
|
-
// Resolve relative query string IRIs by replacing the query string
|
|
9545
|
-
case "?":
|
|
9546
|
-
return base.replace(/(?:\?.*)?$/u, iri);
|
|
9547
|
-
// Resolve root relative IRIs at the root of the base IRI
|
|
9548
|
-
case "/":
|
|
9549
|
-
const baseMatch = base.match(/^(?:[a-z]+:\/*)?[^\/]*/);
|
|
9550
|
-
if (!baseMatch) {
|
|
9551
|
-
throw new Error(`Could not determine relative IRI using base: ${base}`);
|
|
9552
|
-
}
|
|
9553
|
-
const baseRoot = baseMatch[0];
|
|
9554
|
-
return baseRoot + iri;
|
|
9555
|
-
// Resolve all other IRIs at the base IRI's path
|
|
9556
|
-
default:
|
|
9557
|
-
const basePath = base.replace(/[^\/:]*$/, "");
|
|
9558
|
-
return basePath + iri;
|
|
9559
|
-
}
|
|
9560
|
-
}
|
|
9561
|
-
|
|
9562
|
-
// lib/lexer-builder/LexerBuilder.ts
|
|
9563
|
-
var LexerBuilder = class _LexerBuilder {
|
|
9564
|
-
static create(starter) {
|
|
9565
|
-
return new _LexerBuilder(starter);
|
|
9566
|
-
}
|
|
9567
|
-
constructor(starter) {
|
|
9568
|
-
this.tokens = starter?.tokens ? [...starter.tokens] : [];
|
|
9569
|
-
}
|
|
9570
|
-
get(index) {
|
|
9571
|
-
return this.tokens[index];
|
|
9572
|
-
}
|
|
9573
|
-
merge(merge, overwrite = []) {
|
|
9574
|
-
const extraTokens = merge.tokens.filter((token) => {
|
|
9575
|
-
const overwriteToken = overwrite.find((t) => t.name === token.name);
|
|
9576
|
-
if (overwriteToken) {
|
|
9577
|
-
return false;
|
|
9578
|
-
}
|
|
9579
|
-
const match = this.tokens.find((t) => t.name === token.name);
|
|
9580
|
-
if (match) {
|
|
9581
|
-
if (match !== token) {
|
|
9582
|
-
throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);
|
|
9583
|
-
}
|
|
9584
|
-
return false;
|
|
9585
|
-
}
|
|
9586
|
-
return true;
|
|
9587
|
-
});
|
|
9588
|
-
this.tokens.push(...extraTokens);
|
|
9589
|
-
return this;
|
|
9590
|
-
}
|
|
9591
|
-
add(...token) {
|
|
9592
|
-
this.tokens.push(...token);
|
|
9593
|
-
return this;
|
|
9594
|
-
}
|
|
9595
|
-
addBefore(before, ...token) {
|
|
9596
|
-
const index = this.tokens.indexOf(before);
|
|
9597
|
-
if (index === -1) {
|
|
9598
|
-
throw new Error("Token not found");
|
|
9599
|
-
}
|
|
9600
|
-
this.tokens.splice(index, 0, ...token);
|
|
9601
|
-
return this;
|
|
9602
|
-
}
|
|
9603
|
-
moveBeforeOrAfter(beforeOrAfter, before, ...tokens) {
|
|
9604
|
-
const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === "before" ? 0 : 1);
|
|
9605
|
-
if (beforeIndex === -1) {
|
|
9606
|
-
throw new Error("BeforeToken not found");
|
|
9607
|
-
}
|
|
9608
|
-
for (const token of tokens) {
|
|
9609
|
-
const tokenIndex = this.tokens.indexOf(token);
|
|
9610
|
-
if (tokenIndex === -1) {
|
|
9611
|
-
throw new Error("Token not found");
|
|
9612
|
-
}
|
|
9613
|
-
this.tokens.splice(tokenIndex, 1);
|
|
9614
|
-
this.tokens.splice(beforeIndex, 0, token);
|
|
9615
|
-
}
|
|
9616
|
-
return this;
|
|
9617
|
-
}
|
|
9618
|
-
moveBefore(before, ...tokens) {
|
|
9619
|
-
return this.moveBeforeOrAfter("before", before, ...tokens);
|
|
9620
|
-
}
|
|
9621
|
-
moveAfter(after, ...tokens) {
|
|
9622
|
-
return this.moveBeforeOrAfter("after", after, ...tokens);
|
|
9623
|
-
}
|
|
9624
|
-
addAfter(after, ...token) {
|
|
9625
|
-
const index = this.tokens.indexOf(after);
|
|
9626
|
-
if (index === -1) {
|
|
9627
|
-
throw new Error("Token not found");
|
|
9628
|
-
}
|
|
9629
|
-
this.tokens.splice(index + 1, 0, ...token);
|
|
9630
|
-
return this;
|
|
9631
|
-
}
|
|
9632
|
-
delete(...token) {
|
|
9633
|
-
for (const t of token) {
|
|
9634
|
-
const index = this.tokens.indexOf(t);
|
|
9635
|
-
if (index === -1) {
|
|
9636
|
-
throw new Error("Token not found");
|
|
9637
|
-
}
|
|
9638
|
-
this.tokens.splice(index, 1);
|
|
9639
|
-
}
|
|
9640
|
-
return this;
|
|
9641
|
-
}
|
|
9642
|
-
build() {
|
|
9643
|
-
return this.tokens;
|
|
9644
|
-
}
|
|
9645
|
-
};
|
|
9646
|
-
|
|
9647
|
-
// lib/lexer-helper/utils.ts
|
|
9648
9725
|
function createToken2(config) {
|
|
9649
9726
|
return createToken(config);
|
|
9650
9727
|
}
|
|
9651
|
-
|
|
9652
|
-
// lib/Wildcard.ts
|
|
9653
|
-
var Wildcard = class {
|
|
9654
|
-
constructor() {
|
|
9655
|
-
this.value = "*";
|
|
9656
|
-
this.termType = "Wildcard";
|
|
9657
|
-
return WILDCARD ?? this;
|
|
9658
|
-
}
|
|
9659
|
-
equals(other) {
|
|
9660
|
-
return Boolean(other && this.termType === other.termType);
|
|
9661
|
-
}
|
|
9662
|
-
toJSON() {
|
|
9663
|
-
const { value, ...rest } = this;
|
|
9664
|
-
return rest;
|
|
9665
|
-
}
|
|
9666
|
-
};
|
|
9667
|
-
var WILDCARD;
|
|
9668
|
-
WILDCARD = new Wildcard();
|
|
9669
9728
|
/*! Bundled license information:
|
|
9670
9729
|
|
|
9671
9730
|
lodash-es/lodash.js:
|