@traqula/core 0.0.3 → 0.0.5

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 (30) hide show
  1. package/README.md +3 -2
  2. package/lib/generator-builder/builderTypes.d.ts +1 -1
  3. package/lib/generator-builder/builderTypes.js.map +1 -1
  4. package/lib/generator-builder/dynamicGenerator.js +89 -87
  5. package/lib/generator-builder/dynamicGenerator.js.map +1 -1
  6. package/lib/generator-builder/generatorBuilder.d.ts +3 -3
  7. package/lib/generator-builder/generatorBuilder.js +1 -0
  8. package/lib/generator-builder/generatorBuilder.js.map +1 -1
  9. package/lib/generator-builder/generatorTypes.d.ts +3 -3
  10. package/lib/generator-builder/generatorTypes.js.map +1 -1
  11. package/lib/index.cjs +123 -117
  12. package/lib/indirection-builder/IndirBuilder.d.ts +2 -2
  13. package/lib/indirection-builder/IndirBuilder.js +1 -0
  14. package/lib/indirection-builder/IndirBuilder.js.map +1 -1
  15. package/lib/indirection-builder/dynamicIndirected.js +11 -10
  16. package/lib/indirection-builder/dynamicIndirected.js.map +1 -1
  17. package/lib/lexer-builder/LexerBuilder.js +1 -0
  18. package/lib/lexer-builder/LexerBuilder.js.map +1 -1
  19. package/lib/parser-builder/builderTypes.d.ts +2 -2
  20. package/lib/parser-builder/builderTypes.js.map +1 -1
  21. package/lib/parser-builder/dynamicParser.js +3 -2
  22. package/lib/parser-builder/dynamicParser.js.map +1 -1
  23. package/lib/parser-builder/parserBuilder.d.ts +5 -5
  24. package/lib/parser-builder/parserBuilder.js +7 -6
  25. package/lib/parser-builder/parserBuilder.js.map +1 -1
  26. package/lib/parser-builder/ruleDefTypes.d.ts +4 -4
  27. package/lib/parser-builder/ruleDefTypes.js.map +1 -1
  28. package/lib/utils.d.ts +1 -1
  29. package/lib/utils.js.map +1 -1
  30. package/package.json +3 -3
package/lib/index.cjs CHANGED
@@ -163,92 +163,8 @@ var CoreFactory = class {
163
163
  var DynamicGenerator = class {
164
164
  constructor(rules) {
165
165
  this.rules = rules;
166
- this.factory = new CoreFactory();
167
- this.__context = void 0;
168
- this.origSource = "";
169
- this.generatedUntil = 0;
170
- this.stringBuilder = [];
171
- this.subrule = (cstDef, ast, arg) => {
172
- const def = this.rules[cstDef.name];
173
- if (!def) {
174
- throw new Error(`Rule ${cstDef.name} not found`);
175
- }
176
- const generate = () => def.gImpl({
177
- SUBRULE: this.subrule,
178
- PRINT: this.print,
179
- PRINT_SPACE_LEFT: this.printSpaceLeft,
180
- PRINT_WORD: this.printWord,
181
- PRINT_WORDS: this.printWords,
182
- CATCHUP: this.catchup,
183
- HANDLE_LOC: this.handleLoc
184
- })(ast, this.getSafeContext(), arg);
185
- if (this.factory.isLocalized(ast)) {
186
- this.handleLoc(ast, generate);
187
- } else {
188
- generate();
189
- }
190
- };
191
- this.handleLoc = (localized, handle) => {
192
- if (this.factory.isSourceLocationNoMaterialize(localized.loc)) {
193
- return;
194
- }
195
- if (this.factory.isSourceLocationStringReplace(localized.loc)) {
196
- this.catchup(localized.loc.start);
197
- this.print(localized.loc.newSource);
198
- this.generatedUntil = localized.loc.end;
199
- return;
200
- }
201
- if (this.factory.isSourceLocationNodeReplace(localized.loc)) {
202
- this.catchup(localized.loc.start);
203
- this.generatedUntil = localized.loc.end;
204
- }
205
- if (this.factory.isSourceLocationSource(localized.loc)) {
206
- this.catchup(localized.loc.start);
207
- }
208
- const ret = handle();
209
- if (this.factory.isSourceLocationSource(localized.loc)) {
210
- this.catchup(localized.loc.end);
211
- }
212
- return ret;
213
- };
214
- this.catchup = (until) => {
215
- const start = this.generatedUntil;
216
- if (start < until) {
217
- this.print(this.origSource.slice(start, until));
218
- }
219
- this.generatedUntil = Math.max(this.generatedUntil, until);
220
- };
221
- this.print = (...args) => {
222
- const pureArgs = args.filter((x) => x.length > 0);
223
- if (pureArgs.length > 0) {
224
- const [head2, ...tail] = pureArgs;
225
- if (this.expectsSpace) {
226
- this.expectsSpace = false;
227
- const blanks = /* @__PURE__ */ new Set(["\n", " ", " "]);
228
- if (this.stringBuilder.length > 0 && !(blanks.has(head2[0]) || blanks.has(this.stringBuilder.at(-1).at(-1)))) {
229
- this.stringBuilder.push(" ");
230
- }
231
- }
232
- this.stringBuilder.push(head2);
233
- this.stringBuilder.push(...tail);
234
- }
235
- };
236
- this.printWord = (...args) => {
237
- this.expectsSpace = true;
238
- this.print(...args);
239
- this.expectsSpace = true;
240
- };
241
- this.printSpaceLeft = (...args) => {
242
- this.expectsSpace = true;
243
- this.print(...args);
244
- };
245
- this.printWords = (...args) => {
246
- for (const arg of args) {
247
- this.printWord(arg);
248
- }
249
- };
250
166
  for (const rule of Object.values(rules)) {
251
- this[rule.name] = (input, context, args) => {
167
+ this[rule.name] = ((input, context, args) => {
252
168
  this.expectsSpace = false;
253
169
  this.stringBuilder.length = 0;
254
170
  this.origSource = context.origSource;
@@ -257,15 +173,100 @@ var DynamicGenerator = class {
257
173
  this.subrule(rule, input, args);
258
174
  this.catchup(this.origSource.length);
259
175
  return this.stringBuilder.join("");
260
- };
176
+ });
261
177
  }
262
178
  }
179
+ factory = new CoreFactory();
180
+ __context = void 0;
181
+ origSource = "";
182
+ generatedUntil = 0;
183
+ expectsSpace;
184
+ stringBuilder = [];
263
185
  setContext(context) {
264
186
  this.__context = context;
265
187
  }
266
188
  getSafeContext() {
267
189
  return this.__context;
268
190
  }
191
+ subrule = (cstDef, ast, ...arg) => {
192
+ const def = this.rules[cstDef.name];
193
+ if (!def) {
194
+ throw new Error(`Rule ${cstDef.name} not found`);
195
+ }
196
+ const generate = () => def.gImpl({
197
+ SUBRULE: this.subrule,
198
+ PRINT: this.print,
199
+ PRINT_SPACE_LEFT: this.printSpaceLeft,
200
+ PRINT_WORD: this.printWord,
201
+ PRINT_WORDS: this.printWords,
202
+ CATCHUP: this.catchup,
203
+ HANDLE_LOC: this.handleLoc
204
+ })(ast, this.getSafeContext(), ...arg);
205
+ if (this.factory.isLocalized(ast)) {
206
+ this.handleLoc(ast, generate);
207
+ } else {
208
+ generate();
209
+ }
210
+ };
211
+ handleLoc = (localized, handle) => {
212
+ if (this.factory.isSourceLocationNoMaterialize(localized.loc)) {
213
+ return;
214
+ }
215
+ if (this.factory.isSourceLocationStringReplace(localized.loc)) {
216
+ this.catchup(localized.loc.start);
217
+ this.print(localized.loc.newSource);
218
+ this.generatedUntil = localized.loc.end;
219
+ return;
220
+ }
221
+ if (this.factory.isSourceLocationNodeReplace(localized.loc)) {
222
+ this.catchup(localized.loc.start);
223
+ this.generatedUntil = localized.loc.end;
224
+ }
225
+ if (this.factory.isSourceLocationSource(localized.loc)) {
226
+ this.catchup(localized.loc.start);
227
+ }
228
+ const ret = handle();
229
+ if (this.factory.isSourceLocationSource(localized.loc)) {
230
+ this.catchup(localized.loc.end);
231
+ }
232
+ return ret;
233
+ };
234
+ catchup = (until) => {
235
+ const start = this.generatedUntil;
236
+ if (start < until) {
237
+ this.print(this.origSource.slice(start, until));
238
+ }
239
+ this.generatedUntil = Math.max(this.generatedUntil, until);
240
+ };
241
+ print = (...args) => {
242
+ const pureArgs = args.filter((x) => x.length > 0);
243
+ if (pureArgs.length > 0) {
244
+ const [head2, ...tail] = pureArgs;
245
+ if (this.expectsSpace) {
246
+ this.expectsSpace = false;
247
+ const blanks = /* @__PURE__ */ new Set(["\n", " ", " "]);
248
+ if (this.stringBuilder.length > 0 && !(blanks.has(head2[0]) || blanks.has(this.stringBuilder.at(-1).at(-1)))) {
249
+ this.stringBuilder.push(" ");
250
+ }
251
+ }
252
+ this.stringBuilder.push(head2);
253
+ this.stringBuilder.push(...tail);
254
+ }
255
+ };
256
+ printWord = (...args) => {
257
+ this.expectsSpace = true;
258
+ this.print(...args);
259
+ this.expectsSpace = true;
260
+ };
261
+ printSpaceLeft = (...args) => {
262
+ this.expectsSpace = true;
263
+ this.print(...args);
264
+ };
265
+ printWords = (...args) => {
266
+ for (const arg of args) {
267
+ this.printWord(arg);
268
+ }
269
+ };
269
270
  };
270
271
 
271
272
  // lib/generator-builder/generatorBuilder.ts
@@ -283,6 +284,7 @@ var GeneratorBuilder = class _GeneratorBuilder {
283
284
  }
284
285
  return new _GeneratorBuilder(listToRuleDefMap(start));
285
286
  }
287
+ rules;
286
288
  constructor(startRules) {
287
289
  this.rules = startRules;
288
290
  }
@@ -377,29 +379,29 @@ function listToIndirectionMap(rules) {
377
379
  var DynamicIndirect = class {
378
380
  constructor(rules) {
379
381
  this.rules = rules;
380
- this.__context = void 0;
381
- this.subrule = (cstDef, ...args) => {
382
- const def = this.rules[cstDef.name];
383
- if (!def) {
384
- throw new Error(`Rule ${cstDef.name} not found`);
385
- }
386
- return def.fun({
387
- SUBRULE: this.subrule
388
- })(this.getSafeContext(), ...args);
389
- };
390
382
  for (const rule of Object.values(rules)) {
391
- this[rule.name] = (context, ...args) => {
383
+ this[rule.name] = ((context, ...args) => {
392
384
  this.setContext(context);
393
385
  return this.subrule(rule, ...args);
394
- };
386
+ });
395
387
  }
396
388
  }
389
+ __context = void 0;
397
390
  setContext(context) {
398
391
  this.__context = context;
399
392
  }
400
393
  getSafeContext() {
401
394
  return this.__context;
402
395
  }
396
+ subrule = (cstDef, ...args) => {
397
+ const def = this.rules[cstDef.name];
398
+ if (!def) {
399
+ throw new Error(`Rule ${cstDef.name} not found`);
400
+ }
401
+ return def.fun({
402
+ SUBRULE: this.subrule
403
+ })(this.getSafeContext(), ...args);
404
+ };
403
405
  };
404
406
 
405
407
  // lib/indirection-builder/IndirBuilder.ts
@@ -410,6 +412,7 @@ var IndirBuilder = class _IndirBuilder {
410
412
  }
411
413
  return new _IndirBuilder(listToIndirectionMap(start));
412
414
  }
415
+ rules;
413
416
  constructor(startRules) {
414
417
  this.rules = startRules;
415
418
  }
@@ -662,10 +665,10 @@ var coreJsData = root_default["__core-js_shared__"];
662
665
  var coreJsData_default = coreJsData;
663
666
 
664
667
  // ../../node_modules/lodash-es/_isMasked.js
665
- var maskSrcKey = function() {
668
+ var maskSrcKey = (function() {
666
669
  var uid = /[^.]+$/.exec(coreJsData_default && coreJsData_default.keys && coreJsData_default.keys.IE_PROTO || "");
667
670
  return uid ? "Symbol(src)_1." + uid : "";
668
- }();
671
+ })();
669
672
  function isMasked(func) {
670
673
  return !!maskSrcKey && maskSrcKey in func;
671
674
  }
@@ -727,7 +730,7 @@ var WeakMap_default = WeakMap2;
727
730
 
728
731
  // ../../node_modules/lodash-es/_baseCreate.js
729
732
  var objectCreate = Object.create;
730
- var baseCreate = /* @__PURE__ */ function() {
733
+ var baseCreate = /* @__PURE__ */ (function() {
731
734
  function object() {
732
735
  }
733
736
  return function(proto) {
@@ -742,7 +745,7 @@ var baseCreate = /* @__PURE__ */ function() {
742
745
  object.prototype = void 0;
743
746
  return result;
744
747
  };
745
- }();
748
+ })();
746
749
  var baseCreate_default = baseCreate;
747
750
 
748
751
  // ../../node_modules/lodash-es/_apply.js
@@ -807,14 +810,14 @@ function constant(value) {
807
810
  var constant_default = constant;
808
811
 
809
812
  // ../../node_modules/lodash-es/_defineProperty.js
810
- var defineProperty = function() {
813
+ var defineProperty = (function() {
811
814
  try {
812
815
  var func = getNative_default(Object, "defineProperty");
813
816
  func({}, "", {});
814
817
  return func;
815
818
  } catch (e) {
816
819
  }
817
- }();
820
+ })();
818
821
  var defineProperty_default = defineProperty;
819
822
 
820
823
  // ../../node_modules/lodash-es/_baseSetToString.js
@@ -1052,9 +1055,9 @@ var baseIsArguments_default = baseIsArguments;
1052
1055
  var objectProto6 = Object.prototype;
1053
1056
  var hasOwnProperty4 = objectProto6.hasOwnProperty;
1054
1057
  var propertyIsEnumerable = objectProto6.propertyIsEnumerable;
1055
- var isArguments = baseIsArguments_default(/* @__PURE__ */ function() {
1058
+ var isArguments = baseIsArguments_default(/* @__PURE__ */ (function() {
1056
1059
  return arguments;
1057
- }()) ? baseIsArguments_default : function(value) {
1060
+ })()) ? baseIsArguments_default : function(value) {
1058
1061
  return isObjectLike_default(value) && hasOwnProperty4.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
1059
1062
  };
1060
1063
  var isArguments_default = isArguments;
@@ -1120,7 +1123,7 @@ var freeExports2 = typeof exports == "object" && exports && !exports.nodeType &&
1120
1123
  var freeModule2 = freeExports2 && typeof module == "object" && module && !module.nodeType && module;
1121
1124
  var moduleExports2 = freeModule2 && freeModule2.exports === freeExports2;
1122
1125
  var freeProcess = moduleExports2 && freeGlobal_default.process;
1123
- var nodeUtil = function() {
1126
+ var nodeUtil = (function() {
1124
1127
  try {
1125
1128
  var types = freeModule2 && freeModule2.require && freeModule2.require("util").types;
1126
1129
  if (types) {
@@ -1129,7 +1132,7 @@ var nodeUtil = function() {
1129
1132
  return freeProcess && freeProcess.binding && freeProcess.binding("util");
1130
1133
  } catch (e) {
1131
1134
  }
1132
- }();
1135
+ })();
1133
1136
  var nodeUtil_default = nodeUtil;
1134
1137
 
1135
1138
  // ../../node_modules/lodash-es/isTypedArray.js
@@ -9681,6 +9684,7 @@ var EmbeddedActionsParser = class extends Parser {
9681
9684
 
9682
9685
  // lib/lexer-builder/LexerBuilder.ts
9683
9686
  var LexerBuilder = class _LexerBuilder {
9687
+ tokens;
9684
9688
  static create(starter) {
9685
9689
  return new _LexerBuilder(starter);
9686
9690
  }
@@ -9777,6 +9781,7 @@ var LexerBuilder = class _LexerBuilder {
9777
9781
 
9778
9782
  // lib/parser-builder/dynamicParser.ts
9779
9783
  var DynamicParser = class extends EmbeddedActionsParser {
9784
+ context;
9780
9785
  setContext(context) {
9781
9786
  this.context = context;
9782
9787
  }
@@ -9784,7 +9789,7 @@ var DynamicParser = class extends EmbeddedActionsParser {
9784
9789
  super(tokenVocabulary, {
9785
9790
  // RecoveryEnabled: true,
9786
9791
  maxLookahead: 2,
9787
- // SkipValidations: true,
9792
+ skipValidations: true,
9788
9793
  ...config
9789
9794
  });
9790
9795
  this.context = void 0;
@@ -9799,7 +9804,7 @@ var DynamicParser = class extends EmbeddedActionsParser {
9799
9804
  this.performSelfAnalysis();
9800
9805
  }
9801
9806
  constructSelfRef() {
9802
- const subRuleImpl = (chevrotainSubrule) => (cstDef, arg) => chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] });
9807
+ const subRuleImpl = (chevrotainSubrule) => ((cstDef, ...arg) => chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, ...arg] }));
9803
9808
  return {
9804
9809
  CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),
9805
9810
  CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),
@@ -9906,6 +9911,7 @@ var ParserBuilder = class _ParserBuilder {
9906
9911
  }
9907
9912
  return new _ParserBuilder(listToRuleDefMap2(start));
9908
9913
  }
9914
+ rules;
9909
9915
  constructor(startRules) {
9910
9916
  this.rules = startRules;
9911
9917
  }
@@ -9986,7 +9992,7 @@ var ParserBuilder = class _ParserBuilder {
9986
9992
  const firstError = errors[0];
9987
9993
  const messageBuilder = ["Parse error"];
9988
9994
  const lineIdx = firstError.token.startLine;
9989
- if (lineIdx !== void 0) {
9995
+ if (lineIdx !== void 0 && !Number.isNaN(lineIdx)) {
9990
9996
  const errorLine = input.split("\n")[lineIdx - 1];
9991
9997
  messageBuilder.push(` on line ${lineIdx}
9992
9998
  ${errorLine}`);
@@ -10010,9 +10016,9 @@ ${firstError.message}`);
10010
10016
  const lexer = LexerBuilder.create().add(...tokenVocabulary).build({
10011
10017
  positionTracking: "full",
10012
10018
  recoveryEnabled: false,
10013
- // SafeMode: true,
10014
- // SkipValidations: true,
10015
- // ensureOptimizations: true,
10019
+ ensureOptimizations: true,
10020
+ safeMode: false,
10021
+ skipValidations: true,
10016
10022
  ...lexerConfig
10017
10023
  });
10018
10024
  const parser = this.consume({
@@ -10021,12 +10027,12 @@ ${firstError.message}`);
10021
10027
  });
10022
10028
  const selfSufficientParser = {};
10023
10029
  for (const rule of Object.values(this.rules)) {
10024
- selfSufficientParser[rule.name] = (input, context, arg) => {
10030
+ selfSufficientParser[rule.name] = ((input, context, ...args) => {
10025
10031
  const processedInput = queryPreProcessor(input);
10026
10032
  const lexResult = lexer.tokenize(processedInput);
10027
10033
  parser.input = lexResult.tokens;
10028
10034
  parser.setContext(context);
10029
- const result = parser[rule.name](context, arg);
10035
+ const result = parser[rule.name](context, ...args);
10030
10036
  if (parser.errors.length > 0) {
10031
10037
  if (errorHandler) {
10032
10038
  errorHandler(parser.errors);
@@ -10035,7 +10041,7 @@ ${firstError.message}`);
10035
10041
  }
10036
10042
  }
10037
10043
  return result;
10038
- };
10044
+ });
10039
10045
  }
10040
10046
  return selfSufficientParser;
10041
10047
  }
@@ -8,9 +8,9 @@ export declare class IndirBuilder<Context, Names extends string, RuleDefs extend
8
8
  private constructor();
9
9
  widenContext<NewContext extends Context>(): IndirBuilder<NewContext, Names, RuleDefs>;
10
10
  typePatch<Patch extends {
11
- [Key in Names]?: any;
11
+ [Key in Names]?: [any] | [any, any];
12
12
  }>(): IndirBuilder<Context, Names, {
13
- [Key in Names]: Key extends keyof Patch ? (IndirDef<Context, Key, Patch[Key][0], Patch[Key][1]>) : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never);
13
+ [Key in Names]: Key extends keyof Patch ? (Patch[Key] extends [any, any] ? IndirDef<Context, Key, Patch[Key][0], Patch[Key][1]> : (Patch[Key] extends [any] ? (RuleDefs[Key] extends IndirDef<any, any, any, infer Par> ? IndirDef<Context, Key, Patch[Key][0], Par> : never) : never)) : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never);
14
14
  }>;
15
15
  /**
16
16
  * Change the implementation of an existing indirection.
@@ -7,6 +7,7 @@ export class IndirBuilder {
7
7
  }
8
8
  return new IndirBuilder(listToIndirectionMap(start));
9
9
  }
10
+ rules;
10
11
  constructor(startRules) {
11
12
  this.rules = startRules;
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IndirBuilder.js","sourceRoot":"","sources":["IndirBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,W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AC,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/D,OAAuB,IAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,UAAU,CAAkB,QAAW;QAG5C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC5B,OAEY,IAAI,CAAC;IACnB,CAAC;IAEM,KAAK;QACV,OAA4D,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9F,CAAC;CACF","sourcesContent":["import type { ParseNamesFromList } from '../parser-builder/builderTypes';\nimport type { CheckOverlap } from '../utils';\nimport { DynamicIndirect } from './dynamicIndirected';\nimport type { IndirDef, IndirectionMap, IndirectObjFromIndirDefs, ParseIndirsToObject } from './helpers';\nimport { listToIndirectionMap } from './helpers';\n\nexport class IndirBuilder<Context, Names extends string, RuleDefs extends IndirectionMap<Names>> {\n public static create<Context, Names extends string, RuleDefs extends IndirectionMap<Names>>(\n args: IndirBuilder<Context, Names, RuleDefs>\n ): IndirBuilder<Context, Names, RuleDefs>;\n public static create<\n Rules extends readonly IndirDef[] = readonly IndirDef[],\n Context = Rules[0] extends IndirDef<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends IndirectionMap<Names> = ParseIndirsToObject<Rules>,\n >(rules: Rules): IndirBuilder<Context, Names, RuleDefs>;\n public static create<\n Rules extends readonly IndirDef[] = readonly IndirDef[],\n Context = Rules[0] extends IndirDef<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends IndirectionMap<Names> = ParseIndirsToObject<Rules>,\n >(\n start: Rules | IndirBuilder<Context, Names, RuleDefs>,\n ): IndirBuilder<Context, Names, RuleDefs> {\n if (start instanceof IndirBuilder) {\n return new IndirBuilder({ ...start.rules });\n }\n return <IndirBuilder<Context, Names, RuleDefs>> <unknown> new IndirBuilder(listToIndirectionMap(start));\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n public widenContext<NewContext extends Context>(): IndirBuilder<NewContext, Names, RuleDefs> {\n return <IndirBuilder<NewContext, Names, RuleDefs>> <unknown> this;\n }\n\n public typePatch<Patch extends {[Key in Names]?: any }>():\n IndirBuilder<Context, Names, {[Key in Names]: Key extends keyof Patch ? (\n IndirDef<Context, Key, Patch[Key][0], Patch[Key][1]>\n ) : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never) }> {\n return <IndirBuilder<Context, Names, {[Key in Names]: Key extends keyof Patch ? (\n RuleDefs[Key] extends IndirDef<Context, Key, any, infer Par> ? IndirDef<Context, Key, Patch[Key], Par> : never\n ) : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never) }>> <unknown> this;\n }\n\n /**\n * Change the implementation of an existing indirection.\n */\n public patchRule<U extends Names, RET, ARGS extends any[]>(patch: IndirDef<Context, U, RET, ARGS>):\n IndirBuilder<Context, Names, {[Key in Names]: Key extends U ?\n IndirDef<Context, Key, RET, ARGS> :\n (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never)\n } > {\n const self = <IndirBuilder<Context, Names, {[Key in Names]: Key extends U ?\n IndirDef<Context, Key, RET, ARGS> : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never) }>>\n <unknown> this;\n self.rules[patch.name] = <any> patch;\n return self;\n }\n\n /**\n * Add an indirection function. If the rule already exists, but the implementation differs, an error will be thrown.\n */\n public addRuleRedundant<U extends string, RET, ARGS extends any[]>(rule: IndirDef<Context, U, RET, ARGS>):\n IndirBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n IndirDef<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never)\n }> {\n const self = <IndirBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n IndirDef<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never) }>>\n <unknown> this;\n const rules = <Record<string, IndirDef<Context>>> self.rules;\n if (rules[rule.name] !== undefined && rules[rule.name] !== rule) {\n throw new Error(`Function ${rule.name} already exists in the builder`);\n }\n rules[rule.name] = rule;\n return self;\n }\n\n /**\n * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.\n */\n public addRule<U extends string, RET, ARGS extends any[]>(\n rule: CheckOverlap<U, Names, IndirDef<Context, U, RET, ARGS>>,\n ): IndirBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n IndirDef<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends readonly IndirDef<Context>[]>(\n ...rules: CheckOverlap<ParseNamesFromList<U>, Names, U>\n ): IndirBuilder<\n Context,\n Names | ParseNamesFromList<U>,\n {[K in Names | ParseNamesFromList<U>]:\n K extends keyof ParseIndirsToObject<typeof rules> ? (\n ParseIndirsToObject<typeof rules>[K] extends IndirDef<Context, K> ? ParseIndirsToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never\n )\n }\n > {\n this.rules = { ...this.rules, ...listToIndirectionMap(rules) };\n return <any> <unknown> this;\n }\n\n /**\n * Delete a grammar rule by its name.\n */\n public deleteRule<U extends Names>(ruleName: U):\n IndirBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <IndirBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never }>>\n <unknown> this;\n }\n\n public build(): IndirectObjFromIndirDefs<Context, Names, RuleDefs> {\n return <IndirectObjFromIndirDefs<Context, Names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,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,OAAO,CACZ,IAA6D;QAI7D,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEM,OAAO,CACZ,GAAG,KAAoD;QAYvD,IAAI,CAAC,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/D,OAAuB,IAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,UAAU,CAAkB,QAAW;QAG5C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC5B,OAEY,IAAI,CAAC;IACnB,CAAC;IAEM,KAAK;QACV,OAA4D,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9F,CAAC;CACF","sourcesContent":["import type { ParseNamesFromList } from '../parser-builder/builderTypes';\nimport type { CheckOverlap } from '../utils';\nimport { DynamicIndirect } from './dynamicIndirected';\nimport type { IndirDef, IndirectionMap, IndirectObjFromIndirDefs, ParseIndirsToObject } from './helpers';\nimport { listToIndirectionMap } from './helpers';\n\nexport class IndirBuilder<Context, Names extends string, RuleDefs extends IndirectionMap<Names>> {\n public static create<Context, Names extends string, RuleDefs extends IndirectionMap<Names>>(\n args: IndirBuilder<Context, Names, RuleDefs>\n ): IndirBuilder<Context, Names, RuleDefs>;\n public static create<\n Rules extends readonly IndirDef[] = readonly IndirDef[],\n Context = Rules[0] extends IndirDef<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends IndirectionMap<Names> = ParseIndirsToObject<Rules>,\n >(rules: Rules): IndirBuilder<Context, Names, RuleDefs>;\n public static create<\n Rules extends readonly IndirDef[] = readonly IndirDef[],\n Context = Rules[0] extends IndirDef<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends IndirectionMap<Names> = ParseIndirsToObject<Rules>,\n >(\n start: Rules | IndirBuilder<Context, Names, RuleDefs>,\n ): IndirBuilder<Context, Names, RuleDefs> {\n if (start instanceof IndirBuilder) {\n return new IndirBuilder({ ...start.rules });\n }\n return <IndirBuilder<Context, Names, RuleDefs>> <unknown> new IndirBuilder(listToIndirectionMap(start));\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n public widenContext<NewContext extends Context>(): IndirBuilder<NewContext, Names, RuleDefs> {\n return <IndirBuilder<NewContext, Names, RuleDefs>> <unknown> this;\n }\n\n public typePatch<Patch extends {[Key in Names]?: [any] | [any, any]}>():\n IndirBuilder<Context, Names, {[Key in Names]: Key extends keyof Patch ? (\n Patch[Key] extends [any, any] ? IndirDef<Context, Key, Patch[Key][0], Patch[Key][1]> : (\n // Only one - infer arg yourself\n Patch[Key] extends [ any ] ? (\n RuleDefs[Key] extends IndirDef<any, any, any, infer Par> ? IndirDef<Context, Key, Patch[Key][0], Par> : never\n ) : never\n )\n ) : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never) }> {\n return <any> this;\n }\n\n /**\n * Change the implementation of an existing indirection.\n */\n public patchRule<U extends Names, RET, ARGS extends any[]>(patch: IndirDef<Context, U, RET, ARGS>):\n IndirBuilder<Context, Names, {[Key in Names]: Key extends U ?\n IndirDef<Context, Key, RET, ARGS> :\n (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never)\n } > {\n const self = <IndirBuilder<Context, Names, {[Key in Names]: Key extends U ?\n IndirDef<Context, Key, RET, ARGS> : (RuleDefs[Key] extends IndirDef<Context, Key> ? RuleDefs[Key] : never) }>>\n <unknown> this;\n self.rules[patch.name] = <any> patch;\n return self;\n }\n\n /**\n * Add an indirection function. If the rule already exists, but the implementation differs, an error will be thrown.\n */\n public addRuleRedundant<U extends string, RET, ARGS extends any[]>(rule: IndirDef<Context, U, RET, ARGS>):\n IndirBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n IndirDef<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never)\n }> {\n const self = <IndirBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n IndirDef<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never) }>>\n <unknown> this;\n const rules = <Record<string, IndirDef<Context>>> self.rules;\n if (rules[rule.name] !== undefined && rules[rule.name] !== rule) {\n throw new Error(`Function ${rule.name} already exists in the builder`);\n }\n rules[rule.name] = rule;\n return self;\n }\n\n /**\n * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.\n */\n public addRule<U extends string, RET, ARGS extends any[]>(\n rule: CheckOverlap<U, Names, IndirDef<Context, U, RET, ARGS>>,\n ): IndirBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n IndirDef<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends readonly IndirDef<Context>[]>(\n ...rules: CheckOverlap<ParseNamesFromList<U>, Names, U>\n ): IndirBuilder<\n Context,\n Names | ParseNamesFromList<U>,\n {[K in Names | ParseNamesFromList<U>]:\n K extends keyof ParseIndirsToObject<typeof rules> ? (\n ParseIndirsToObject<typeof rules>[K] extends IndirDef<Context, K> ? ParseIndirsToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never) : never\n )\n }\n > {\n this.rules = { ...this.rules, ...listToIndirectionMap(rules) };\n return <any> <unknown> this;\n }\n\n /**\n * Delete a grammar rule by its name.\n */\n public deleteRule<U extends Names>(ruleName: U):\n IndirBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <IndirBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends IndirDef<Context, K> ? RuleDefs[K] : never }>>\n <unknown> this;\n }\n\n public build(): IndirectObjFromIndirDefs<Context, Names, RuleDefs> {\n return <IndirectObjFromIndirDefs<Context, Names, RuleDefs>> new DynamicIndirect(this.rules);\n }\n}\n"]}
@@ -1,16 +1,8 @@
1
1
  export class DynamicIndirect {
2
+ rules;
3
+ __context = undefined;
2
4
  constructor(rules) {
3
5
  this.rules = rules;
4
- this.__context = undefined;
5
- this.subrule = (cstDef, ...args) => {
6
- const def = this.rules[cstDef.name];
7
- if (!def) {
8
- throw new Error(`Rule ${cstDef.name} not found`);
9
- }
10
- return def.fun({
11
- SUBRULE: this.subrule,
12
- })(this.getSafeContext(), ...args);
13
- };
14
6
  for (const rule of Object.values(rules)) {
15
7
  this[rule.name] = ((context, ...args) => {
16
8
  this.setContext(context);
@@ -24,5 +16,14 @@ export class DynamicIndirect {
24
16
  getSafeContext() {
25
17
  return this.__context;
26
18
  }
19
+ subrule = (cstDef, ...args) => {
20
+ const def = this.rules[cstDef.name];
21
+ if (!def) {
22
+ throw new Error(`Rule ${cstDef.name} not found`);
23
+ }
24
+ return def.fun({
25
+ SUBRULE: this.subrule,
26
+ })(this.getSafeContext(), ...args);
27
+ };
27
28
  }
28
29
  //# sourceMappingURL=dynamicIndirected.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamicIndirected.js","sourceRoot":"","sources":["dynamicIndirected.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;IAG1B,YAA6B,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;QAFlC,cAAS,GAAwB,SAAS,CAAC;QAmBlC,YAAO,GAA2B,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE;YACvE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAmB,MAAM,CAAC,IAAI,CAAC,CAAC;YACtD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,KAAK,CAAC,QAAQ,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC;YACnD,CAAC;YAED,OAAa,GAAG,CAAC,GAAG,CAAC;gBACnB,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACrC,CAAC,CAAC;QAzBA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAoC,KAAK,CAAC,EAAE,CAAC;YAC3E,IAAI,CAAsB,IAAI,CAAC,IAAI,CAAC,GAAS,CAAC,CAAC,OAAgB,EAAE,GAAG,IAAS,EAAO,EAAE;gBACpF,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEM,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAES,cAAc;QACtB,OAAiB,IAAI,CAAC,SAAS,CAAC;IAClC,CAAC;CAYF","sourcesContent":["import type { IndirDef, IndirDefArg, IndirectionMap } from './helpers';\n\nexport class DynamicIndirect<Context, Names extends string, RuleDefs extends IndirectionMap<Names>> {\n protected __context: Context | undefined = undefined;\n\n public constructor(protected rules: RuleDefs) {\n for (const rule of Object.values(<Record<string, IndirDef<Context>>>rules)) {\n this[<keyof (typeof this)>rule.name] = <any> ((context: Context, ...args: any): any => {\n this.setContext(context);\n return this.subrule(rule, ...args);\n });\n }\n }\n\n public setContext(context: Context): void {\n this.__context = context;\n }\n\n protected getSafeContext(): Context {\n return <Context> this.__context;\n }\n\n protected readonly subrule: IndirDefArg['SUBRULE'] = (cstDef, ...args) => {\n const def = this.rules[<Names> <unknown> cstDef.name];\n if (!def) {\n throw new Error(`Rule ${cstDef.name} not found`);\n }\n\n return <any> def.fun({\n SUBRULE: this.subrule,\n })(this.getSafeContext(), ...args);\n };\n}\n"]}
1
+ {"version":3,"file":"dynamicIndirected.js","sourceRoot":"","sources":["dynamicIndirected.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;IAGG;IAFnB,SAAS,GAAwB,SAAS,CAAC;IAErD,YAA6B,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;QAC1C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAoC,KAAK,CAAC,EAAE,CAAC;YAC3E,IAAI,CAAsB,IAAI,CAAC,IAAI,CAAC,GAAS,CAAC,CAAC,OAAgB,EAAE,GAAG,IAAS,EAAO,EAAE;gBACpF,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEM,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAES,cAAc;QACtB,OAAiB,IAAI,CAAC,SAAS,CAAC;IAClC,CAAC;IAEkB,OAAO,GAA2B,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE;QACvE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAmB,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,QAAQ,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC;QACnD,CAAC;QAED,OAAa,GAAG,CAAC,GAAG,CAAC;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC;CACH","sourcesContent":["import type { IndirDef, IndirDefArg, IndirectionMap } from './helpers';\n\nexport class DynamicIndirect<Context, Names extends string, RuleDefs extends IndirectionMap<Names>> {\n protected __context: Context | undefined = undefined;\n\n public constructor(protected rules: RuleDefs) {\n for (const rule of Object.values(<Record<string, IndirDef<Context>>>rules)) {\n this[<keyof (typeof this)>rule.name] = <any> ((context: Context, ...args: any): any => {\n this.setContext(context);\n return this.subrule(rule, ...args);\n });\n }\n }\n\n public setContext(context: Context): void {\n this.__context = context;\n }\n\n protected getSafeContext(): Context {\n return <Context> this.__context;\n }\n\n protected readonly subrule: IndirDefArg['SUBRULE'] = (cstDef, ...args) => {\n const def = this.rules[<Names> <unknown> cstDef.name];\n if (!def) {\n throw new Error(`Rule ${cstDef.name} not found`);\n }\n\n return <any> def.fun({\n SUBRULE: this.subrule,\n })(this.getSafeContext(), ...args);\n };\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { Lexer } from 'chevrotain';
2
2
  export class LexerBuilder {
3
+ tokens;
3
4
  static create(starter) {
4
5
  return new LexerBuilder(starter);
5
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LexerBuilder.js","sourceRoot":"","sources":["LexerBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,MAAM,OAAO,YAAY;IAGhB,MAAM,CAAC,MAAM,CAAsD,OAAW;QACnF,OAAW,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,YAAoB,OAA6B;QAC/C,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,GAAG,OAAO,CAAC,MAAM,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,CAAC;IAEM,KAAK,CACV,KAA+B,EAC/B,YAA8B,EAAE;QAGhC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YAChD,MAAM,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC,C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MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAqB,GAAG,KAAyB;QAC5D,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,WAA0B;QACrC,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;YAC5B,gBAAgB,EAAE,WAAW;YAC7B,eAAe,EAAE,KAAK;YACtB,mBAAmB,EAAE,IAAI;YACzB,kBAAkB;YAClB,yBAAyB;YACzB,GAAG,WAAW;SACf,CAAC,CAAC;IACL,CAAC;IAED,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import type { ILexerConfig } from '@chevrotain/types';\nimport type { TokenType } from 'chevrotain';\nimport { Lexer } from 'chevrotain';\nimport type { CheckOverlap, NamedToken } from '../utils';\n\nexport class LexerBuilder<NAMES extends string = string> {\n private readonly tokens: TokenType[];\n\n public static create<U extends LexerBuilder<T>, T extends string = never>(starter?: U): U {\n return <U> new LexerBuilder(starter);\n }\n\n private constructor(starter?: LexerBuilder<NAMES>) {\n this.tokens = starter?.tokens ? [ ...starter.tokens ] : [];\n }\n\n public merge<OtherNames extends string, OW extends string>(\n merge: LexerBuilder<OtherNames>,\n overwrite: NamedToken<OW>[] = [],\n ):\n LexerBuilder<NAMES | OtherNames> {\n const extraTokens = merge.tokens.filter((token) => {\n const overwriteToken = overwrite.find(t => t.name === token.name);\n if (overwriteToken) {\n return false;\n }\n const match = this.tokens.find(t => t.name === token.name);\n if (match) {\n if (match !== token) {\n throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);\n }\n return false;\n }\n return true;\n });\n this.tokens.push(...extraTokens);\n return this;\n }\n\n public add<Name extends string>(...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>):\n LexerBuilder<Name | NAMES> {\n this.tokens.push(...token);\n return this;\n }\n\n public addBefore<Name extends string>(\n before: NamedToken<NAMES>,\n ...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>\n ): LexerBuilder<NAMES | Name> {\n const index = this.tokens.indexOf(before);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index, 0, ...token);\n return this;\n }\n\n private moveBeforeOrAfter<Name extends string>(\n beforeOrAfter: 'before' | 'after',\n before: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === 'before' ? 0 : 1);\n if (beforeIndex === -1) {\n throw new Error('BeforeToken not found');\n }\n for (const token of tokens) {\n const tokenIndex = this.tokens.indexOf(token);\n if (tokenIndex === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(tokenIndex, 1);\n this.tokens.splice(beforeIndex, 0, token);\n }\n return this;\n }\n\n /**\n * @param before token to move rest before\n * @param tokens tokens to move before the first token\n */\n public moveBefore<Name extends string>(\n before: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n return this.moveBeforeOrAfter('before', before, ...tokens);\n }\n\n public moveAfter<Name extends string>(\n after: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n return this.moveBeforeOrAfter('after', after, ...tokens);\n }\n\n public addAfter<Name extends string>(\n after: NamedToken<NAMES>,\n ...token: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES | Name> {\n const index = this.tokens.indexOf(after);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index + 1, 0, ...token);\n return this;\n }\n\n public delete<Name extends NAMES>(...token: NamedToken<Name>[]): LexerBuilder<Exclude<NAMES, Name>> {\n for (const t of token) {\n const index = this.tokens.indexOf(t);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index, 1);\n }\n return this;\n }\n\n public build(lexerConfig?: ILexerConfig): Lexer {\n return new Lexer(this.tokens, {\n positionTracking: 'onlyStart',\n recoveryEnabled: false,\n ensureOptimizations: true,\n // SafeMode: true,\n // SkipValidations: true,\n ...lexerConfig,\n });\n }\n\n public get tokenVocabulary(): readonly TokenType[] {\n return this.tokens;\n }\n}\n"]}
1
+ {"version":3,"file":"LexerBuilder.js","sourceRoot":"","sources":["LexerBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,MAAM,OAAO,YAAY;IACN,MAAM,CAAc;IAE9B,MAAM,CAAC,MAAM,CAAsD,OAAW;QACnF,OAAW,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,YAAoB,OAA6B;QAC/C,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,GAAG,OAAO,CAAC,MAAM,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,CAAC;IAEM,KAAK,CACV,KAA+B,EAC/B,YAA8B,EAAE;QAGhC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YAChD,MAAM,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KA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AAG,KAAK,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAqB,GAAG,KAAyB;QAC5D,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,WAA0B;QACrC,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;YAC5B,gBAAgB,EAAE,WAAW;YAC7B,eAAe,EAAE,KAAK;YACtB,mBAAmB,EAAE,IAAI;YACzB,kBAAkB;YAClB,yBAAyB;YACzB,GAAG,WAAW;SACf,CAAC,CAAC;IACL,CAAC;IAED,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import type { ILexerConfig } from '@chevrotain/types';\nimport type { TokenType } from 'chevrotain';\nimport { Lexer } from 'chevrotain';\nimport type { CheckOverlap, NamedToken } from '../utils';\n\nexport class LexerBuilder<NAMES extends string = string> {\n private readonly tokens: TokenType[];\n\n public static create<U extends LexerBuilder<T>, T extends string = never>(starter?: U): U {\n return <U> new LexerBuilder(starter);\n }\n\n private constructor(starter?: LexerBuilder<NAMES>) {\n this.tokens = starter?.tokens ? [ ...starter.tokens ] : [];\n }\n\n public merge<OtherNames extends string, OW extends string>(\n merge: LexerBuilder<OtherNames>,\n overwrite: NamedToken<OW>[] = [],\n ):\n LexerBuilder<NAMES | OtherNames> {\n const extraTokens = merge.tokens.filter((token) => {\n const overwriteToken = overwrite.find(t => t.name === token.name);\n if (overwriteToken) {\n return false;\n }\n const match = this.tokens.find(t => t.name === token.name);\n if (match) {\n if (match !== token) {\n throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);\n }\n return false;\n }\n return true;\n });\n this.tokens.push(...extraTokens);\n return this;\n }\n\n public add<Name extends string>(...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>):\n LexerBuilder<Name | NAMES> {\n this.tokens.push(...token);\n return this;\n }\n\n public addBefore<Name extends string>(\n before: NamedToken<NAMES>,\n ...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>\n ): LexerBuilder<NAMES | Name> {\n const index = this.tokens.indexOf(before);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index, 0, ...token);\n return this;\n }\n\n private moveBeforeOrAfter<Name extends string>(\n beforeOrAfter: 'before' | 'after',\n before: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === 'before' ? 0 : 1);\n if (beforeIndex === -1) {\n throw new Error('BeforeToken not found');\n }\n for (const token of tokens) {\n const tokenIndex = this.tokens.indexOf(token);\n if (tokenIndex === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(tokenIndex, 1);\n this.tokens.splice(beforeIndex, 0, token);\n }\n return this;\n }\n\n /**\n * @param before token to move rest before\n * @param tokens tokens to move before the first token\n */\n public moveBefore<Name extends string>(\n before: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n return this.moveBeforeOrAfter('before', before, ...tokens);\n }\n\n public moveAfter<Name extends string>(\n after: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n return this.moveBeforeOrAfter('after', after, ...tokens);\n }\n\n public addAfter<Name extends string>(\n after: NamedToken<NAMES>,\n ...token: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES | Name> {\n const index = this.tokens.indexOf(after);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index + 1, 0, ...token);\n return this;\n }\n\n public delete<Name extends NAMES>(...token: NamedToken<Name>[]): LexerBuilder<Exclude<NAMES, Name>> {\n for (const t of token) {\n const index = this.tokens.indexOf(t);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index, 1);\n }\n return this;\n }\n\n public build(lexerConfig?: ILexerConfig): Lexer {\n return new Lexer(this.tokens, {\n positionTracking: 'onlyStart',\n recoveryEnabled: false,\n ensureOptimizations: true,\n // SafeMode: true,\n // SkipValidations: true,\n ...lexerConfig,\n });\n }\n\n public get tokenVocabulary(): readonly TokenType[] {\n return this.tokens;\n }\n}\n"]}
@@ -19,8 +19,8 @@ export type ParseRulesToObject<T extends readonly ParserRule[], Names extends st
19
19
  [K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K];
20
20
  }>) : never) : never) : ParseRuleMap<Names> & Agg;
21
21
  export type ParserFromRules<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> = {
22
- [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ? (input: string, context: Context, args: ARGS) => RET : never;
22
+ [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ? (input: string, context: Context, ...args: ARGS) => RET : never;
23
23
  };
24
24
  export type ParseMethodsFromRules<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> = {
25
- [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ? ParserMethod<[Context, ARGS], RET> : never;
25
+ [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ? ParserMethod<[Context, ...ARGS], RET> : never;
26
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"builderTypes.js","sourceRoot":"","sources":["builderTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ParserMethod } from 'chevrotain';\nimport type { ParserRule } from './ruleDefTypes';\n\n/**\n * Get union-type of names used in list of ruledefs.\n */\nexport type ParseNamesFromList<T extends readonly { name: string }[]> = T[number]['name'];\n\n/**\n * Convert a list of ruledefs to a record that maps each rule name to its definition.\n */\nexport type ParseRuleMap<RuleNames extends string> = {[Key in RuleNames]: ParserRule<any, Key> };\n\n/**\n * Convert a list of RuleDefs to a Record with the name of the RuleDef as the key, matching the RuleDefMap type.\n */\nexport type ParseRulesToObject<\n T extends readonly ParserRule[],\n Names extends string = ParseNamesFromList<T>,\n Agg extends Record<string, ParserRule> = Record<never, never>,\n> = T extends readonly [infer First, ...infer Rest] ? (\n First extends ParserRule ? (\n Rest extends readonly ParserRule[] ? (\n ParseRulesToObject<Rest, Names, {[K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K] }>\n ) : never\n ) : never\n) : ParseRuleMap<Names> & Agg;\n\nexport type ParserFromRules<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> = {\n [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ?\n (input: string, context: Context, args: ARGS) => RET : never\n};\n\nexport type ParseMethodsFromRules<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> = {\n [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ?\n ParserMethod<[Context, ARGS], RET> : never\n};\n"]}
1
+ {"version":3,"file":"builderTypes.js","sourceRoot":"","sources":["builderTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ParserMethod } from 'chevrotain';\nimport type { ParserRule } from './ruleDefTypes';\n\n/**\n * Get union-type of names used in list of ruledefs.\n */\nexport type ParseNamesFromList<T extends readonly { name: string }[]> = T[number]['name'];\n\n/**\n * Convert a list of ruledefs to a record that maps each rule name to its definition.\n */\nexport type ParseRuleMap<RuleNames extends string> = {[Key in RuleNames]: ParserRule<any, Key> };\n\n/**\n * Convert a list of RuleDefs to a Record with the name of the RuleDef as the key, matching the RuleDefMap type.\n */\nexport type ParseRulesToObject<\n T extends readonly ParserRule[],\n Names extends string = ParseNamesFromList<T>,\n Agg extends Record<string, ParserRule> = Record<never, never>,\n> = T extends readonly [infer First, ...infer Rest] ? (\n First extends ParserRule ? (\n Rest extends readonly ParserRule[] ? (\n ParseRulesToObject<Rest, Names, {[K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K] }>\n ) : never\n ) : never\n) : ParseRuleMap<Names> & Agg;\n\nexport type ParserFromRules<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> = {\n [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ?\n (input: string, context: Context, ...args: ARGS) => RET : never\n};\n\nexport type ParseMethodsFromRules<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> = {\n [K in Names]: RuleDefs[K] extends ParserRule<Context, K, infer RET, infer ARGS> ?\n ParserMethod<[Context, ...ARGS], RET> : never\n};\n"]}
@@ -1,5 +1,6 @@
1
1
  import { EmbeddedActionsParser } from 'chevrotain';
2
2
  export class DynamicParser extends EmbeddedActionsParser {
3
+ context;
3
4
  setContext(context) {
4
5
  this.context = context;
5
6
  }
@@ -7,7 +8,7 @@ export class DynamicParser extends EmbeddedActionsParser {
7
8
  super(tokenVocabulary, {
8
9
  // RecoveryEnabled: true,
9
10
  maxLookahead: 2,
10
- // SkipValidations: true,
11
+ skipValidations: true,
11
12
  ...config,
12
13
  });
13
14
  this.context = undefined;
@@ -23,7 +24,7 @@ export class DynamicParser extends EmbeddedActionsParser {
23
24
  this.performSelfAnalysis();
24
25
  }
25
26
  constructSelfRef() {
26
- const subRuleImpl = (chevrotainSubrule) => ((cstDef, arg) => chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] }));
27
+ const subRuleImpl = (chevrotainSubrule) => ((cstDef, ...arg) => chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, ...arg] }));
27
28
  return {
28
29
  CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),
29
30
  CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),