@traqula/core 0.0.1-alpha.145 → 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.
Files changed (51) hide show
  1. package/README.md +44 -22
  2. package/lib/generator-builder/builderTypes.d.ts +20 -0
  3. package/lib/generator-builder/builderTypes.js.map +1 -0
  4. package/lib/generator-builder/dynamicGenerator.d.ts +7 -0
  5. package/lib/generator-builder/dynamicGenerator.js +28 -0
  6. package/lib/generator-builder/dynamicGenerator.js.map +1 -0
  7. package/lib/generator-builder/generatorBuilder.d.ts +58 -0
  8. package/lib/generator-builder/generatorBuilder.js +101 -0
  9. package/lib/generator-builder/generatorBuilder.js.map +1 -0
  10. package/lib/generator-builder/generatorTypes.d.ts +27 -0
  11. package/lib/generator-builder/generatorTypes.js +2 -0
  12. package/lib/generator-builder/generatorTypes.js.map +1 -0
  13. package/lib/index.cjs +388 -643
  14. package/lib/index.d.ts +7 -6
  15. package/lib/index.js +11 -6
  16. package/lib/index.js.map +1 -1
  17. package/lib/lexer-builder/LexerBuilder.d.ts +7 -9
  18. package/lib/lexer-builder/LexerBuilder.js +12 -4
  19. package/lib/lexer-builder/LexerBuilder.js.map +1 -1
  20. package/lib/parser-builder/builderTypes.d.ts +24 -0
  21. package/lib/parser-builder/builderTypes.js +2 -0
  22. package/lib/parser-builder/builderTypes.js.map +1 -0
  23. package/lib/parser-builder/dynamicParser.d.ts +9 -0
  24. package/lib/parser-builder/dynamicParser.js +113 -0
  25. package/lib/parser-builder/dynamicParser.js.map +1 -0
  26. package/lib/parser-builder/parserBuilder.d.ts +73 -0
  27. package/lib/parser-builder/parserBuilder.js +161 -0
  28. package/lib/parser-builder/parserBuilder.js.map +1 -0
  29. package/lib/{grammar-builder → parser-builder}/ruleDefTypes.d.ts +45 -29
  30. package/lib/parser-builder/ruleDefTypes.js.map +1 -0
  31. package/lib/utils.d.ts +17 -0
  32. package/lib/utils.js +8 -0
  33. package/lib/utils.js.map +1 -0
  34. package/package.json +8 -10
  35. package/lib/Wildcard.d.ts +0 -9
  36. package/lib/Wildcard.js +0 -19
  37. package/lib/Wildcard.js.map +0 -1
  38. package/lib/grammar-builder/builderTypes.d.ts +0 -19
  39. package/lib/grammar-builder/builderTypes.js.map +0 -1
  40. package/lib/grammar-builder/parserBuilder.d.ts +0 -50
  41. package/lib/grammar-builder/parserBuilder.js +0 -276
  42. package/lib/grammar-builder/parserBuilder.js.map +0 -1
  43. package/lib/grammar-builder/ruleDefTypes.js.map +0 -1
  44. package/lib/grammar-helpers/utils.d.ts +0 -16
  45. package/lib/grammar-helpers/utils.js +0 -53
  46. package/lib/grammar-helpers/utils.js.map +0 -1
  47. package/lib/lexer-helper/utils.d.ts +0 -6
  48. package/lib/lexer-helper/utils.js +0 -5
  49. package/lib/lexer-helper/utils.js.map +0 -1
  50. /package/lib/{grammar-builder → generator-builder}/builderTypes.js +0 -0
  51. /package/lib/{grammar-builder → parser-builder}/ruleDefTypes.js +0 -0
package/lib/index.cjs CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
6
  var __export = (target, all) => {
12
7
  for (var name in all)
13
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,326 +15,139 @@ var __copyProps = (to, from, except, desc) => {
20
15
  }
21
16
  return to;
22
17
  };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
19
 
33
- // ../../node_modules/rdf-data-factory/lib/BlankNode.js
34
- var require_BlankNode = __commonJS({
35
- "../../node_modules/rdf-data-factory/lib/BlankNode.js"(exports2) {
36
- "use strict";
37
- Object.defineProperty(exports2, "__esModule", { value: true });
38
- exports2.BlankNode = void 0;
39
- var BlankNode = class {
40
- constructor(value) {
41
- this.termType = "BlankNode";
42
- this.value = value;
43
- }
44
- equals(other) {
45
- return !!other && other.termType === "BlankNode" && other.value === this.value;
46
- }
47
- };
48
- exports2.BlankNode = BlankNode;
49
- }
20
+ // lib/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ GeneratorBuilder: () => GeneratorBuilder,
24
+ LexerBuilder: () => LexerBuilder,
25
+ ParserBuilder: () => ParserBuilder,
26
+ createToken: () => createToken2,
27
+ unCapitalize: () => unCapitalize
50
28
  });
29
+ module.exports = __toCommonJS(index_exports);
51
30
 
52
- // ../../node_modules/rdf-data-factory/lib/DefaultGraph.js
53
- var require_DefaultGraph = __commonJS({
54
- "../../node_modules/rdf-data-factory/lib/DefaultGraph.js"(exports2) {
55
- "use strict";
56
- Object.defineProperty(exports2, "__esModule", { value: true });
57
- exports2.DefaultGraph = void 0;
58
- var DefaultGraph = class {
59
- constructor() {
60
- this.termType = "DefaultGraph";
61
- this.value = "";
62
- }
63
- equals(other) {
64
- return !!other && other.termType === "DefaultGraph";
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);
65
42
  }
66
43
  };
67
- exports2.DefaultGraph = DefaultGraph;
68
- DefaultGraph.INSTANCE = new DefaultGraph();
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
+ }
69
50
  }
70
- });
71
-
72
- // ../../node_modules/rdf-data-factory/lib/NamedNode.js
73
- var require_NamedNode = __commonJS({
74
- "../../node_modules/rdf-data-factory/lib/NamedNode.js"(exports2) {
75
- "use strict";
76
- Object.defineProperty(exports2, "__esModule", { value: true });
77
- exports2.NamedNode = void 0;
78
- var NamedNode = class {
79
- constructor(value) {
80
- this.termType = "NamedNode";
81
- this.value = value;
82
- }
83
- equals(other) {
84
- return !!other && other.termType === "NamedNode" && other.value === this.value;
85
- }
86
- };
87
- exports2.NamedNode = NamedNode;
51
+ setContext(context) {
52
+ this.__context = context;
88
53
  }
89
- });
90
-
91
- // ../../node_modules/rdf-data-factory/lib/Literal.js
92
- var require_Literal = __commonJS({
93
- "../../node_modules/rdf-data-factory/lib/Literal.js"(exports2) {
94
- "use strict";
95
- Object.defineProperty(exports2, "__esModule", { value: true });
96
- exports2.Literal = void 0;
97
- var NamedNode_1 = require_NamedNode();
98
- var Literal = class _Literal {
99
- constructor(value, languageOrDatatype) {
100
- this.termType = "Literal";
101
- this.value = value;
102
- if (typeof languageOrDatatype === "string") {
103
- this.language = languageOrDatatype;
104
- this.datatype = _Literal.RDF_LANGUAGE_STRING;
105
- this.direction = "";
106
- } else if (languageOrDatatype) {
107
- if ("termType" in languageOrDatatype) {
108
- this.language = "";
109
- this.datatype = languageOrDatatype;
110
- this.direction = "";
111
- } else {
112
- this.language = languageOrDatatype.language;
113
- this.datatype = languageOrDatatype.direction ? _Literal.RDF_DIRECTIONAL_LANGUAGE_STRING : _Literal.RDF_LANGUAGE_STRING;
114
- this.direction = languageOrDatatype.direction || "";
115
- }
116
- } else {
117
- this.language = "";
118
- this.datatype = _Literal.XSD_STRING;
119
- this.direction = "";
120
- }
121
- }
122
- equals(other) {
123
- return !!other && other.termType === "Literal" && other.value === this.value && other.language === this.language && (other.direction === this.direction || !other.direction && this.direction === "") && this.datatype.equals(other.datatype);
124
- }
125
- };
126
- exports2.Literal = Literal;
127
- Literal.RDF_LANGUAGE_STRING = new NamedNode_1.NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
128
- Literal.RDF_DIRECTIONAL_LANGUAGE_STRING = new NamedNode_1.NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString");
129
- Literal.XSD_STRING = new NamedNode_1.NamedNode("http://www.w3.org/2001/XMLSchema#string");
54
+ getSafeContext() {
55
+ return this.__context;
130
56
  }
131
- });
57
+ };
132
58
 
133
- // ../../node_modules/rdf-data-factory/lib/Quad.js
134
- var require_Quad = __commonJS({
135
- "../../node_modules/rdf-data-factory/lib/Quad.js"(exports2) {
136
- "use strict";
137
- Object.defineProperty(exports2, "__esModule", { value: true });
138
- exports2.Quad = void 0;
139
- var Quad = class {
140
- constructor(subject, predicate, object, graph) {
141
- this.termType = "Quad";
142
- this.value = "";
143
- this.subject = subject;
144
- this.predicate = predicate;
145
- this.object = object;
146
- this.graph = graph;
147
- }
148
- equals(other) {
149
- return !!other && (other.termType === "Quad" || !other.termType) && this.subject.equals(other.subject) && this.predicate.equals(other.predicate) && this.object.equals(other.object) && this.graph.equals(other.graph);
150
- }
151
- };
152
- exports2.Quad = Quad;
59
+ // lib/generator-builder/generatorBuilder.ts
60
+ function listToRuleDefMap(rules) {
61
+ const newRules = {};
62
+ for (const rule of rules) {
63
+ newRules[rule.name] = rule;
153
64
  }
154
- });
155
-
156
- // ../../node_modules/rdf-data-factory/lib/Variable.js
157
- var require_Variable = __commonJS({
158
- "../../node_modules/rdf-data-factory/lib/Variable.js"(exports2) {
159
- "use strict";
160
- Object.defineProperty(exports2, "__esModule", { value: true });
161
- exports2.Variable = void 0;
162
- var Variable = class {
163
- constructor(value) {
164
- this.termType = "Variable";
165
- this.value = value;
166
- }
167
- equals(other) {
168
- return !!other && other.termType === "Variable" && other.value === this.value;
169
- }
170
- };
171
- exports2.Variable = Variable;
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));
172
73
  }
173
- });
174
-
175
- // ../../node_modules/rdf-data-factory/lib/DataFactory.js
176
- var require_DataFactory = __commonJS({
177
- "../../node_modules/rdf-data-factory/lib/DataFactory.js"(exports2) {
178
- "use strict";
179
- Object.defineProperty(exports2, "__esModule", { value: true });
180
- exports2.DataFactory = void 0;
181
- var BlankNode_1 = require_BlankNode();
182
- var DefaultGraph_1 = require_DefaultGraph();
183
- var Literal_1 = require_Literal();
184
- var NamedNode_1 = require_NamedNode();
185
- var Quad_1 = require_Quad();
186
- var Variable_1 = require_Variable();
187
- var dataFactoryCounter = 0;
188
- var DataFactory2 = class {
189
- constructor(options) {
190
- this.blankNodeCounter = 0;
191
- options = options || {};
192
- this.blankNodePrefix = options.blankNodePrefix || `df_${dataFactoryCounter++}_`;
193
- }
194
- /**
195
- * @param value The IRI for the named node.
196
- * @return A new instance of NamedNode.
197
- * @see NamedNode
198
- */
199
- namedNode(value) {
200
- return new NamedNode_1.NamedNode(value);
201
- }
202
- /**
203
- * @param value The optional blank node identifier.
204
- * @return A new instance of BlankNode.
205
- * If the `value` parameter is undefined a new identifier
206
- * for the blank node is generated for each call.
207
- * @see BlankNode
208
- */
209
- blankNode(value) {
210
- return new BlankNode_1.BlankNode(value || `${this.blankNodePrefix}${this.blankNodeCounter++}`);
211
- }
212
- /**
213
- * @param value The literal value.
214
- * @param languageOrDatatype The optional language, datatype, or directional language.
215
- * If `languageOrDatatype` is a NamedNode,
216
- * then it is used for the value of `NamedNode.datatype`.
217
- * If `languageOrDatatype` is a NamedNode, it is used for the value
218
- * of `NamedNode.language`.
219
- * Otherwise, it is used as a directional language,
220
- * from which the language is set to `languageOrDatatype.language`
221
- * and the direction to `languageOrDatatype.direction`.
222
- * @return A new instance of Literal.
223
- * @see Literal
224
- */
225
- literal(value, languageOrDatatype) {
226
- return new Literal_1.Literal(value, languageOrDatatype);
227
- }
228
- /**
229
- * This method is optional.
230
- * @param value The variable name
231
- * @return A new instance of Variable.
232
- * @see Variable
233
- */
234
- variable(value) {
235
- return new Variable_1.Variable(value);
236
- }
237
- /**
238
- * @return An instance of DefaultGraph.
239
- */
240
- defaultGraph() {
241
- return DefaultGraph_1.DefaultGraph.INSTANCE;
242
- }
243
- /**
244
- * @param subject The quad subject term.
245
- * @param predicate The quad predicate term.
246
- * @param object The quad object term.
247
- * @param graph The quad graph term.
248
- * @return A new instance of Quad.
249
- * @see Quad
250
- */
251
- quad(subject, predicate, object, graph) {
252
- return new Quad_1.Quad(subject, predicate, object, graph || this.defaultGraph());
253
- }
254
- /**
255
- * Create a deep copy of the given term using this data factory.
256
- * @param original An RDF term.
257
- * @return A deep copy of the given term.
258
- */
259
- fromTerm(original) {
260
- switch (original.termType) {
261
- case "NamedNode":
262
- return this.namedNode(original.value);
263
- case "BlankNode":
264
- return this.blankNode(original.value);
265
- case "Literal":
266
- if (original.language) {
267
- return this.literal(original.value, original.language);
268
- }
269
- if (!original.datatype.equals(Literal_1.Literal.XSD_STRING)) {
270
- return this.literal(original.value, this.fromTerm(original.datatype));
271
- }
272
- return this.literal(original.value);
273
- case "Variable":
274
- return this.variable(original.value);
275
- case "DefaultGraph":
276
- return this.defaultGraph();
277
- case "Quad":
278
- return this.quad(this.fromTerm(original.subject), this.fromTerm(original.predicate), this.fromTerm(original.object), this.fromTerm(original.graph));
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
+ }
279
141
  }
280
142
  }
281
- /**
282
- * Create a deep copy of the given quad using this data factory.
283
- * @param original An RDF quad.
284
- * @return A deep copy of the given quad.
285
- */
286
- fromQuad(original) {
287
- return this.fromTerm(original);
288
- }
289
- /**
290
- * Reset the internal blank node counter.
291
- */
292
- resetBlankNodeCounter() {
293
- this.blankNodeCounter = 0;
294
- }
295
- };
296
- exports2.DataFactory = DataFactory2;
143
+ }
144
+ this.rules = otherRules;
145
+ return this;
297
146
  }
298
- });
299
-
300
- // ../../node_modules/rdf-data-factory/index.js
301
- var require_rdf_data_factory = __commonJS({
302
- "../../node_modules/rdf-data-factory/index.js"(exports2) {
303
- "use strict";
304
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
305
- if (k2 === void 0) k2 = k;
306
- var desc = Object.getOwnPropertyDescriptor(m, k);
307
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
308
- desc = { enumerable: true, get: function() {
309
- return m[k];
310
- } };
311
- }
312
- Object.defineProperty(o, k2, desc);
313
- } : function(o, m, k, k2) {
314
- if (k2 === void 0) k2 = k;
315
- o[k2] = m[k];
316
- });
317
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
318
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
319
- };
320
- Object.defineProperty(exports2, "__esModule", { value: true });
321
- __exportStar(require_BlankNode(), exports2);
322
- __exportStar(require_DataFactory(), exports2);
323
- __exportStar(require_DefaultGraph(), exports2);
324
- __exportStar(require_Literal(), exports2);
325
- __exportStar(require_NamedNode(), exports2);
326
- __exportStar(require_Quad(), exports2);
327
- __exportStar(require_Variable(), exports2);
147
+ build() {
148
+ return new DynamicGenerator(this.rules);
328
149
  }
329
- });
330
-
331
- // lib/index.ts
332
- var index_exports = {};
333
- __export(index_exports, {
334
- Builder: () => Builder,
335
- CommonIRIs: () => CommonIRIs,
336
- LexerBuilder: () => LexerBuilder,
337
- Wildcard: () => Wildcard,
338
- createToken: () => createToken2,
339
- resolveIRI: () => resolveIRI,
340
- unCapitalize: () => unCapitalize
341
- });
342
- module.exports = __toCommonJS(index_exports);
150
+ };
343
151
 
344
152
  // ../../node_modules/lodash-es/_freeGlobal.js
345
153
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
@@ -1706,8 +1514,8 @@ var Promise2 = getNative_default(root_default, "Promise");
1706
1514
  var Promise_default = Promise2;
1707
1515
 
1708
1516
  // ../../node_modules/lodash-es/_Set.js
1709
- var Set2 = getNative_default(root_default, "Set");
1710
- var Set_default = Set2;
1517
+ var Set = getNative_default(root_default, "Set");
1518
+ var Set_default = Set;
1711
1519
 
1712
1520
  // ../../node_modules/lodash-es/_getTag.js
1713
1521
  var mapTag2 = "[object Map]";
@@ -9559,29 +9367,235 @@ var EmbeddedActionsParser = class extends Parser {
9559
9367
  }
9560
9368
  };
9561
9369
 
9562
- // lib/grammar-builder/parserBuilder.ts
9563
- var import_rdf_data_factory = __toESM(require_rdf_data_factory(), 1);
9564
- function listToRuleDefMap(rules) {
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) {
9565
9576
  const newRules = {};
9566
9577
  for (const rule of rules) {
9567
9578
  newRules[rule.name] = rule;
9568
9579
  }
9569
9580
  return newRules;
9570
9581
  }
9571
- var Builder = class _Builder {
9582
+ var ParserBuilder = class _ParserBuilder {
9572
9583
  /**
9573
- * Create a builder with from some initial grammar rules or an existing builder.
9584
+ * Create a builder from some initial grammar rules or an existing builder.
9574
9585
  * If a builder is provided, a new copy will be created.
9575
9586
  */
9576
9587
  static createBuilder(start) {
9577
- if (start instanceof _Builder) {
9578
- return new _Builder({ ...start.rules });
9588
+ if (start instanceof _ParserBuilder) {
9589
+ return new _ParserBuilder({ ...start.rules });
9579
9590
  }
9580
- return new _Builder(listToRuleDefMap(start));
9591
+ return new _ParserBuilder(listToRuleDefMap2(start));
9581
9592
  }
9582
9593
  constructor(startRules) {
9583
9594
  this.rules = startRules;
9584
9595
  }
9596
+ typePatch() {
9597
+ return this;
9598
+ }
9585
9599
  /**
9586
9600
  * Change the implementation of an existing grammar rule.
9587
9601
  */
@@ -9609,13 +9623,25 @@ var Builder = class _Builder {
9609
9623
  return this.addRuleRedundant(rule);
9610
9624
  }
9611
9625
  addMany(...rules) {
9612
- this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
9626
+ this.rules = { ...this.rules, ...listToRuleDefMap2(rules) };
9613
9627
  return this;
9614
9628
  }
9629
+ /**
9630
+ * Delete a grammar rule by its name.
9631
+ */
9615
9632
  deleteRule(ruleName) {
9616
9633
  delete this.rules[ruleName];
9617
9634
  return this;
9618
9635
  }
9636
+ /**
9637
+ * Merge this grammar builder with another.
9638
+ * It is best to merge the bigger grammar with the smaller one.
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.
9641
+ * If they map to a different object, an error will be thrown.
9642
+ * To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
9643
+ * this rule implementation will be used.
9644
+ */
9619
9645
  merge(builder, overridingRules) {
9620
9646
  const otherRules = { ...builder.rules };
9621
9647
  const myRules = this.rules;
@@ -9637,349 +9663,68 @@ var Builder = class _Builder {
9637
9663
  this.rules = otherRules;
9638
9664
  return this;
9639
9665
  }
9640
- consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }, context = {}) {
9641
- const lexer = new Lexer(tokenVocabulary, {
9642
- positionTracking: "onlyStart",
9643
- recoveryEnabled: false,
9644
- // SafeMode: true,
9645
- // SkipValidations: true,
9646
- ensureOptimizations: true,
9647
- ...lexerConfig
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
9648
9695
  });
9649
- const parser = this.consume({ tokenVocabulary, config: parserConfig }, context);
9650
9696
  const selfSufficientParser = {};
9651
9697
  for (const rule of Object.values(this.rules)) {
9652
- selfSufficientParser[rule.name] = (input, arg) => {
9653
- input = input.replaceAll(
9654
- /\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
9655
- (_, unicode4, unicode8) => {
9656
- if (unicode4) {
9657
- const charCode2 = Number.parseInt(unicode4, 16);
9658
- return String.fromCodePoint(charCode2);
9659
- }
9660
- const charCode = Number.parseInt(unicode8, 16);
9661
- if (charCode < 65535) {
9662
- return String.fromCodePoint(charCode);
9663
- }
9664
- const substractedCharCode = charCode - 65536;
9665
- return String.fromCodePoint(55296 + (substractedCharCode >> 10), 56320 + (substractedCharCode & 1023));
9666
- }
9667
- );
9668
- if (/[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/u.test(input)) {
9669
- throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
9670
- }
9671
- const lexResult = lexer.tokenize(input);
9672
- parser.reset();
9698
+ selfSufficientParser[rule.name] = (input, context, arg) => {
9699
+ const processedInput = queryPreProcessor(input);
9700
+ const lexResult = lexer.tokenize(processedInput);
9673
9701
  parser.input = lexResult.tokens;
9674
- const result = parser[rule.name](arg);
9702
+ parser.setContext(context);
9703
+ const result = parser[rule.name](context, arg);
9675
9704
  if (parser.errors.length > 0) {
9676
- throw new Error(`Parse error on line ${parser.errors.map((x) => x.token.startLine).join(", ")}
9677
- ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
9705
+ if (errorHandler) {
9706
+ errorHandler(parser.errors);
9707
+ } else {
9708
+ this.defaultErrorHandler(processedInput, parser.errors);
9709
+ }
9678
9710
  }
9679
9711
  return result;
9680
9712
  };
9681
9713
  }
9682
9714
  return selfSufficientParser;
9683
9715
  }
9684
- consume({ tokenVocabulary, config = {} }, context = {}) {
9685
- const rules = this.rules;
9686
- class MyParser extends EmbeddedActionsParser {
9687
- constructor() {
9688
- super(tokenVocabulary, {
9689
- // RecoveryEnabled: true,
9690
- maxLookahead: 2,
9691
- // SkipValidations: true,
9692
- ...config
9693
- });
9694
- const selfRef = this.getSelfRef();
9695
- this.initialParseContext = {
9696
- dataFactory: new import_rdf_data_factory.DataFactory({ blankNodePrefix: "g_" }),
9697
- baseIRI: void 0,
9698
- parseMode: /* @__PURE__ */ new Set(),
9699
- skipValidation: false,
9700
- ...context,
9701
- prefixes: context.prefixes ? { ...context.prefixes } : {}
9702
- };
9703
- this.runningContext = {
9704
- ...this.initialParseContext,
9705
- prefixes: { ...this.initialParseContext.prefixes },
9706
- parseMode: new Set(this.initialParseContext.parseMode)
9707
- };
9708
- const implArgs = {
9709
- ...selfRef,
9710
- cache: /* @__PURE__ */ new WeakMap(),
9711
- context: this.runningContext
9712
- };
9713
- for (const rule of Object.values(rules)) {
9714
- this[rule.name] = this.RULE(rule.name, rule.impl(implArgs));
9715
- }
9716
- this.performSelfAnalysis();
9717
- }
9718
- reset() {
9719
- super.reset();
9720
- Object.assign(this.runningContext, {
9721
- ...this.initialParseContext
9722
- });
9723
- this.runningContext.prefixes = { ...this.initialParseContext.prefixes };
9724
- this.runningContext.parseMode = new Set(this.initialParseContext.parseMode);
9725
- }
9726
- getSelfRef() {
9727
- const subRuleImpl = (subrule) => {
9728
- return (cstDef, ...args) => {
9729
- return subrule(this[cstDef.name], { ARGS: args });
9730
- };
9731
- };
9732
- return {
9733
- CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),
9734
- CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),
9735
- CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),
9736
- CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),
9737
- CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),
9738
- CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),
9739
- CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),
9740
- CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),
9741
- CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),
9742
- CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),
9743
- OPTION: (actionORMethodDef) => this.OPTION(actionORMethodDef),
9744
- OPTION1: (actionORMethodDef) => this.OPTION1(actionORMethodDef),
9745
- OPTION2: (actionORMethodDef) => this.OPTION2(actionORMethodDef),
9746
- OPTION3: (actionORMethodDef) => this.OPTION3(actionORMethodDef),
9747
- OPTION4: (actionORMethodDef) => this.OPTION4(actionORMethodDef),
9748
- OPTION5: (actionORMethodDef) => this.OPTION5(actionORMethodDef),
9749
- OPTION6: (actionORMethodDef) => this.OPTION6(actionORMethodDef),
9750
- OPTION7: (actionORMethodDef) => this.OPTION7(actionORMethodDef),
9751
- OPTION8: (actionORMethodDef) => this.OPTION8(actionORMethodDef),
9752
- OPTION9: (actionORMethodDef) => this.OPTION9(actionORMethodDef),
9753
- OR: (altsOrOpts) => this.OR(altsOrOpts),
9754
- OR1: (altsOrOpts) => this.OR1(altsOrOpts),
9755
- OR2: (altsOrOpts) => this.OR2(altsOrOpts),
9756
- OR3: (altsOrOpts) => this.OR3(altsOrOpts),
9757
- OR4: (altsOrOpts) => this.OR4(altsOrOpts),
9758
- OR5: (altsOrOpts) => this.OR5(altsOrOpts),
9759
- OR6: (altsOrOpts) => this.OR6(altsOrOpts),
9760
- OR7: (altsOrOpts) => this.OR7(altsOrOpts),
9761
- OR8: (altsOrOpts) => this.OR8(altsOrOpts),
9762
- OR9: (altsOrOpts) => this.OR9(altsOrOpts),
9763
- MANY: (actionORMethodDef) => this.MANY(actionORMethodDef),
9764
- MANY1: (actionORMethodDef) => this.MANY1(actionORMethodDef),
9765
- MANY2: (actionORMethodDef) => this.MANY2(actionORMethodDef),
9766
- MANY3: (actionORMethodDef) => this.MANY3(actionORMethodDef),
9767
- MANY4: (actionORMethodDef) => this.MANY4(actionORMethodDef),
9768
- MANY5: (actionORMethodDef) => this.MANY5(actionORMethodDef),
9769
- MANY6: (actionORMethodDef) => this.MANY6(actionORMethodDef),
9770
- MANY7: (actionORMethodDef) => this.MANY7(actionORMethodDef),
9771
- MANY8: (actionORMethodDef) => this.MANY8(actionORMethodDef),
9772
- MANY9: (actionORMethodDef) => this.MANY9(actionORMethodDef),
9773
- MANY_SEP: (options) => this.MANY_SEP(options),
9774
- MANY_SEP1: (options) => this.MANY_SEP1(options),
9775
- MANY_SEP2: (options) => this.MANY_SEP2(options),
9776
- MANY_SEP3: (options) => this.MANY_SEP3(options),
9777
- MANY_SEP4: (options) => this.MANY_SEP4(options),
9778
- MANY_SEP5: (options) => this.MANY_SEP5(options),
9779
- MANY_SEP6: (options) => this.MANY_SEP6(options),
9780
- MANY_SEP7: (options) => this.MANY_SEP7(options),
9781
- MANY_SEP8: (options) => this.MANY_SEP8(options),
9782
- MANY_SEP9: (options) => this.MANY_SEP9(options),
9783
- AT_LEAST_ONE: (actionORMethodDef) => this.AT_LEAST_ONE(actionORMethodDef),
9784
- AT_LEAST_ONE1: (actionORMethodDef) => this.AT_LEAST_ONE1(actionORMethodDef),
9785
- AT_LEAST_ONE2: (actionORMethodDef) => this.AT_LEAST_ONE2(actionORMethodDef),
9786
- AT_LEAST_ONE3: (actionORMethodDef) => this.AT_LEAST_ONE3(actionORMethodDef),
9787
- AT_LEAST_ONE4: (actionORMethodDef) => this.AT_LEAST_ONE4(actionORMethodDef),
9788
- AT_LEAST_ONE5: (actionORMethodDef) => this.AT_LEAST_ONE5(actionORMethodDef),
9789
- AT_LEAST_ONE6: (actionORMethodDef) => this.AT_LEAST_ONE6(actionORMethodDef),
9790
- AT_LEAST_ONE7: (actionORMethodDef) => this.AT_LEAST_ONE7(actionORMethodDef),
9791
- AT_LEAST_ONE8: (actionORMethodDef) => this.AT_LEAST_ONE8(actionORMethodDef),
9792
- AT_LEAST_ONE9: (actionORMethodDef) => this.AT_LEAST_ONE9(actionORMethodDef),
9793
- AT_LEAST_ONE_SEP: (options) => this.AT_LEAST_ONE_SEP(options),
9794
- AT_LEAST_ONE_SEP1: (options) => this.AT_LEAST_ONE_SEP1(options),
9795
- AT_LEAST_ONE_SEP2: (options) => this.AT_LEAST_ONE_SEP2(options),
9796
- AT_LEAST_ONE_SEP3: (options) => this.AT_LEAST_ONE_SEP3(options),
9797
- AT_LEAST_ONE_SEP4: (options) => this.AT_LEAST_ONE_SEP4(options),
9798
- AT_LEAST_ONE_SEP5: (options) => this.AT_LEAST_ONE_SEP5(options),
9799
- AT_LEAST_ONE_SEP6: (options) => this.AT_LEAST_ONE_SEP6(options),
9800
- AT_LEAST_ONE_SEP7: (options) => this.AT_LEAST_ONE_SEP7(options),
9801
- AT_LEAST_ONE_SEP8: (options) => this.AT_LEAST_ONE_SEP8(options),
9802
- AT_LEAST_ONE_SEP9: (options) => this.AT_LEAST_ONE_SEP9(options),
9803
- ACTION: (func) => this.ACTION(func),
9804
- BACKTRACK: (cstDef, ...args) => {
9805
- try {
9806
- return this.BACKTRACK(this[cstDef.name], { ARGS: args });
9807
- } catch (error) {
9808
- throw error;
9809
- }
9810
- },
9811
- SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),
9812
- SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),
9813
- SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),
9814
- SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),
9815
- SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),
9816
- SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),
9817
- SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),
9818
- SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),
9819
- SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),
9820
- SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args))
9821
- };
9822
- }
9823
- }
9824
- return new MyParser();
9716
+ consume({ tokenVocabulary, config = {} }) {
9717
+ return new DynamicParser(this.rules, tokenVocabulary, config);
9825
9718
  }
9826
9719
  };
9827
9720
 
9828
- // lib/grammar-helpers/utils.ts
9829
- var CommonIRIs = /* @__PURE__ */ ((CommonIRIs2) => {
9830
- CommonIRIs2["BOOLEAN"] = "http://www.w3.org/2001/XMLSchema#boolean";
9831
- CommonIRIs2["INTEGER"] = "http://www.w3.org/2001/XMLSchema#integer";
9832
- CommonIRIs2["DECIMAL"] = "http://www.w3.org/2001/XMLSchema#decimal";
9833
- CommonIRIs2["DOUBLE"] = "http://www.w3.org/2001/XMLSchema#double";
9834
- CommonIRIs2["FIRST"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";
9835
- CommonIRIs2["REST"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";
9836
- CommonIRIs2["NIL"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
9837
- CommonIRIs2["TYPE"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
9838
- CommonIRIs2["REIFIES"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies";
9839
- return CommonIRIs2;
9840
- })(CommonIRIs || {});
9721
+ // lib/utils.ts
9841
9722
  function unCapitalize(str) {
9842
9723
  return str.charAt(0).toLowerCase() + str.slice(1);
9843
9724
  }
9844
- function resolveIRI(iri, base) {
9845
- if (/^[a-z][\d+.a-z-]*:/iu.test(iri)) {
9846
- return iri;
9847
- }
9848
- if (!base) {
9849
- throw new Error(`Cannot resolve relative IRI ${iri} because no base IRI was set.`);
9850
- }
9851
- switch (iri[0]) {
9852
- // An empty relative IRI indicates the base IRI
9853
- case void 0:
9854
- return base;
9855
- // Resolve relative fragment IRIs against the base IRI
9856
- case "#":
9857
- return base + iri;
9858
- // Resolve relative query string IRIs by replacing the query string
9859
- case "?":
9860
- return base.replace(/(?:\?.*)?$/u, iri);
9861
- // Resolve root relative IRIs at the root of the base IRI
9862
- case "/":
9863
- const baseMatch = base.match(/^(?:[a-z]+:\/*)?[^\/]*/);
9864
- if (!baseMatch) {
9865
- throw new Error(`Could not determine relative IRI using base: ${base}`);
9866
- }
9867
- const baseRoot = baseMatch[0];
9868
- return baseRoot + iri;
9869
- // Resolve all other IRIs at the base IRI's path
9870
- default:
9871
- const basePath = base.replace(/[^\/:]*$/, "");
9872
- return basePath + iri;
9873
- }
9874
- }
9875
-
9876
- // lib/lexer-builder/LexerBuilder.ts
9877
- var LexerBuilder = class _LexerBuilder {
9878
- static create(starter) {
9879
- return new _LexerBuilder(starter);
9880
- }
9881
- constructor(starter) {
9882
- this.tokens = starter?.tokens ? [...starter.tokens] : [];
9883
- }
9884
- get(index) {
9885
- return this.tokens[index];
9886
- }
9887
- merge(merge, overwrite = []) {
9888
- const extraTokens = merge.tokens.filter((token) => {
9889
- const overwriteToken = overwrite.find((t) => t.name === token.name);
9890
- if (overwriteToken) {
9891
- return false;
9892
- }
9893
- const match = this.tokens.find((t) => t.name === token.name);
9894
- if (match) {
9895
- if (match !== token) {
9896
- throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);
9897
- }
9898
- return false;
9899
- }
9900
- return true;
9901
- });
9902
- this.tokens.push(...extraTokens);
9903
- return this;
9904
- }
9905
- add(...token) {
9906
- this.tokens.push(...token);
9907
- return this;
9908
- }
9909
- addBefore(before, ...token) {
9910
- const index = this.tokens.indexOf(before);
9911
- if (index === -1) {
9912
- throw new Error("Token not found");
9913
- }
9914
- this.tokens.splice(index, 0, ...token);
9915
- return this;
9916
- }
9917
- moveBeforeOrAfter(beforeOrAfter, before, ...tokens) {
9918
- const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === "before" ? 0 : 1);
9919
- if (beforeIndex === -1) {
9920
- throw new Error("BeforeToken not found");
9921
- }
9922
- for (const token of tokens) {
9923
- const tokenIndex = this.tokens.indexOf(token);
9924
- if (tokenIndex === -1) {
9925
- throw new Error("Token not found");
9926
- }
9927
- this.tokens.splice(tokenIndex, 1);
9928
- this.tokens.splice(beforeIndex, 0, token);
9929
- }
9930
- return this;
9931
- }
9932
- moveBefore(before, ...tokens) {
9933
- return this.moveBeforeOrAfter("before", before, ...tokens);
9934
- }
9935
- moveAfter(after, ...tokens) {
9936
- return this.moveBeforeOrAfter("after", after, ...tokens);
9937
- }
9938
- addAfter(after, ...token) {
9939
- const index = this.tokens.indexOf(after);
9940
- if (index === -1) {
9941
- throw new Error("Token not found");
9942
- }
9943
- this.tokens.splice(index + 1, 0, ...token);
9944
- return this;
9945
- }
9946
- delete(...token) {
9947
- for (const t of token) {
9948
- const index = this.tokens.indexOf(t);
9949
- if (index === -1) {
9950
- throw new Error("Token not found");
9951
- }
9952
- this.tokens.splice(index, 1);
9953
- }
9954
- return this;
9955
- }
9956
- build() {
9957
- return this.tokens;
9958
- }
9959
- };
9960
-
9961
- // lib/lexer-helper/utils.ts
9962
9725
  function createToken2(config) {
9963
9726
  return createToken(config);
9964
9727
  }
9965
-
9966
- // lib/Wildcard.ts
9967
- var Wildcard = class {
9968
- constructor() {
9969
- this.value = "*";
9970
- this.termType = "Wildcard";
9971
- return WILDCARD ?? this;
9972
- }
9973
- equals(other) {
9974
- return Boolean(other && this.termType === other.termType);
9975
- }
9976
- toJSON() {
9977
- const { value, ...rest } = this;
9978
- return rest;
9979
- }
9980
- };
9981
- var WILDCARD;
9982
- WILDCARD = new Wildcard();
9983
9728
  /*! Bundled license information:
9984
9729
 
9985
9730
  lodash-es/lodash.js: