@traqula/core 0.0.23 → 0.0.24

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/dist/cjs/lib/AstCoreFactory.js +136 -149
  2. package/dist/cjs/lib/AstCoreFactory.js.map +1 -0
  3. package/dist/cjs/lib/generator-builder/builderTypes.js +2 -15
  4. package/dist/cjs/lib/generator-builder/builderTypes.js.map +1 -0
  5. package/dist/cjs/lib/generator-builder/dynamicGenerator.js +189 -200
  6. package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -0
  7. package/dist/cjs/lib/generator-builder/generatorBuilder.js +103 -117
  8. package/dist/cjs/lib/generator-builder/generatorBuilder.js.map +1 -0
  9. package/dist/cjs/lib/generator-builder/generatorTypes.js +2 -15
  10. package/dist/cjs/lib/generator-builder/generatorTypes.js.map +1 -0
  11. package/dist/cjs/lib/index.js +39 -57
  12. package/dist/cjs/lib/index.js.map +1 -0
  13. package/dist/cjs/lib/indirection-builder/IndirBuilder.js +63 -85
  14. package/dist/cjs/lib/indirection-builder/IndirBuilder.js.map +1 -0
  15. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js +28 -50
  16. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js.map +1 -0
  17. package/dist/cjs/lib/indirection-builder/helpers.js +11 -31
  18. package/dist/cjs/lib/indirection-builder/helpers.js.map +1 -0
  19. package/dist/cjs/lib/lexer-builder/LexerBuilder.js +92 -114
  20. package/dist/cjs/lib/lexer-builder/LexerBuilder.js.map +1 -0
  21. package/dist/cjs/lib/parser-builder/builderTypes.js +2 -15
  22. package/dist/cjs/lib/parser-builder/builderTypes.js.map +1 -0
  23. package/dist/cjs/lib/parser-builder/dynamicParser.js +115 -136
  24. package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -0
  25. package/dist/cjs/lib/parser-builder/parserBuilder.js +167 -169
  26. package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -0
  27. package/dist/cjs/lib/parser-builder/ruleDefTypes.js +2 -15
  28. package/dist/cjs/lib/parser-builder/ruleDefTypes.js.map +1 -0
  29. package/dist/cjs/lib/transformers/TransformerObject.js +196 -198
  30. package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -0
  31. package/dist/cjs/lib/transformers/TransformerSubTyped.js +120 -141
  32. package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -0
  33. package/dist/cjs/lib/transformers/TransformerTyped.js +99 -120
  34. package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -0
  35. package/dist/cjs/lib/types.js +2 -15
  36. package/dist/cjs/lib/types.js.map +1 -0
  37. package/dist/cjs/lib/utils.js +13 -34
  38. package/dist/cjs/lib/utils.js.map +1 -0
  39. package/package.json +9 -9
  40. package/dist/cjs/test/generatorBuilder/generatorBuilder.types.test.js +0 -30
  41. package/dist/cjs/test/grammar-builder/parserBuilder.types.test.js +0 -27
  42. package/dist/cjs/test/transformer.test.js +0 -82
  43. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.d.ts +0 -1
  44. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js +0 -38
  45. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js.map +0 -1
  46. package/dist/esm/test/grammar-builder/parserBuilder.types.test.d.ts +0 -1
  47. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js +0 -38
  48. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js.map +0 -1
  49. package/dist/esm/test/transformer.test.d.ts +0 -1
  50. package/dist/esm/test/transformer.test.js +0 -82
  51. package/dist/esm/test/transformer.test.js.map +0 -1
@@ -1,182 +1,180 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var parserBuilder_exports = {};
20
- __export(parserBuilder_exports, {
21
- ParserBuilder: () => ParserBuilder
22
- });
23
- module.exports = __toCommonJS(parserBuilder_exports);
24
- var import_LexerBuilder = require("../lexer-builder/LexerBuilder.js");
25
- var import_dynamicParser = require("./dynamicParser.js");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParserBuilder = void 0;
4
+ const LexerBuilder_js_1 = require("../lexer-builder/LexerBuilder.js");
5
+ const dynamicParser_js_1 = require("./dynamicParser.js");
6
+ /**
7
+ * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.
8
+ */
26
9
  function listToRuleDefMap(rules) {
27
- const newRules = {};
28
- for (const rule of rules) {
29
- newRules[rule.name] = rule;
30
- }
31
- return newRules;
10
+ const newRules = {};
11
+ for (const rule of rules) {
12
+ newRules[rule.name] = rule;
13
+ }
14
+ return newRules;
32
15
  }
16
+ /**
17
+ * The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework).
18
+ * Using the builder you can create a grammar + AST creator.
19
+ * At any point in time, a parser can be constructed from the added rules.
20
+ * Constructing a parser will cause a validation which will validate the correctness of the grammar.
21
+ */
22
+ // This code is wild so other code can be simple.
33
23
  class ParserBuilder {
34
- /**
35
- * Create a builder from some initial grammar rules or an existing builder.
36
- * If a builder is provided, a new copy will be created.
37
- */
38
- static create(start) {
39
- if (Array.isArray(start)) {
40
- return new ParserBuilder(listToRuleDefMap(start));
24
+ /**
25
+ * Create a builder from some initial grammar rules or an existing builder.
26
+ * If a builder is provided, a new copy will be created.
27
+ */
28
+ static create(start) {
29
+ if (Array.isArray(start)) {
30
+ return new ParserBuilder(listToRuleDefMap(start));
31
+ }
32
+ return new ParserBuilder({ ...start.rules });
33
+ }
34
+ rules;
35
+ constructor(startRules) {
36
+ this.rules = startRules;
37
+ }
38
+ widenContext() {
39
+ return this;
41
40
  }
42
- return new ParserBuilder({ ...start.rules });
43
- }
44
- rules;
45
- constructor(startRules) {
46
- this.rules = startRules;
47
- }
48
- widenContext() {
49
- return this;
50
- }
51
- typePatch() {
52
- return this;
53
- }
54
- /**
55
- * Change the implementation of an existing grammar rule.
56
- */
57
- patchRule(patch) {
58
- const self = this;
59
- self.rules[patch.name] = patch;
60
- return self;
61
- }
62
- /**
63
- * Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.
64
- */
65
- addRuleRedundant(rule) {
66
- const self = this;
67
- const rules = self.rules;
68
- if (rules[rule.name] !== void 0 && rules[rule.name] !== rule) {
69
- throw new Error(`Rule ${rule.name} already exists in the builder`);
41
+ typePatch() {
42
+ return this;
70
43
  }
71
- rules[rule.name] = rule;
72
- return self;
73
- }
74
- /**
75
- * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
76
- */
77
- addRule(rule) {
78
- return this.addRuleRedundant(rule);
79
- }
80
- addMany(...rules) {
81
- this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
82
- return this;
83
- }
84
- /**
85
- * Delete a grammar rule by its name.
86
- */
87
- deleteRule(ruleName) {
88
- delete this.rules[ruleName];
89
- return this;
90
- }
91
- getRule(ruleName) {
92
- return this.rules[ruleName];
93
- }
94
- /**
95
- * Merge this grammar builder with another.
96
- * It is best to merge the bigger grammar with the smaller one.
97
- * If the two builders both have a grammar rule with the same name,
98
- * no error will be thrown case they map to the same ruledef object.
99
- * If they map to a different object, an error will be thrown.
100
- * To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
101
- * this rule implementation will be used.
102
- */
103
- merge(builder, overridingRules) {
104
- const otherRules = { ...builder.rules };
105
- const myRules = this.rules;
106
- for (const rule of Object.values(myRules)) {
107
- if (otherRules[rule.name] === void 0) {
108
- otherRules[rule.name] = rule;
109
- } else {
110
- const existingRule = otherRules[rule.name];
111
- if (existingRule !== rule) {
112
- const override = overridingRules.find((x) => x.name === rule.name);
113
- if (override) {
114
- otherRules[rule.name] = override;
115
- } else {
116
- throw new Error(`Rule with name "${rule.name}" already exists in the builder, specify an override to resolve conflict`);
117
- }
44
+ /**
45
+ * Change the implementation of an existing grammar rule.
46
+ */
47
+ patchRule(patch) {
48
+ const self = this;
49
+ self.rules[patch.name] = patch;
50
+ return self;
51
+ }
52
+ /**
53
+ * Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.
54
+ */
55
+ addRuleRedundant(rule) {
56
+ const self = this;
57
+ const rules = self.rules;
58
+ if (rules[rule.name] !== undefined && rules[rule.name] !== rule) {
59
+ throw new Error(`Rule ${rule.name} already exists in the builder`);
118
60
  }
119
- }
61
+ rules[rule.name] = rule;
62
+ return self;
63
+ }
64
+ /**
65
+ * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
66
+ */
67
+ addRule(rule) {
68
+ return this.addRuleRedundant(rule);
69
+ }
70
+ addMany(...rules) {
71
+ this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
72
+ return this;
120
73
  }
121
- this.rules = otherRules;
122
- return this;
123
- }
124
- defaultErrorHandler(input, errors) {
125
- const firstError = errors[0];
126
- const messageBuilder = ["Parse error"];
127
- const lineIdx = firstError.token.startLine;
128
- if (lineIdx !== void 0 && !Number.isNaN(lineIdx)) {
129
- const errorLine = input.split("\n")[lineIdx - 1];
130
- messageBuilder.push(` on line ${lineIdx}
74
+ /**
75
+ * Delete a grammar rule by its name.
76
+ */
77
+ deleteRule(ruleName) {
78
+ delete this.rules[ruleName];
79
+ return this;
80
+ }
81
+ getRule(ruleName) {
82
+ return this.rules[ruleName];
83
+ }
84
+ /**
85
+ * Merge this grammar builder with another.
86
+ * It is best to merge the bigger grammar with the smaller one.
87
+ * If the two builders both have a grammar rule with the same name,
88
+ * no error will be thrown case they map to the same ruledef object.
89
+ * If they map to a different object, an error will be thrown.
90
+ * To fix this problem, the overridingRules array should contain a rule with the same conflicting name,
91
+ * this rule implementation will be used.
92
+ */
93
+ merge(builder, overridingRules) {
94
+ // Assume the other grammar is bigger than yours. So start from that one and add this one
95
+ const otherRules = { ...builder.rules };
96
+ const myRules = this.rules;
97
+ for (const rule of Object.values(myRules)) {
98
+ if (otherRules[rule.name] === undefined) {
99
+ otherRules[rule.name] = rule;
100
+ }
101
+ else {
102
+ const existingRule = otherRules[rule.name];
103
+ // If same rule, no issue, move on. Else
104
+ if (existingRule !== rule) {
105
+ const override = overridingRules.find(x => x.name === rule.name);
106
+ // If override specified, take override, else, inform user that there is a conflict
107
+ if (override) {
108
+ otherRules[rule.name] = override;
109
+ }
110
+ else {
111
+ throw new Error(`Rule with name "${rule.name}" already exists in the builder, specify an override to resolve conflict`);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ this.rules = otherRules;
117
+ return this;
118
+ }
119
+ defaultErrorHandler(input, errors) {
120
+ const firstError = errors[0];
121
+ const messageBuilder = ['Parse error'];
122
+ const lineIdx = firstError.token.startLine;
123
+ if (lineIdx !== undefined && !Number.isNaN(lineIdx)) {
124
+ const errorLine = input.split('\n')[lineIdx - 1];
125
+ messageBuilder.push(` on line ${lineIdx}
131
126
  ${errorLine}`);
132
- const columnIdx = firstError.token.startColumn;
133
- if (columnIdx !== void 0) {
134
- messageBuilder.push(`
135
- ${"-".repeat(columnIdx - 1)}^`);
136
- }
127
+ const columnIdx = firstError.token.startColumn;
128
+ if (columnIdx !== undefined) {
129
+ messageBuilder.push(`\n${'-'.repeat(columnIdx - 1)}^`);
130
+ }
131
+ }
132
+ messageBuilder.push(`\n${firstError.message}`);
133
+ throw new Error(messageBuilder.join(''));
137
134
  }
138
- messageBuilder.push(`
139
- ${firstError.message}`);
140
- throw new Error(messageBuilder.join(""));
141
- }
142
- build({ tokenVocabulary, parserConfig = {}, lexerConfig = {}, queryPreProcessor = (s) => s, errorHandler }) {
143
- const lexer = import_LexerBuilder.LexerBuilder.create().add(...tokenVocabulary).build({
144
- positionTracking: "full",
145
- recoveryEnabled: false,
146
- ensureOptimizations: true,
147
- safeMode: false,
148
- skipValidations: true,
149
- ...lexerConfig
150
- });
151
- const parser = this.consume({
152
- tokenVocabulary,
153
- config: parserConfig
154
- });
155
- const selfSufficientParser = {};
156
- for (const rule of Object.values(this.rules)) {
157
- selfSufficientParser[rule.name] = ((input, context, ...args) => {
158
- const processedInput = queryPreProcessor(input);
159
- const lexResult = lexer.tokenize(processedInput);
160
- parser.input = lexResult.tokens;
161
- parser.setContext(context);
162
- const result = parser[rule.name](context, ...args);
163
- if (parser.errors.length > 0) {
164
- if (errorHandler) {
165
- errorHandler(parser.errors);
166
- } else {
167
- this.defaultErrorHandler(processedInput, parser.errors);
168
- }
135
+ build({ tokenVocabulary, parserConfig = {}, lexerConfig = {}, queryPreProcessor = s => s, errorHandler, }) {
136
+ const lexer = LexerBuilder_js_1.LexerBuilder.create().add(...tokenVocabulary).build({
137
+ positionTracking: 'full',
138
+ recoveryEnabled: false,
139
+ ensureOptimizations: true,
140
+ safeMode: false,
141
+ skipValidations: true,
142
+ ...lexerConfig,
143
+ });
144
+ // Get the chevrotain parser
145
+ const parser = this.consume({
146
+ tokenVocabulary: tokenVocabulary,
147
+ config: parserConfig,
148
+ });
149
+ // Start building a parser that does not pass input using a state, but instead gets it as a function argument.
150
+ const selfSufficientParser = {};
151
+ // To do that, we need to create a wrapper for each parser rule.
152
+ // eslint-disable-next-line ts/no-unnecessary-type-assertion
153
+ for (const rule of Object.values(this.rules)) {
154
+ selfSufficientParser[rule.name] = ((input, context, ...args) => {
155
+ const processedInput = queryPreProcessor(input);
156
+ const lexResult = lexer.tokenize(processedInput);
157
+ // This also resets the parser
158
+ parser.input = lexResult.tokens;
159
+ parser.setContext(context);
160
+ const result = parser[rule.name](context, ...args);
161
+ if (parser.errors.length > 0) {
162
+ // Console.log(lexResult);
163
+ if (errorHandler) {
164
+ errorHandler(parser.errors);
165
+ }
166
+ else {
167
+ this.defaultErrorHandler(processedInput, parser.errors);
168
+ }
169
+ }
170
+ return result;
171
+ });
169
172
  }
170
- return result;
171
- });
173
+ return selfSufficientParser;
174
+ }
175
+ consume({ tokenVocabulary, config = {} }) {
176
+ return new dynamicParser_js_1.DynamicParser(this.rules, tokenVocabulary, config);
172
177
  }
173
- return selfSufficientParser;
174
- }
175
- consume({ tokenVocabulary, config = {} }) {
176
- return new import_dynamicParser.DynamicParser(this.rules, tokenVocabulary, config);
177
- }
178
178
  }
179
- // Annotate the CommonJS export names for ESM import in node:
180
- 0 && (module.exports = {
181
- ParserBuilder
182
- });
179
+ exports.ParserBuilder = ParserBuilder;
180
+ //# sourceMappingURL=parserBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parserBuilder.js","sourceRoot":"","sources":["../../../../lib/parser-builder/parserBuilder.ts"],"names":[],"mappings":";;;AAQA,sEAAgE;AAShE,yDAAmD;AAGnD;;GAEG;AACH,SAAS,gBAAgB,CAAkC,KAAQ;IACjE,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,OAA8B,QAAQ,CAAC;AACzC,CAAC;AAUD;;;;;GAKG;AACH,iDAAiD;AACjD,MAAa,aAAa;IACxB;;;OAGG;IACI,MAAM,CAAC,MAAM,CAMlB,KAAsD;QAEtD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAA2D,IAAI,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,IAAI,aAAa,CAAC,EAAE,GAAkC,KAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC/E,CA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C,CAAC;IAChH,CAAC;CACF;AAhQD,sCAgQC","sourcesContent":["import type {\n ILexerConfig,\n IParserConfig,\n IRecognitionException,\n TokenType,\n TokenVocabulary,\n EmbeddedActionsParser,\n} from '@traqula/chevrotain';\nimport { LexerBuilder } from '../lexer-builder/LexerBuilder.js';\nimport type { CheckOverlap } from '../utils.js';\nimport type {\n ParseMethodsFromRules,\n ParserFromRules,\n ParseRuleMap,\n ParseRulesToObject,\n ParseNamesFromList,\n} from './builderTypes.js';\nimport { DynamicParser } from './dynamicParser.js';\nimport type { ParserRule } from './ruleDefTypes.js';\n\n/**\n * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.\n */\nfunction listToRuleDefMap<T extends readonly ParserRule[]>(rules: T): ParseRulesToObject<T> {\n const newRules: Record<string, ParserRule> = {};\n for (const rule of rules) {\n newRules[rule.name] = rule;\n }\n return <ParseRulesToObject<T>>newRules;\n}\n\nexport interface ParserBuildArgs {\n tokenVocabulary: readonly TokenType[];\n parserConfig?: IParserConfig;\n lexerConfig?: ILexerConfig;\n queryPreProcessor?: (input: string) => string;\n errorHandler?: (errors: IRecognitionException[]) => void;\n}\n\n/**\n * The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework).\n * Using the builder you can create a grammar + AST creator.\n * At any point in time, a parser can be constructed from the added rules.\n * Constructing a parser will cause a validation which will validate the correctness of the grammar.\n */\n// This code is wild so other code can be simple.\nexport class ParserBuilder<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> {\n /**\n * Create a builder from some initial grammar rules or an existing builder.\n * If a builder is provided, a new copy will be created.\n */\n public static create<\n Rules extends readonly ParserRule[] = readonly ParserRule[],\n Context = Rules[0] extends ParserRule<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends ParseRuleMap<Names> = ParseRulesToObject<Rules>,\n >(\n start: Rules | ParserBuilder<Context, Names, RuleDefs>,\n ): ParserBuilder<Context, Names, RuleDefs> {\n if (Array.isArray(start)) {\n return <ParserBuilder<Context, Names, RuleDefs>> <unknown> new ParserBuilder(listToRuleDefMap(start));\n }\n return new ParserBuilder({ ...(<ParserBuilder<any, any, any>>start).rules });\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n public widenContext<NewContext extends Context>(): ParserBuilder<\n NewContext,\nNames,\n{[Key in keyof RuleDefs]: Key extends Names ?\n (RuleDefs[Key] extends ParserRule<any, any, infer RT, infer PT> ? ParserRule<NewContext, Key, RT, PT> : never)\n : never }\n> {\n return <any> this;\n }\n\n public typePatch<Patch extends {[Key in Names]?: [any] | [any, any[]]}>():\n ParserBuilder<Context, Names, {[Key in Names]: Key extends keyof Patch ? (\n Patch[Key] extends [any, any[]] ? ParserRule<Context, Key, Patch[Key][0], Patch[Key][1]> : (\n // Only one - infer yourself\n Patch[Key] extends [any] ? (\n RuleDefs[Key] extends ParserRule<any, any, any, infer Par> ?\n ParserRule<Context, Key, Patch[Key][0], Par> : never\n ) : never\n )\n ) : (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never) }> {\n return <any> this;\n }\n\n /**\n * Change the implementation of an existing grammar rule.\n */\n public patchRule<U extends Names, RET, ARGS extends any[]>(patch: ParserRule<Context, U, RET, ARGS>):\n ParserBuilder<Context, Names, {[Key in Names]: Key extends U ?\n ParserRule<Context, Key, RET, ARGS> :\n (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never)\n } > {\n const self = <ParserBuilder<Context, Names, {[Key in Names]: Key extends U ?\n ParserRule<Context, Key, RET, ARGS> : (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never) }>>\n <unknown> this;\n self.rules[patch.name] = <any> patch;\n return self;\n }\n\n /**\n * Add a rule to the grammar. 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: ParserRule<Context, U, RET, ARGS>):\n ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never)\n }> {\n const self = <ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never) }>>\n <unknown> this;\n const rules = <Record<string, ParserRule<Context>>> self.rules;\n if (rules[rule.name] !== undefined && rules[rule.name] !== rule) {\n throw new Error(`Rule ${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, ParserRule<Context, U, RET, ARGS>>,\n ): ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends readonly ParserRule<Context>[]>(\n ...rules: CheckOverlap<ParseNamesFromList<U>, Names, U>\n ): ParserBuilder<\n Context,\n Names | ParseNamesFromList<U>,\n {[K in Names | ParseNamesFromList<U>]:\n K extends keyof ParseRulesToObject<typeof rules> ? (\n ParseRulesToObject<typeof rules>[K] extends ParserRule<Context, K> ? ParseRulesToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never\n )\n }\n > {\n this.rules = { ...this.rules, ...listToRuleDefMap(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 ParserBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <ParserBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never }>>\n <unknown> this;\n }\n\n public getRule<U extends Names>(ruleName: U): RuleDefs[U] extends ParserRule<any, U, infer RT, infer PT> ?\n ParserRule<Context, U, RT, PT> : never {\n return <any> this.rules[ruleName];\n }\n\n /**\n * Merge this grammar builder with another.\n * It is best to merge the bigger grammar with the smaller one.\n * If the two builders both have a grammar rule with the same name,\n * no error will be thrown case they map to the same ruledef object.\n * If they map to a different object, an error will be thrown.\n * To fix this problem, the overridingRules array should contain a rule with the same conflicting name,\n * this rule implementation will be used.\n */\n public merge<\n OtherNames extends string,\n OtherRules extends ParseRuleMap<OtherNames>,\n OW extends readonly ParserRule<Context>[],\n >(\n builder: ParserBuilder<Context, OtherNames, OtherRules>,\n overridingRules: OW,\n ):\n ParserBuilder<\n Context,\n Names | OtherNames | ParseNamesFromList<OW>,\n {[K in Names | OtherNames | ParseNamesFromList<OW>]:\n K extends keyof ParseRulesToObject<OW> ? (\n ParseRulesToObject<OW>[K] extends ParserRule<Context, K> ? ParseRulesToObject<OW>[K] : never\n )\n : (\n K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never)\n : K extends OtherNames ? (OtherRules[K] extends ParserRule<Context, K> ? OtherRules[K] : never) : never\n ) }\n > {\n // Assume the other grammar is bigger than yours. So start from that one and add this one\n const otherRules: Record<string, ParserRule<Context>> = { ...builder.rules };\n const myRules: Record<string, ParserRule<Context>> = this.rules;\n\n for (const rule of Object.values(myRules)) {\n if (otherRules[rule.name] === undefined) {\n otherRules[rule.name] = rule;\n } else {\n const existingRule = otherRules[rule.name];\n // If same rule, no issue, move on. Else\n if (existingRule !== rule) {\n const override = overridingRules.find(x => x.name === rule.name);\n // If override specified, take override, else, inform user that there is a conflict\n if (override) {\n otherRules[rule.name] = override;\n } else {\n throw new Error(`Rule with name \"${rule.name}\" already exists in the builder, specify an override to resolve conflict`);\n }\n }\n }\n }\n\n this.rules = <any> <unknown> otherRules;\n return <any> <unknown> this;\n }\n\n private defaultErrorHandler(input: string, errors: IRecognitionException[]): void {\n const firstError = errors[0];\n const messageBuilder: string[] = [ 'Parse error' ];\n const lineIdx = firstError.token.startLine;\n if (lineIdx !== undefined && !Number.isNaN(lineIdx)) {\n const errorLine = input.split('\\n')[lineIdx - 1];\n messageBuilder.push(` on line ${lineIdx}\n${errorLine}`);\n const columnIdx = firstError.token.startColumn;\n if (columnIdx !== undefined) {\n messageBuilder.push(`\\n${'-'.repeat(columnIdx - 1)}^`);\n }\n }\n messageBuilder.push(`\\n${firstError.message}`);\n throw new Error(messageBuilder.join(''));\n }\n\n public build({\n tokenVocabulary,\n parserConfig = {},\n lexerConfig = {},\n queryPreProcessor = s => s,\n errorHandler,\n }: ParserBuildArgs): ParserFromRules<Context, Names, RuleDefs> {\n const lexer = LexerBuilder.create().add(...tokenVocabulary).build({\n positionTracking: 'full',\n recoveryEnabled: false,\n ensureOptimizations: true,\n safeMode: false,\n skipValidations: true,\n ...lexerConfig,\n });\n // Get the chevrotain parser\n const parser = this.consume({\n tokenVocabulary: <TokenType[]> tokenVocabulary,\n config: parserConfig,\n });\n // Start building a parser that does not pass input using a state, but instead gets it as a function argument.\n const selfSufficientParser: Partial<ParserFromRules<Context, Names, RuleDefs>> = {};\n\n // To do that, we need to create a wrapper for each parser rule.\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n for (const rule of <ParserRule<Context, Names>[]> Object.values(this.rules)) {\n selfSufficientParser[rule.name] = <any> ((input: string, context: Context, ...args: unknown[]) => {\n const processedInput = queryPreProcessor(input);\n const lexResult = lexer.tokenize(processedInput);\n\n // This also resets the parser\n parser.input = lexResult.tokens;\n parser.setContext(context);\n const result = parser[rule.name](context, ...args);\n if (parser.errors.length > 0) {\n // Console.log(lexResult);\n if (errorHandler) {\n errorHandler(parser.errors);\n } else {\n this.defaultErrorHandler(processedInput, parser.errors);\n }\n }\n return result;\n });\n }\n return <ParserFromRules<Context, Names, RuleDefs>> selfSufficientParser;\n }\n\n private consume({ tokenVocabulary, config = {}}: {\n tokenVocabulary: TokenVocabulary;\n config?: IParserConfig;\n }): EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> &\n { setContext: (context: Context) => void } {\n return <EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> &\n { setContext: (context: Context) => void }><unknown> new DynamicParser(this.rules, tokenVocabulary, config);\n }\n}\n"]}
@@ -1,16 +1,3 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var ruleDefTypes_exports = {};
16
- module.exports = __toCommonJS(ruleDefTypes_exports);
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ruleDefTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["../../../../lib/parser-builder/ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n ConsumeMethodOpts,\n IToken,\n TokenType,\n} from '@traqula/chevrotain';\n\n/**\n * Get the return-type of a RuleDef\n */\nexport type RuleDefReturn<T extends ParserRule> = T extends ParserRule<any, string, infer Ret> ? Ret : never;\n\n/**\n * Type used to declare grammar rules.\n */\nexport type ParserRule<\n /**\n * Context object available in rule implementation.\n */\n Context = any,\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType extends any[] = any[],\n> = {\n name: NameType;\n impl: (def: ImplArgs) => (context: Context, ...params: ParamType) => ReturnType;\n};\n\n/**\n * Type expected by grammar rules in the main `impl` function.\n */\nexport interface ImplArgs extends CstDef {\n cache: WeakMap<ParserRule, unknown>;\n}\n\n/**\n * Type definition used by {@link CstDef.SUBRULE} and family.\n */\ntype SubRuleFunc = <T extends string, U = unknown, ARGS extends any[] = any>(\n cstDef: ParserRule<any, T, U, ARGS>,\n ...argument: ARGS\n) => U;\n/**\n * Type definition used by {@link CstDef.BACKTRACK}.\n */\ntype BacktrackFunc = <T extends string, U = unknown, ARGS extends any[] = any>(\n cstDef: ParserRule<any, T, U, ARGS>,\n ...argument: ARGS\n) => () => boolean;\n\n/**\n * Mainly a repetition of the functions exposed by the {@link EmbeddedActionsParser},\n * with some small adjustments that allow for the API changes made by traqula.\n * Specifically changes are made to the {@link CstDef.SUBRULE} (and family) interface,\n * and to the {@link CstDef.BACKTRACK} interface.\n */\nexport interface CstDef {\n /**\n *\n * A Parsing DSL method use to consume a single Token.\n * In EBNF terms this is equivalent to a Terminal.\n *\n * A Token will be consumed, IFF the next token in the token vector matches `tokType`.\n * otherwise the parser may attempt to perform error recovery (if enabled).\n *\n * The index in the method name indicates the unique occurrence of a terminal consumption\n * inside a the top level rule. What this means is that if a terminal appears\n * more than once in a single rule, each appearance must have a **different** index.\n *\n * For example:\n * ```\n * this.RULE(\"qualifiedName\", () => {\n * this.CONSUME1(Identifier);\n * this.MANY(() => {\n * this.CONSUME1(Dot);\n * // here we use CONSUME2 because the terminal\n * // 'Identifier' has already appeared previously in the\n * // the rule 'parseQualifiedName'\n * this.CONSUME2(Identifier);\n * });\n * })\n * ```\n *\n * - See more details on the [unique suffixes requirement](http://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES).\n *\n * @param tokType - The Type of the token to be consumed.\n * @param options - optional properties to modify the behavior of CONSUME.\n */\n CONSUME: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME1: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME2: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME3: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME4: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME5: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME6: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME7: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME8: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME9: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n /**\n * Parsing DSL Method that Indicates an Optional production.\n * in EBNF notation this is equivalent to: \"[...]\".\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.OPTION(() => {\n * this.CONSUME(Digit)}\n * );\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.OPTION({\n * GATE:predicateFunc,\n * DEF: () => {\n * this.CONSUME(Digit)\n * }});\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the optional production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke once\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n * @returns The `GrammarAction` return value (OUT) if the optional syntax is encountered\n * or `undefined` if not.\n */\n OPTION: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION1: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION2: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION3: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION4: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION5: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION6: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION7: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION8: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION9: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n /**\n * Parsing DSL method that indicates a choice between a set of alternatives must be made.\n * This is equivalent to an EBNF alternation (A | B | C | D ...), except\n * that the alternatives are ordered like in a PEG grammar.\n * This means that the **first** matching alternative is always chosen.\n *\n * There are several forms for the inner alternatives array:\n *\n * - Passing alternatives array directly:\n * ```\n * this.OR([\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Passing alternative array directly with predicates (GATE):\n * ```\n * this.OR([\n * { GATE: predicateFunc1, ALT:() => { this.CONSUME(One) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Two) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - These syntax forms can also be mixed:\n * ```\n * this.OR([\n * {\n * GATE: predicateFunc1,\n * ALT:() => { this.CONSUME(One) }\n * },\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Additionally an \"options\" object may be used:\n * ```\n * this.OR({\n * DEF:[\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ],\n * // OPTIONAL property\n * ERR_MSG: \"A Number\"\n * })\n * ```\n *\n * The 'predicateFuncX' in the long form can be used to add constraints to choosing the alternative.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the alternation production in it's top rule.\n *\n * @param altsOrOpts - A set of alternatives or an \"OPTIONS\" object describing the alternatives\n * and optional properties.\n *\n * @returns The result of invoking the chosen alternative.\n */\n OR: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR1: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR2: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR3: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR4: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR5: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR6: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR7: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR8: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR9: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more.\n * This is equivalent to EBNF repetition \\{...\\}.\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.MANY(() => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * })\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.MANY({\n * GATE: predicateFunc,\n * DEF: () => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * }\n * });\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n MANY: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more with a separator\n * Token between the repetitions.\n *\n * Example:\n *\n * ```\n * this.MANY_SEP({\n * SEP:Comma,\n * DEF: () => {\n * this.CONSUME(Number};\n * // ...\n * })\n * ```\n *\n * Note that because this DSL method always requires more than one argument the options object is always required\n * and it is not possible to use a shorter form like in the MANY DSL method.\n *\n * Note that for the purposes of deciding on whether or not another iteration exists\n * Only a single Token is examined (The separator). Therefore if the grammar being implemented is\n * so \"crazy\" to require multiple tokens to identify an item separator please use the more basic DSL methods\n * to implement it.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n */\n MANY_SEP: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP1: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP2: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP3: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP4: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP5: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP6: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP7: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP8: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP9: (options: ManySepMethodOpts<any>) => void;\n /**\n * Convenience method, same as MANY but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause a parsing error.\n *\n * @see MANY\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n AT_LEAST_ONE: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n /**\n * Convenience method, same as MANY_SEP but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause the parser to attempt error recovery.\n *\n * Note that an additional optional property ERR_MSG can be used to provide custom error messages.\n *\n * @see MANY_SEP\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n * @return ISeparatedIterationResult<OUT>\n */\n AT_LEAST_ONE_SEP: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP1: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP2: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP3: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP4: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP5: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP6: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP7: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP8: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP9: (options: AtLeastOneSepMethodOpts<any>) => void;\n /**\n * Perform an action that is only executed during actual parsing and not during parser initialization.\n * (When a lot of this secretly return null)\n * @param impl\n * @constructor\n */\n ACTION: <T>(impl: () => T) => T;\n BACKTRACK: BacktrackFunc;\n SUBRULE: SubRuleFunc;\n SUBRULE1: SubRuleFunc;\n SUBRULE2: SubRuleFunc;\n SUBRULE3: SubRuleFunc;\n SUBRULE4: SubRuleFunc;\n SUBRULE5: SubRuleFunc;\n SUBRULE6: SubRuleFunc;\n SUBRULE7: SubRuleFunc;\n SUBRULE8: SubRuleFunc;\n SUBRULE9: SubRuleFunc;\n}\n"]}