@traqula/core 0.0.1-alpha.145 → 0.0.1-alpha.148

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.
@@ -1,9 +1,18 @@
1
1
  import type { ParserMethod } from 'chevrotain';
2
2
  import type { RuleDef } from './ruleDefTypes';
3
+ /**
4
+ * Get union-type of names used in list of ruledefs.
5
+ */
3
6
  export type RuleNamesFromList<T extends readonly RuleDef[]> = T[number]['name'];
7
+ /**
8
+ * Convert a list of ruledefs to a record that maps each rule name to its definition.
9
+ */
4
10
  export type RuleDefMap<RuleNames extends string> = {
5
- [Key in RuleNames]: RuleDef<Key>;
11
+ [Key in RuleNames]: RuleDef<any, Key>;
6
12
  };
13
+ /**
14
+ * Check whether the first two types overlap, if yes, return the 3th argument, else the 4th.
15
+ */
7
16
  export type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;
8
17
  /**
9
18
  * Convert a list of RuleDefs to a Record with the name of the RuleDef as the key, matching the RuleDefMap type.
@@ -11,9 +20,9 @@ export type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;
11
20
  export type RuleListToObject<T extends readonly RuleDef[], Names extends string = RuleNamesFromList<T>, Agg extends Record<string, RuleDef> = Record<never, never>> = T extends readonly [infer First, ...infer Rest] ? (First extends RuleDef ? (Rest extends readonly RuleDef[] ? (RuleListToObject<Rest, Names, {
12
21
  [K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K];
13
22
  }>) : never) : never) : RuleDefMap<Names> & Agg;
14
- export type ParserFromRules<Names extends string, RuleDefs extends RuleDefMap<Names>> = {
15
- [K in Names]: RuleDefs[K] extends RuleDef<K, infer RET, infer ARGS> ? (...args: ARGS) => RET : never;
23
+ export type ParserFromRules<Context, Names extends string, RuleDefs extends RuleDefMap<Names>> = {
24
+ [K in Names]: RuleDefs[K] extends RuleDef<Context, K, infer RET, infer ARGS> ? (input: string, context: Context, args: ARGS) => RET : never;
16
25
  };
17
- export type ParseMethodsFromRules<Names extends string, RuleDefs extends RuleDefMap<Names>> = {
18
- [K in Names]: RuleDefs[K] extends RuleDef<K, infer RET, infer ARGS> ? ParserMethod<ARGS, RET> : never;
26
+ export type ParseMethodsFromRules<Context, Names extends string, RuleDefs extends RuleDefMap<Names>> = {
27
+ [K in Names]: RuleDefs[K] extends RuleDef<Context, K, infer RET, infer ARGS> ? ParserMethod<[Context, ARGS], RET> : never;
19
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"builderTypes.js","sourceRoot":"","sources":["builderTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ParserMethod } from 'chevrotain';\nimport type { RuleDef } from './ruleDefTypes';\n\nexport type RuleNamesFromList<T extends readonly RuleDef[]> = T[number]['name'];\n\nexport type RuleDefMap<RuleNames extends string> = {[Key in RuleNames]: RuleDef<Key> };\n\nexport type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;\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 RuleListToObject<\n T extends readonly RuleDef[],\n Names extends string = RuleNamesFromList<T>,\n Agg extends Record<string, RuleDef> = Record<never, never>,\n> = T extends readonly [infer First, ...infer Rest] ? (\n First extends RuleDef ? (\n Rest extends readonly RuleDef[] ? (\n RuleListToObject<Rest, Names, {[K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K] }>\n ) : never\n ) : never\n) : RuleDefMap<Names> & Agg;\n\nexport type ParserFromRules<Names extends string, RuleDefs extends RuleDefMap<Names>> = {\n [K in Names]: RuleDefs[K] extends RuleDef<K, infer RET, infer ARGS> ? (...args: ARGS) => RET : never\n};\n\nexport type ParseMethodsFromRules<Names extends string, RuleDefs extends RuleDefMap<Names>> = {\n [K in Names]: RuleDefs[K] extends RuleDef<K, infer RET, infer ARGS> ? ParserMethod<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 {RuleDef} from './ruleDefTypes';\n\n/**\n * Get union-type of names used in list of ruledefs.\n */\nexport type RuleNamesFromList<T extends readonly RuleDef[]> = 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 RuleDefMap<RuleNames extends string> = {[Key in RuleNames]: RuleDef<any, Key> };\n\n/**\n * Check whether the first two types overlap, if yes, return the 3th argument, else the 4th.\n */\nexport type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;\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 RuleListToObject<\n T extends readonly RuleDef[],\n Names extends string = RuleNamesFromList<T>,\n Agg extends Record<string, RuleDef> = Record<never, never>,\n> = T extends readonly [infer First, ...infer Rest] ? (\n First extends RuleDef ? (\n Rest extends readonly RuleDef[] ? (\n RuleListToObject<Rest, Names, {[K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K] }>\n ) : never\n ) : never\n) : RuleDefMap<Names> & Agg;\n\nexport type ParserFromRules<Context, Names extends string, RuleDefs extends RuleDefMap<Names>> = {\n [K in Names]: RuleDefs[K] extends RuleDef<Context, K, infer RET, infer ARGS> ? (input: string, context: Context, args: ARGS) => RET : never\n};\n\nexport type ParseMethodsFromRules<Context, Names extends string, RuleDefs extends RuleDefMap<Names>> = {\n [K in Names]: RuleDefs[K] extends RuleDef<Context, K, infer RET, infer ARGS> ? ParserMethod<[Context, ARGS], RET> : never\n};\n"]}
@@ -1,50 +1,68 @@
1
- import type { ILexerConfig, IParserConfig } from '@chevrotain/types';
1
+ import { ILexerConfig, IParserConfig } from '@chevrotain/types';
2
2
  import type { TokenType, TokenVocabulary } from 'chevrotain';
3
3
  import { EmbeddedActionsParser } from 'chevrotain';
4
- import type { CheckOverlap, RuleDefMap, ParserFromRules, RuleListToObject, RuleNamesFromList, ParseMethodsFromRules } from './builderTypes';
5
- import type { ImplArgs, RuleDef } from './ruleDefTypes';
6
- export declare class Builder<Names extends string, RuleDefs extends RuleDefMap<Names>> {
4
+ import type { CheckOverlap, ParseMethodsFromRules, ParserFromRules, RuleDefMap, RuleListToObject, RuleNamesFromList } from './builderTypes';
5
+ import type { RuleDef } from './ruleDefTypes';
6
+ /**
7
+ * The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework).
8
+ * Using the builder you can create a grammar + AST creator.
9
+ * At any point in time, a parser can be constructed from the added rules.
10
+ * Constructing a parser will cause a validation which will validate the correctness of the grammar.
11
+ */
12
+ export declare class Builder<Context, Names extends string, RuleDefs extends RuleDefMap<Names>> {
7
13
  /**
8
- * Create a builder with from some initial grammar rules or an existing builder.
14
+ * Create a builder from some initial grammar rules or an existing builder.
9
15
  * If a builder is provided, a new copy will be created.
10
16
  */
11
- static createBuilder<Rules extends readonly RuleDef[] = RuleDef[], Names extends string = RuleNamesFromList<Rules>, RuleDefs extends RuleDefMap<Names> = RuleListToObject<Rules>>(start: Rules | Builder<Names, RuleDefs>): Builder<Names, RuleDefs>;
17
+ static createBuilder<Rules extends readonly RuleDef[] = readonly RuleDef[], Context = Rules[0] extends RuleDef<infer context> ? context : never, Names extends string = RuleNamesFromList<Rules>, RuleDefs extends RuleDefMap<Names> = RuleListToObject<Rules>>(start: Rules | Builder<Context, Names, RuleDefs>): Builder<Context, Names, RuleDefs>;
12
18
  private rules;
13
19
  private constructor();
14
20
  /**
15
21
  * Change the implementation of an existing grammar rule.
16
22
  */
17
- patchRule<U extends Names, RET, ARGS extends unknown[]>(patch: RuleDef<U, RET, ARGS>): Builder<Names, {
18
- [Key in Names]: Key extends U ? RuleDef<Key, RET, ARGS> : (RuleDefs[Key] extends RuleDef<Key> ? RuleDefs[Key] : never);
23
+ patchRule<U extends Names, RET, ARGS>(patch: RuleDef<Context, U, RET, ARGS>): Builder<Context, Names, {
24
+ [Key in Names]: Key extends U ? RuleDef<Context, Key, RET, ARGS> : (RuleDefs[Key] extends RuleDef<Context, Key> ? RuleDefs[Key] : never);
19
25
  }>;
20
26
  /**
21
27
  * Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.
22
28
  */
23
- addRuleRedundant<U extends string, RET, ARGS extends unknown[]>(rule: RuleDef<U, RET, ARGS>): Builder<Names | U, {
24
- [K in Names | U]: K extends U ? RuleDef<K, RET, ARGS> : (K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never) : never);
29
+ addRuleRedundant<U extends string, RET, ARGS>(rule: RuleDef<Context, U, RET, ARGS>): Builder<Context, Names | U, {
30
+ [K in Names | U]: K extends U ? RuleDef<Context, K, RET, ARGS> : (K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never) : never);
25
31
  }>;
26
32
  /**
27
33
  * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
28
34
  */
29
- addRule<U extends string, RET, ARGS extends unknown[]>(rule: CheckOverlap<U, Names, RuleDef<U, RET, ARGS>>): Builder<Names | U, {
30
- [K in Names | U]: K extends U ? RuleDef<K, RET, ARGS> : (K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never) : never);
35
+ addRule<U extends string, RET, ARGS>(rule: CheckOverlap<U, Names, RuleDef<Context, U, RET, ARGS>>): Builder<Context, Names | U, {
36
+ [K in Names | U]: K extends U ? RuleDef<Context, K, RET, ARGS> : (K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never) : never);
31
37
  }>;
32
- addMany<U extends RuleDef[]>(...rules: CheckOverlap<RuleNamesFromList<U>, Names, U>): Builder<Names | RuleNamesFromList<U>, {
33
- [K in Names | RuleNamesFromList<U>]: K extends keyof RuleListToObject<typeof rules> ? (RuleListToObject<typeof rules>[K] extends RuleDef<K> ? RuleListToObject<typeof rules>[K] : never) : (K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never) : never);
38
+ addMany<U extends readonly RuleDef<Context>[]>(...rules: CheckOverlap<RuleNamesFromList<U>, Names, U>): Builder<Context, Names | RuleNamesFromList<U>, {
39
+ [K in Names | RuleNamesFromList<U>]: K extends keyof RuleListToObject<typeof rules> ? (RuleListToObject<typeof rules>[K] extends RuleDef<Context, K> ? RuleListToObject<typeof rules>[K] : never) : (K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never) : never);
34
40
  }>;
35
- deleteRule<U extends Names>(ruleName: U): Builder<Exclude<Names, U>, {
36
- [K in Exclude<Names, U>]: RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never;
41
+ /**
42
+ * Delete a grammar rule by its name.
43
+ */
44
+ deleteRule<U extends Names>(ruleName: U): Builder<Context, Exclude<Names, U>, {
45
+ [K in Exclude<Names, U>]: RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never;
37
46
  }>;
38
- merge<OtherNames extends string, OtherRules extends RuleDefMap<OtherNames>, OW extends readonly RuleDef[]>(builder: Builder<OtherNames, OtherRules>, overridingRules: OW): Builder<Names | OtherNames | RuleNamesFromList<OW>, {
39
- [K in Names | OtherNames | RuleNamesFromList<OW>]: K extends keyof RuleListToObject<OW> ? (RuleListToObject<OW>[K] extends RuleDef<K> ? RuleListToObject<OW>[K] : never) : (K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never) : K extends OtherNames ? (OtherRules[K] extends RuleDef<K> ? OtherRules[K] : never) : never);
47
+ /**
48
+ * Merge this grammar builder with another.
49
+ * It is best to merge the bigger grammar with the smaller one.
50
+ * If the two builders both have a grammar rule with the same name, no error will be thrown case they map to the same ruledef object.
51
+ * If they map to a different object, an error will be thrown.
52
+ * To fix this problem, the overridingRules array should contain a rule with the same conflicting name, this rule implementation will be used.
53
+ */
54
+ merge<OtherNames extends string, OtherRules extends RuleDefMap<OtherNames>, OW extends readonly RuleDef<Context>[]>(builder: Builder<Context, OtherNames, OtherRules>, overridingRules: OW): Builder<Context, Names | OtherNames | RuleNamesFromList<OW>, {
55
+ [K in Names | OtherNames | RuleNamesFromList<OW>]: K extends keyof RuleListToObject<OW> ? (RuleListToObject<OW>[K] extends RuleDef<Context, K> ? RuleListToObject<OW>[K] : never) : (K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never) : K extends OtherNames ? (OtherRules[K] extends RuleDef<Context, K> ? OtherRules[K] : never) : never);
40
56
  }>;
41
57
  consumeToParser({ tokenVocabulary, parserConfig, lexerConfig }: {
42
58
  tokenVocabulary: TokenType[];
43
59
  parserConfig?: IParserConfig;
44
60
  lexerConfig?: ILexerConfig;
45
- }, context?: Partial<ImplArgs['context']>): ParserFromRules<Names, RuleDefs>;
61
+ }): ParserFromRules<Context, Names, RuleDefs>;
46
62
  consume({ tokenVocabulary, config }: {
47
63
  tokenVocabulary: TokenVocabulary;
48
64
  config?: IParserConfig;
49
- }, context?: Partial<ImplArgs['context']>): EmbeddedActionsParser & ParseMethodsFromRules<Names, RuleDefs>;
65
+ }): EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> & {
66
+ setContext: (context: Context) => void;
67
+ };
50
68
  }
@@ -1,5 +1,7 @@
1
1
  import { EmbeddedActionsParser, Lexer } from 'chevrotain';
2
- import { DataFactory } from 'rdf-data-factory';
2
+ /**
3
+ * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.
4
+ */
3
5
  function listToRuleDefMap(rules) {
4
6
  const newRules = {};
5
7
  for (const rule of rules) {
@@ -7,9 +9,16 @@ function listToRuleDefMap(rules) {
7
9
  }
8
10
  return newRules;
9
11
  }
12
+ /**
13
+ * The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework).
14
+ * Using the builder you can create a grammar + AST creator.
15
+ * At any point in time, a parser can be constructed from the added rules.
16
+ * Constructing a parser will cause a validation which will validate the correctness of the grammar.
17
+ */
18
+ // This code is wild so other code can be simple.
10
19
  export class Builder {
11
20
  /**
12
- * Create a builder with from some initial grammar rules or an existing builder.
21
+ * Create a builder from some initial grammar rules or an existing builder.
13
22
  * If a builder is provided, a new copy will be created.
14
23
  */
15
24
  static createBuilder(start) {
@@ -51,10 +60,20 @@ export class Builder {
51
60
  this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
52
61
  return this;
53
62
  }
63
+ /**
64
+ * Delete a grammar rule by its name.
65
+ */
54
66
  deleteRule(ruleName) {
55
67
  delete this.rules[ruleName];
56
68
  return this;
57
69
  }
70
+ /**
71
+ * Merge this grammar builder with another.
72
+ * It is best to merge the bigger grammar with the smaller one.
73
+ * If the two builders both have a grammar rule with the same name, no error will be thrown case they map to the same ruledef object.
74
+ * If they map to a different object, an error will be thrown.
75
+ * To fix this problem, the overridingRules array should contain a rule with the same conflicting name, this rule implementation will be used.
76
+ */
58
77
  merge(builder, overridingRules) {
59
78
  // Assume the other grammar is bigger than yours. So start from that one and add this one
60
79
  const otherRules = { ...builder.rules };
@@ -81,7 +100,7 @@ export class Builder {
81
100
  this.rules = otherRules;
82
101
  return this;
83
102
  }
84
- consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }, context = {}) {
103
+ consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }) {
85
104
  const lexer = new Lexer(tokenVocabulary, {
86
105
  positionTracking: 'onlyStart',
87
106
  recoveryEnabled: false,
@@ -90,11 +109,13 @@ export class Builder {
90
109
  ensureOptimizations: true,
91
110
  ...lexerConfig,
92
111
  });
93
- const parser = this.consume({ tokenVocabulary, config: parserConfig }, context);
112
+ // get the chevrotain parser
113
+ const parser = this.consume({ tokenVocabulary, config: parserConfig });
114
+ // Start building a parser that does not pass input using a state, but instead gets it as a function argument.
94
115
  const selfSufficientParser = {};
95
- // eslint-disable-next-line ts/no-unnecessary-type-assertion
116
+ // To do that, we need to create a wrapper for each parser rule.
96
117
  for (const rule of Object.values(this.rules)) {
97
- selfSufficientParser[rule.name] = ((input, arg) => {
118
+ selfSufficientParser[rule.name] = ((input, context, arg) => {
98
119
  // Transform input in accordance to 19.2
99
120
  input = input.replaceAll(/\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu, (_, unicode4, unicode8) => {
100
121
  if (unicode4) {
@@ -113,10 +134,10 @@ export class Builder {
113
134
  throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
114
135
  }
115
136
  const lexResult = lexer.tokenize(input);
116
- // Console.log(lexResult.tokens);
117
- parser.reset();
137
+ // This also resets the parser
118
138
  parser.input = lexResult.tokens;
119
- const result = parser[rule.name](arg);
139
+ parser.setContext(context);
140
+ const result = parser[rule.name](context, arg);
120
141
  if (parser.errors.length > 0) {
121
142
  // Console.log(lexResult.tokens);
122
143
  throw new Error(`Parse error on line ${parser.errors.map(x => x.token.startLine).join(', ')}
@@ -127,9 +148,18 @@ ${parser.errors.map(x => `${x.token.startLine}: ${x.message}`).join('\n')}`);
127
148
  }
128
149
  return selfSufficientParser;
129
150
  }
130
- consume({ tokenVocabulary, config = {} }, context = {}) {
151
+ consume({ tokenVocabulary, config = {} }) {
131
152
  const rules = this.rules;
132
153
  class MyParser extends EmbeddedActionsParser {
154
+ getSafeContext() {
155
+ if (this.context === undefined) {
156
+ throw new Error('context was not correctly set');
157
+ }
158
+ return this.context;
159
+ }
160
+ setContext(context) {
161
+ this.context = context;
162
+ }
133
163
  constructor() {
134
164
  super(tokenVocabulary, {
135
165
  // RecoveryEnabled: true,
@@ -137,44 +167,21 @@ ${parser.errors.map(x => `${x.token.startLine}: ${x.message}`).join('\n')}`);
137
167
  // SkipValidations: true,
138
168
  ...config,
139
169
  });
170
+ this.context = undefined;
140
171
  const selfRef = this.getSelfRef();
141
- // !!! Remember to change the RESET function accordingly !!!
142
- this.initialParseContext = {
143
- dataFactory: new DataFactory({ blankNodePrefix: 'g_' }),
144
- baseIRI: undefined,
145
- parseMode: new Set(),
146
- skipValidation: false,
147
- ...context,
148
- prefixes: context.prefixes ? { ...context.prefixes } : {},
149
- };
150
- this.runningContext = {
151
- ...this.initialParseContext,
152
- prefixes: { ...this.initialParseContext.prefixes },
153
- parseMode: new Set(this.initialParseContext.parseMode),
154
- };
155
172
  const implArgs = {
156
173
  ...selfRef,
157
174
  cache: new WeakMap(),
158
- context: this.runningContext,
159
175
  };
160
176
  for (const rule of Object.values(rules)) {
161
177
  this[rule.name] = this.RULE(rule.name, rule.impl(implArgs));
162
178
  }
163
179
  this.performSelfAnalysis();
164
180
  }
165
- reset() {
166
- super.reset();
167
- // We need to keep the original object reference.
168
- Object.assign(this.runningContext, {
169
- ...this.initialParseContext,
170
- });
171
- this.runningContext.prefixes = { ...this.initialParseContext.prefixes };
172
- this.runningContext.parseMode = new Set(this.initialParseContext.parseMode);
173
- }
174
181
  getSelfRef() {
175
- const subRuleImpl = (subrule) => {
176
- return ((cstDef, ...args) => {
177
- return subrule(this[cstDef.name], { ARGS: args });
182
+ const subRuleImpl = (chevrotainSubrule) => {
183
+ return ((cstDef, arg) => {
184
+ return chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] });
178
185
  });
179
186
  };
180
187
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"parserBuilder.js","sourceRoot":"","sources":["parserBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAW/C,SAAS,gBAAgB,CAA+B,KAAQ;IAC9D,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,OAA4B,QAAQ,CAAC;AACvC,CAAC;AAED,MAAM,OAAO,OAAO;IAClB;;;OAGG;IACI,MAAM,CAAC,aAAa,CAI3B,KAAuC;QACrC,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;YAC7B,OAAO,IAAI,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACzC,C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AQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;iBACjE,CAAC;YACJ,CAAC;SACF;QACD,OAAiF,IAAI,QAAQ,EAAE,CAAC;IAClG,CAAC;CACF","sourcesContent":["import type { ILexerConfig, IParserConfig } from '@chevrotain/types';\nimport type {IToken, TokenType, TokenVocabulary} from 'chevrotain';\nimport { EmbeddedActionsParser, Lexer } from 'chevrotain';\nimport { DataFactory } from 'rdf-data-factory';\nimport type {\n CheckOverlap,\n RuleDefMap,\n ParserFromRules,\n RuleListToObject,\n RuleNamesFromList,\n ParseMethodsFromRules,\n} from './builderTypes';\nimport type { CstDef, ImplArgs, RuleDef } from './ruleDefTypes';\n\nfunction listToRuleDefMap<T extends readonly RuleDef[]>(rules: T): RuleListToObject<T> {\n const newRules: Record<string, RuleDef> = {};\n for (const rule of rules) {\n newRules[rule.name] = rule;\n }\n return <RuleListToObject<T>>newRules;\n}\n\nexport class Builder<Names extends string, RuleDefs extends RuleDefMap<Names>> {\n /**\n * Create a builder with 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 createBuilder<\n Rules extends readonly RuleDef[] = RuleDef[],\n Names extends string = RuleNamesFromList<Rules>,\n RuleDefs extends RuleDefMap<Names> = RuleListToObject<Rules>,\n>(start: Rules | Builder<Names, RuleDefs>): Builder<Names, RuleDefs> {\n if (start instanceof Builder) {\n return new Builder({ ...start.rules });\n }\n return <Builder<Names, RuleDefs>> <unknown> new Builder(listToRuleDefMap(start));\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n /**\n * Change the implementation of an existing grammar rule.\n */\n public patchRule<U extends Names, RET, ARGS extends unknown[]>(patch: RuleDef<U, RET, ARGS>):\n Builder<Names, {[Key in Names]: Key extends U ? RuleDef<Key, RET, ARGS> : (RuleDefs[Key] extends RuleDef<Key> ? RuleDefs[Key] : never) }> {\n const self = <Builder<Names, {[Key in Names]: Key extends U ? RuleDef<Key, RET, ARGS> : (RuleDefs[Key] extends RuleDef<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 unknown[]>(rule: RuleDef<U, RET, ARGS>):\n Builder<Names | U, {[K in Names | U]: K extends U ? RuleDef<K, RET, ARGS> : ( K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never ) : never) }> {\n const self = <Builder<Names | U, {[K in Names | U]: K extends U ? RuleDef<K, RET, ARGS> : ( K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never ) : never) }>>\n <unknown> this;\n const rules = <Record<string, RuleDef>> 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 unknown[]>(\n rule: CheckOverlap<U, Names, RuleDef<U, RET, ARGS>>,\n ): Builder<Names | U, {[K in Names | U]: K extends U ? RuleDef<K, RET, ARGS> : ( K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never ) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends RuleDef[]>(\n ...rules: CheckOverlap<RuleNamesFromList<U>, Names, U>\n ): Builder<\n Names | RuleNamesFromList<U>,\n {[K in Names | RuleNamesFromList<U>]:\n K extends keyof RuleListToObject<typeof rules> ? (\n RuleListToObject<typeof rules>[K] extends RuleDef<K> ? RuleListToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never) : never\n )\n }> {\n this.rules = { ...this.rules, ...listToRuleDefMap(rules) };\n return <any> <unknown> this;\n }\n\n public deleteRule<U extends Names>(ruleName: U):\n Builder<Exclude<Names, U>, { [K in Exclude<Names, U>]: RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <Builder<Exclude<Names, U>, { [K in Exclude<Names, U>]: RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never }>>\n <unknown> this;\n }\n\n public merge<OtherNames extends string, OtherRules extends RuleDefMap<OtherNames>, OW extends readonly RuleDef[]>(\n builder: Builder<OtherNames, OtherRules>,\n overridingRules: OW,\n ):\n Builder<\n Names | OtherNames | RuleNamesFromList<OW>,\n {[K in Names | OtherNames | RuleNamesFromList<OW>]:\n K extends keyof RuleListToObject<OW> ? (\n RuleListToObject<OW>[K] extends RuleDef<K> ? RuleListToObject<OW>[K] : never\n )\n : (\n K extends Names ? (RuleDefs[K] extends RuleDef<K> ? RuleDefs[K] : never)\n : K extends OtherNames ? (OtherRules[K] extends RuleDef<K> ? OtherRules[K] : never) : never\n )}> {\n // Assume the other grammar is bigger than yours. So start from that one and add this one\n const otherRules: Record<string, RuleDef> = { ...builder.rules };\n const myRules: Record<string, RuleDef> = 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 public consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {}}: {\n tokenVocabulary: TokenType[];\n parserConfig?: IParserConfig;\n lexerConfig?: ILexerConfig;\n }, context: Partial<ImplArgs['context']> = {}): ParserFromRules<Names, RuleDefs> {\n const lexer: Lexer = new Lexer(tokenVocabulary, {\n positionTracking: 'onlyStart',\n recoveryEnabled: false,\n // SafeMode: true,\n // SkipValidations: true,\n ensureOptimizations: true,\n ...lexerConfig,\n });\n const parser = this.consume({ tokenVocabulary, config: parserConfig }, context);\n const selfSufficientParser: Partial<ParserFromRules<Names, RuleDefs>> = {};\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n for (const rule of <RuleDef<Names>[]> Object.values(this.rules)) {\n selfSufficientParser[rule.name] = <any> ((input: string, arg: unknown) => {\n // Transform input in accordance to 19.2\n input = input.replaceAll(\n /\\\\u([0-9a-fA-F]{4})|\\\\U([0-9a-fA-F]{8})/gu,\n (_, unicode4: string, unicode8: string) => {\n if (unicode4) {\n const charCode = Number.parseInt(unicode4, 16);\n return String.fromCodePoint(charCode);\n }\n const charCode = Number.parseInt(unicode8, 16);\n if (charCode < 0xFFFF) {\n return String.fromCodePoint(charCode);\n }\n const substractedCharCode = charCode - 0x10000;\n return String.fromCodePoint(0xD800 + (substractedCharCode >> 10), 0xDC00 + (substractedCharCode & 0x3FF));\n },\n );\n // Test for invalid unicode surrogate pairs\n if (/[\\uD800-\\uDBFF]([^\\uDC00-\\uDFFF]|$)/u.test(input)) {\n throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);\n }\n\n const lexResult = lexer.tokenize(input);\n // Console.log(lexResult.tokens);\n\n parser.reset();\n parser.input = lexResult.tokens;\n const result = parser[rule.name](arg);\n if (parser.errors.length > 0) {\n // Console.log(lexResult.tokens);\n throw new Error(`Parse error on line ${parser.errors.map(x => x.token.startLine).join(', ')}\n${parser.errors.map(x => `${x.token.startLine}: ${x.message}`).join('\\n')}`);\n }\n return result;\n });\n }\n return <ParserFromRules<Names, RuleDefs>> selfSufficientParser;\n }\n\n public consume({ tokenVocabulary, config = {}}: {\n tokenVocabulary: TokenVocabulary;\n config?: IParserConfig;\n }, context: Partial<ImplArgs['context']> = {}): EmbeddedActionsParser & ParseMethodsFromRules<Names, RuleDefs> {\n const rules = this.rules;\n class MyParser extends EmbeddedActionsParser {\n private readonly initialParseContext: ImplArgs['context'];\n private readonly runningContext: ImplArgs['context'];\n\n public constructor() {\n super(tokenVocabulary, {\n // RecoveryEnabled: true,\n maxLookahead: 2,\n // SkipValidations: true,\n ...config,\n });\n\n const selfRef = this.getSelfRef();\n // !!! Remember to change the RESET function accordingly !!!\n this.initialParseContext = {\n dataFactory: new DataFactory({ blankNodePrefix: 'g_' }),\n baseIRI: undefined,\n parseMode: new Set(),\n skipValidation: false,\n ...context,\n prefixes: context.prefixes ? { ...context.prefixes } : {},\n };\n this.runningContext = {\n ...this.initialParseContext,\n prefixes: { ...this.initialParseContext.prefixes },\n parseMode: new Set(this.initialParseContext.parseMode),\n };\n\n const implArgs: ImplArgs = {\n ...selfRef,\n cache: new WeakMap(),\n context: this.runningContext,\n };\n\n for (const rule of Object.values(<Record<string, RuleDef>>rules)) {\n this[<keyof (typeof this)> rule.name] = <any> this.RULE(rule.name, rule.impl(implArgs));\n }\n this.performSelfAnalysis();\n }\n\n public override reset(): void {\n super.reset();\n // We need to keep the original object reference.\n Object.assign(this.runningContext, {\n ...this.initialParseContext,\n });\n this.runningContext.prefixes = { ...this.initialParseContext.prefixes };\n this.runningContext.parseMode = new Set(this.initialParseContext.parseMode);\n }\n\n private getSelfRef(): CstDef {\n const subRuleImpl = (subrule: typeof this.SUBRULE): CstDef['SUBRULE'] => {\n return ((cstDef, ...args) => {\n return subrule(<any> this[<keyof (typeof this)> cstDef.name], <any> { ARGS: args });\n }) satisfies CstDef['SUBRULE'];\n }\n return {\n CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),\n CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),\n CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),\n CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),\n CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),\n CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),\n CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),\n CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),\n CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),\n CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),\n OPTION: actionORMethodDef => this.OPTION(actionORMethodDef),\n OPTION1: actionORMethodDef => this.OPTION1(actionORMethodDef),\n OPTION2: actionORMethodDef => this.OPTION2(actionORMethodDef),\n OPTION3: actionORMethodDef => this.OPTION3(actionORMethodDef),\n OPTION4: actionORMethodDef => this.OPTION4(actionORMethodDef),\n OPTION5: actionORMethodDef => this.OPTION5(actionORMethodDef),\n OPTION6: actionORMethodDef => this.OPTION6(actionORMethodDef),\n OPTION7: actionORMethodDef => this.OPTION7(actionORMethodDef),\n OPTION8: actionORMethodDef => this.OPTION8(actionORMethodDef),\n OPTION9: actionORMethodDef => this.OPTION9(actionORMethodDef),\n OR: altsOrOpts => this.OR(altsOrOpts),\n OR1: altsOrOpts => this.OR1(altsOrOpts),\n OR2: altsOrOpts => this.OR2(altsOrOpts),\n OR3: altsOrOpts => this.OR3(altsOrOpts),\n OR4: altsOrOpts => this.OR4(altsOrOpts),\n OR5: altsOrOpts => this.OR5(altsOrOpts),\n OR6: altsOrOpts => this.OR6(altsOrOpts),\n OR7: altsOrOpts => this.OR7(altsOrOpts),\n OR8: altsOrOpts => this.OR8(altsOrOpts),\n OR9: altsOrOpts => this.OR9(altsOrOpts),\n MANY: actionORMethodDef => this.MANY(actionORMethodDef),\n MANY1: actionORMethodDef => this.MANY1(actionORMethodDef),\n MANY2: actionORMethodDef => this.MANY2(actionORMethodDef),\n MANY3: actionORMethodDef => this.MANY3(actionORMethodDef),\n MANY4: actionORMethodDef => this.MANY4(actionORMethodDef),\n MANY5: actionORMethodDef => this.MANY5(actionORMethodDef),\n MANY6: actionORMethodDef => this.MANY6(actionORMethodDef),\n MANY7: actionORMethodDef => this.MANY7(actionORMethodDef),\n MANY8: actionORMethodDef => this.MANY8(actionORMethodDef),\n MANY9: actionORMethodDef => this.MANY9(actionORMethodDef),\n MANY_SEP: options => this.MANY_SEP(options),\n MANY_SEP1: options => this.MANY_SEP1(options),\n MANY_SEP2: options => this.MANY_SEP2(options),\n MANY_SEP3: options => this.MANY_SEP3(options),\n MANY_SEP4: options => this.MANY_SEP4(options),\n MANY_SEP5: options => this.MANY_SEP5(options),\n MANY_SEP6: options => this.MANY_SEP6(options),\n MANY_SEP7: options => this.MANY_SEP7(options),\n MANY_SEP8: options => this.MANY_SEP8(options),\n MANY_SEP9: options => this.MANY_SEP9(options),\n AT_LEAST_ONE: actionORMethodDef => this.AT_LEAST_ONE(actionORMethodDef),\n AT_LEAST_ONE1: actionORMethodDef => this.AT_LEAST_ONE1(actionORMethodDef),\n AT_LEAST_ONE2: actionORMethodDef => this.AT_LEAST_ONE2(actionORMethodDef),\n AT_LEAST_ONE3: actionORMethodDef => this.AT_LEAST_ONE3(actionORMethodDef),\n AT_LEAST_ONE4: actionORMethodDef => this.AT_LEAST_ONE4(actionORMethodDef),\n AT_LEAST_ONE5: actionORMethodDef => this.AT_LEAST_ONE5(actionORMethodDef),\n AT_LEAST_ONE6: actionORMethodDef => this.AT_LEAST_ONE6(actionORMethodDef),\n AT_LEAST_ONE7: actionORMethodDef => this.AT_LEAST_ONE7(actionORMethodDef),\n AT_LEAST_ONE8: actionORMethodDef => this.AT_LEAST_ONE8(actionORMethodDef),\n AT_LEAST_ONE9: actionORMethodDef => this.AT_LEAST_ONE9(actionORMethodDef),\n AT_LEAST_ONE_SEP: options => this.AT_LEAST_ONE_SEP(options),\n AT_LEAST_ONE_SEP1: options => this.AT_LEAST_ONE_SEP1(options),\n AT_LEAST_ONE_SEP2: options => this.AT_LEAST_ONE_SEP2(options),\n AT_LEAST_ONE_SEP3: options => this.AT_LEAST_ONE_SEP3(options),\n AT_LEAST_ONE_SEP4: options => this.AT_LEAST_ONE_SEP4(options),\n AT_LEAST_ONE_SEP5: options => this.AT_LEAST_ONE_SEP5(options),\n AT_LEAST_ONE_SEP6: options => this.AT_LEAST_ONE_SEP6(options),\n AT_LEAST_ONE_SEP7: options => this.AT_LEAST_ONE_SEP7(options),\n AT_LEAST_ONE_SEP8: options => this.AT_LEAST_ONE_SEP8(options),\n AT_LEAST_ONE_SEP9: options => this.AT_LEAST_ONE_SEP9(options),\n ACTION: func => this.ACTION(func),\n BACKTRACK: (cstDef, ...args) => {\n try {\n return this.BACKTRACK(<any> this[<keyof (typeof this)> cstDef.name], <any> { ARGS: args });\n } catch (error: unknown) {\n throw error;\n }\n },\n SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),\n SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),\n SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),\n SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),\n SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),\n SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),\n SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),\n SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),\n SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),\n SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args)),\n };\n }\n }\n return <EmbeddedActionsParser & ParseMethodsFromRules<Names, RuleDefs>><unknown> new MyParser();\n }\n}\n"]}
1
+ {"version":3,"file":"parserBuilder.js","sourceRoot":"","sources":["parserBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,qBAAqB,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AAWxD;;GAEG;AACH,SAAS,gBAAgB,CAA+B,KAAQ;IAC9D,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,OAA4B,QAAQ,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,iDAAiD;AACjD,MAAM,OAAO,OAAO;IAClB;;;OAGG;IACI,MAAM,CAAC,aAAa,CAK3B,KAAgD;QAC9C,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;YAC7B,OAAO,IAAI,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,OAAqD,IAAI,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5F,CAAC;IAID,YAAoB,UAAoB;QACtC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;IAC1B,CAAC;IAED;;OAEG;IACI,SAAS,CAA6B,KAAqC;QAEhF,MAA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F;QACD,OAAuI,IAAI,QAAQ,EAAE,CAAC;IACxJ,CAAC;CACF","sourcesContent":["import {ILexerConfig, IParserConfig} from '@chevrotain/types';\nimport type {TokenType, TokenVocabulary} from 'chevrotain';\nimport {EmbeddedActionsParser, Lexer} from 'chevrotain';\nimport type {\n CheckOverlap,\n ParseMethodsFromRules,\n ParserFromRules,\n RuleDefMap,\n RuleListToObject,\n RuleNamesFromList,\n} from './builderTypes';\nimport type {CstDef, ImplArgs, RuleDef} from './ruleDefTypes';\n\n/**\n * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.\n */\nfunction listToRuleDefMap<T extends readonly RuleDef[]>(rules: T): RuleListToObject<T> {\n const newRules: Record<string, RuleDef> = {};\n for (const rule of rules) {\n newRules[rule.name] = rule;\n }\n return <RuleListToObject<T>>newRules;\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 Builder<Context, Names extends string, RuleDefs extends RuleDefMap<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 createBuilder<\n Rules extends readonly RuleDef[] = readonly RuleDef[],\n Context = Rules[0] extends RuleDef<infer context> ? context : never,\n Names extends string = RuleNamesFromList<Rules>,\n RuleDefs extends RuleDefMap<Names> = RuleListToObject<Rules>,\n>(start: Rules | Builder<Context, Names, RuleDefs>): Builder<Context, Names, RuleDefs> {\n if (start instanceof Builder) {\n return new Builder({ ...start.rules });\n }\n return <Builder<Context, Names, RuleDefs>> <unknown> new Builder(listToRuleDefMap(start));\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n /**\n * Change the implementation of an existing grammar rule.\n */\n public patchRule<U extends Names, RET, ARGS>(patch: RuleDef<Context, U, RET, ARGS>):\n Builder<Context, Names, {[Key in Names]: Key extends U ? RuleDef<Context, Key, RET, ARGS> : (RuleDefs[Key] extends RuleDef<Context, Key> ? RuleDefs[Key] : never) }> {\n const self = <Builder<Context, Names, {[Key in Names]: Key extends U ? RuleDef<Context, Key, RET, ARGS> : (RuleDefs[Key] extends RuleDef<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>(rule: RuleDef<Context, U, RET, ARGS>):\n Builder<Context, Names | U, {[K in Names | U]: K extends U ? RuleDef<Context, K, RET, ARGS> : ( K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never ) : never) }> {\n const self = <Builder<Context, Names | U, {[K in Names | U]: K extends U ? RuleDef<Context, K, RET, ARGS> : ( K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never ) : never) }>>\n <unknown> this;\n const rules = <Record<string, RuleDef<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>(\n rule: CheckOverlap<U, Names, RuleDef<Context, U, RET, ARGS>>,\n ): Builder<Context, Names | U, {[K in Names | U]: K extends U ? RuleDef<Context, K, RET, ARGS> : ( K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never ) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends readonly RuleDef<Context>[]>(\n ...rules: CheckOverlap<RuleNamesFromList<U>, Names, U>\n ): Builder<\n Context,\n Names | RuleNamesFromList<U>,\n {[K in Names | RuleNamesFromList<U>]:\n K extends keyof RuleListToObject<typeof rules> ? (\n RuleListToObject<typeof rules>[K] extends RuleDef<Context, K> ? RuleListToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never) : never\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 Builder<Context, Exclude<Names, U>, { [K in Exclude<Names, U>]: RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <Builder<Context, Exclude<Names, U>, { [K in Exclude<Names, U>]: RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never }>>\n <unknown> this;\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, 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, this rule implementation will be used.\n */\n public merge<OtherNames extends string, OtherRules extends RuleDefMap<OtherNames>, OW extends readonly RuleDef<Context>[]>(\n builder: Builder<Context, OtherNames, OtherRules>,\n overridingRules: OW,\n ):\n Builder<\n Context,\n Names | OtherNames | RuleNamesFromList<OW>,\n {[K in Names | OtherNames | RuleNamesFromList<OW>]:\n K extends keyof RuleListToObject<OW> ? (\n RuleListToObject<OW>[K] extends RuleDef<Context, K> ? RuleListToObject<OW>[K] : never\n )\n : (\n K extends Names ? (RuleDefs[K] extends RuleDef<Context, K> ? RuleDefs[K] : never)\n : K extends OtherNames ? (OtherRules[K] extends RuleDef<Context, K> ? OtherRules[K] : never) : never\n )}> {\n // Assume the other grammar is bigger than yours. So start from that one and add this one\n const otherRules: Record<string, RuleDef<Context>> = { ...builder.rules };\n const myRules: Record<string, RuleDef<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 public consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {}}: {\n tokenVocabulary: TokenType[];\n parserConfig?: IParserConfig;\n lexerConfig?: ILexerConfig;\n }): ParserFromRules<Context, Names, RuleDefs> {\n const lexer: Lexer = new Lexer(tokenVocabulary, {\n positionTracking: 'onlyStart',\n recoveryEnabled: false,\n // SafeMode: true,\n // SkipValidations: true,\n ensureOptimizations: true,\n ...lexerConfig,\n });\n // get the chevrotain parser\n const parser = this.consume({ tokenVocabulary, config: parserConfig });\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 // To do that, we need to create a wrapper for each parser rule.\n for (const rule of <RuleDef<Context, Names>[]> Object.values(this.rules)) {\n selfSufficientParser[rule.name] = <any> ((input: string, context: Context, arg: unknown) => {\n // Transform input in accordance to 19.2\n input = input.replaceAll(\n /\\\\u([0-9a-fA-F]{4})|\\\\U([0-9a-fA-F]{8})/gu,\n (_, unicode4: string, unicode8: string) => {\n if (unicode4) {\n const charCode = Number.parseInt(unicode4, 16);\n return String.fromCodePoint(charCode);\n }\n const charCode = Number.parseInt(unicode8, 16);\n if (charCode < 0xFFFF) {\n return String.fromCodePoint(charCode);\n }\n const substractedCharCode = charCode - 0x10000;\n return String.fromCodePoint(0xD800 + (substractedCharCode >> 10), 0xDC00 + (substractedCharCode & 0x3FF));\n },\n );\n // Test for invalid unicode surrogate pairs\n if (/[\\uD800-\\uDBFF]([^\\uDC00-\\uDFFF]|$)/u.test(input)) {\n throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);\n }\n\n const lexResult = lexer.tokenize(input);\n\n // This also resets the parser\n parser.input = lexResult.tokens;\n parser.setContext(context);\n const result = parser[rule.name](context, arg);\n if (parser.errors.length > 0) {\n // Console.log(lexResult.tokens);\n throw new Error(`Parse error on line ${parser.errors.map(x => x.token.startLine).join(', ')}\n${parser.errors.map(x => `${x.token.startLine}: ${x.message}`).join('\\n')}`);\n }\n return result;\n });\n }\n return <ParserFromRules<Context, Names, RuleDefs>> selfSufficientParser;\n }\n\n public consume({ tokenVocabulary, config = {}}: {\n tokenVocabulary: TokenVocabulary;\n config?: IParserConfig;\n }): EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> & { setContext: (context: Context) => void } {\n const rules = this.rules;\n class MyParser extends EmbeddedActionsParser {\n private context: Context | undefined;\n\n private getSafeContext(): Context {\n if (this.context === undefined) {\n throw new Error('context was not correctly set');\n }\n return this.context;\n }\n\n public setContext(context: Context): void {\n this.context = context;\n }\n\n public constructor() {\n super(tokenVocabulary, {\n // RecoveryEnabled: true,\n maxLookahead: 2,\n // SkipValidations: true,\n ...config,\n });\n this.context = undefined;\n const selfRef = this.getSelfRef();\n const implArgs: ImplArgs = {\n ...selfRef,\n cache: new WeakMap(),\n };\n\n for (const rule of Object.values(<Record<string, RuleDef<Context>>>rules)) {\n this[<keyof (typeof this)> rule.name] = <any> this.RULE(rule.name, rule.impl(implArgs));\n }\n this.performSelfAnalysis();\n }\n\n private getSelfRef(): CstDef {\n const subRuleImpl = (chevrotainSubrule: typeof this.SUBRULE): CstDef['SUBRULE'] => {\n return ((cstDef, arg) => {\n return chevrotainSubrule(<any> this[<keyof (typeof this)> cstDef.name], <any> { ARGS: [this.context, arg] });\n }) satisfies CstDef['SUBRULE'];\n }\n return {\n CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),\n CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),\n CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),\n CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),\n CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),\n CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),\n CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),\n CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),\n CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),\n CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),\n OPTION: actionORMethodDef => this.OPTION(actionORMethodDef),\n OPTION1: actionORMethodDef => this.OPTION1(actionORMethodDef),\n OPTION2: actionORMethodDef => this.OPTION2(actionORMethodDef),\n OPTION3: actionORMethodDef => this.OPTION3(actionORMethodDef),\n OPTION4: actionORMethodDef => this.OPTION4(actionORMethodDef),\n OPTION5: actionORMethodDef => this.OPTION5(actionORMethodDef),\n OPTION6: actionORMethodDef => this.OPTION6(actionORMethodDef),\n OPTION7: actionORMethodDef => this.OPTION7(actionORMethodDef),\n OPTION8: actionORMethodDef => this.OPTION8(actionORMethodDef),\n OPTION9: actionORMethodDef => this.OPTION9(actionORMethodDef),\n OR: altsOrOpts => this.OR(altsOrOpts),\n OR1: altsOrOpts => this.OR1(altsOrOpts),\n OR2: altsOrOpts => this.OR2(altsOrOpts),\n OR3: altsOrOpts => this.OR3(altsOrOpts),\n OR4: altsOrOpts => this.OR4(altsOrOpts),\n OR5: altsOrOpts => this.OR5(altsOrOpts),\n OR6: altsOrOpts => this.OR6(altsOrOpts),\n OR7: altsOrOpts => this.OR7(altsOrOpts),\n OR8: altsOrOpts => this.OR8(altsOrOpts),\n OR9: altsOrOpts => this.OR9(altsOrOpts),\n MANY: actionORMethodDef => this.MANY(actionORMethodDef),\n MANY1: actionORMethodDef => this.MANY1(actionORMethodDef),\n MANY2: actionORMethodDef => this.MANY2(actionORMethodDef),\n MANY3: actionORMethodDef => this.MANY3(actionORMethodDef),\n MANY4: actionORMethodDef => this.MANY4(actionORMethodDef),\n MANY5: actionORMethodDef => this.MANY5(actionORMethodDef),\n MANY6: actionORMethodDef => this.MANY6(actionORMethodDef),\n MANY7: actionORMethodDef => this.MANY7(actionORMethodDef),\n MANY8: actionORMethodDef => this.MANY8(actionORMethodDef),\n MANY9: actionORMethodDef => this.MANY9(actionORMethodDef),\n MANY_SEP: options => this.MANY_SEP(options),\n MANY_SEP1: options => this.MANY_SEP1(options),\n MANY_SEP2: options => this.MANY_SEP2(options),\n MANY_SEP3: options => this.MANY_SEP3(options),\n MANY_SEP4: options => this.MANY_SEP4(options),\n MANY_SEP5: options => this.MANY_SEP5(options),\n MANY_SEP6: options => this.MANY_SEP6(options),\n MANY_SEP7: options => this.MANY_SEP7(options),\n MANY_SEP8: options => this.MANY_SEP8(options),\n MANY_SEP9: options => this.MANY_SEP9(options),\n AT_LEAST_ONE: actionORMethodDef => this.AT_LEAST_ONE(actionORMethodDef),\n AT_LEAST_ONE1: actionORMethodDef => this.AT_LEAST_ONE1(actionORMethodDef),\n AT_LEAST_ONE2: actionORMethodDef => this.AT_LEAST_ONE2(actionORMethodDef),\n AT_LEAST_ONE3: actionORMethodDef => this.AT_LEAST_ONE3(actionORMethodDef),\n AT_LEAST_ONE4: actionORMethodDef => this.AT_LEAST_ONE4(actionORMethodDef),\n AT_LEAST_ONE5: actionORMethodDef => this.AT_LEAST_ONE5(actionORMethodDef),\n AT_LEAST_ONE6: actionORMethodDef => this.AT_LEAST_ONE6(actionORMethodDef),\n AT_LEAST_ONE7: actionORMethodDef => this.AT_LEAST_ONE7(actionORMethodDef),\n AT_LEAST_ONE8: actionORMethodDef => this.AT_LEAST_ONE8(actionORMethodDef),\n AT_LEAST_ONE9: actionORMethodDef => this.AT_LEAST_ONE9(actionORMethodDef),\n AT_LEAST_ONE_SEP: options => this.AT_LEAST_ONE_SEP(options),\n AT_LEAST_ONE_SEP1: options => this.AT_LEAST_ONE_SEP1(options),\n AT_LEAST_ONE_SEP2: options => this.AT_LEAST_ONE_SEP2(options),\n AT_LEAST_ONE_SEP3: options => this.AT_LEAST_ONE_SEP3(options),\n AT_LEAST_ONE_SEP4: options => this.AT_LEAST_ONE_SEP4(options),\n AT_LEAST_ONE_SEP5: options => this.AT_LEAST_ONE_SEP5(options),\n AT_LEAST_ONE_SEP6: options => this.AT_LEAST_ONE_SEP6(options),\n AT_LEAST_ONE_SEP7: options => this.AT_LEAST_ONE_SEP7(options),\n AT_LEAST_ONE_SEP8: options => this.AT_LEAST_ONE_SEP8(options),\n AT_LEAST_ONE_SEP9: options => this.AT_LEAST_ONE_SEP9(options),\n ACTION: func => this.ACTION(func),\n BACKTRACK: (cstDef, ...args) => {\n try {\n return this.BACKTRACK(<any> this[<keyof (typeof this)> cstDef.name], <any> { ARGS: args });\n } catch (error: unknown) {\n throw error;\n }\n },\n SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),\n SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),\n SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),\n SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),\n SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),\n SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),\n SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),\n SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),\n SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),\n SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args)),\n };\n }\n }\n return <EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> & { setContext: (context: Context) => void }><unknown> new MyParser();\n }\n}\n"]}
@@ -1,37 +1,53 @@
1
1
  import type { AtLeastOneSepMethodOpts, DSLMethodOpts, DSLMethodOptsWithErr, GrammarAction, IOrAlt, ManySepMethodOpts, OrMethodOpts } from '@chevrotain/types';
2
- import type * as RDF from '@rdfjs/types';
3
2
  import type { ConsumeMethodOpts, IToken, TokenType } from 'chevrotain';
4
- import type { DataFactory } from 'rdf-data-factory';
5
- export type RuleDef<NameType extends string = string, ReturnType = unknown, ParamType extends unknown[] = unknown[]> = {
3
+ /**
4
+ * Get the return-type of a RuleDef
5
+ */
6
+ export type RuleDefReturn<T extends RuleDef> = T extends RuleDef<any, string, infer Ret> ? Ret : never;
7
+ /**
8
+ * Type used to declare grammar rules.
9
+ */
10
+ export type RuleDef<
11
+ /**
12
+ * Context object available in rule implementation.
13
+ */
14
+ Context = any,
15
+ /**
16
+ * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.
17
+ */
18
+ NameType extends string = string,
19
+ /**
20
+ * Type that will be returned after a correct parse of this rule.
21
+ * This type will be the return type of calling SUBRULE with this grammar rule.
22
+ */
23
+ ReturnType = unknown,
24
+ /**
25
+ * Function arguments that can be given to convey the state of the current parse operation.
26
+ */
27
+ ParamType = any> = {
6
28
  name: NameType;
7
- impl: (def: ImplArgs) => (...args: ArrayMagicWork<ParamType>) => ReturnType;
29
+ impl: (def: ImplArgs) => (context: Context, params: ParamType) => ReturnType;
8
30
  };
9
- export type RuleDefReturn<T> = T extends RuleDef<any, infer Ret, any> ? Ret : never;
10
- type ArrayMagicWork<ArrayType extends unknown[]> = ArrayType extends [infer First, ...infer Rest] ? [First, ...ArrayMagicWork<Rest>] : [];
31
+ /**
32
+ * Type expected by grammar rules in the main `impl` function.
33
+ */
11
34
  export interface ImplArgs extends CstDef {
12
35
  cache: WeakMap<RuleDef, unknown>;
13
- context: {
14
- dataFactory: DataFactory<RDF.BaseQuad>;
15
- /**
16
- * Current scoped prefixes. Used for resolving prefixed names.
17
- */
18
- prefixes: Record<string, string>;
19
- /**
20
- * The base IRI for the query. Used for resolving relative IRIs.
21
- */
22
- baseIRI: string | undefined;
23
- /**
24
- * Can be used to disable the validation that used variables in a select clause are in scope.
25
- */
26
- skipValidation: boolean;
27
- /**
28
- * Set of queryModes. Primarily used for note 8, 14.
29
- */
30
- parseMode: Set<symbol>;
31
- };
32
36
  }
33
- type SubRuleFunc = <T extends string, U = unknown, ARGS extends any[] = []>(cstDef: RuleDef<T, U, ARGS>, ...argument: ARGS) => U;
34
- type BacktrackFunc = <T extends string, U = unknown, ARGS extends any[] = []>(cstDef: RuleDef<T, U, ARGS>, ...argument: ARGS) => () => boolean;
37
+ /**
38
+ * Type definition used by {@link CstDef.SUBRULE} and family.
39
+ */
40
+ type SubRuleFunc = <T extends string, U = unknown, ARGS = any>(cstDef: RuleDef<any, T, U, ARGS>, argument: ARGS) => U;
41
+ /**
42
+ * Type definition used by {@link CstDef.BACKTRACK}.
43
+ */
44
+ type BacktrackFunc = <T extends string, U = unknown, ARGS = any>(cstDef: RuleDef<any, T, U, ARGS>, argument: ARGS) => () => boolean;
45
+ /**
46
+ * Mainly a repetition of the functions exposed by the {@link EmbeddedActionsParser},
47
+ * with some small adjustments that allow for the API changes made by traqula.
48
+ * Specifically changes are made to the {@link CstDef.SUBRULE} (and family) interface,
49
+ * and to the {@link CstDef.BACKTRACK} interface.
50
+ */
35
51
  export interface CstDef {
36
52
  /**
37
53
  *
@@ -303,7 +319,7 @@ export interface CstDef {
303
319
  *
304
320
  * @param options - An object defining the grammar of each iteration and the separator between iterations
305
321
  *
306
- * @return {ISeparatedIterationResult<OUT>}
322
+ * @return ISeparatedIterationResult<OUT>
307
323
  */
308
324
  AT_LEAST_ONE_SEP: (options: AtLeastOneSepMethodOpts<any>) => void;
309
325
  AT_LEAST_ONE_SEP1: (options: AtLeastOneSepMethodOpts<any>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n} from '@chevrotain/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { ConsumeMethodOpts, IToken, TokenType } from 'chevrotain';\nimport type { DataFactory } from 'rdf-data-factory';\n\nexport type RuleDef<\n NameType extends string = string,\n ReturnType = unknown,\n ParamType extends unknown[] = unknown[],\n> = {\n name: NameType;\n impl: (def: ImplArgs) => (...args: ArrayMagicWork<ParamType>) => ReturnType;\n};\n\nexport type RuleDefReturn<T> = T extends RuleDef<any, infer Ret, any> ? Ret : never;\n\ntype ArrayMagicWork<ArrayType extends unknown[]> =\n ArrayType extends [infer First, ...infer Rest] ? [First, ...ArrayMagicWork<Rest>] : [];\n\nexport interface ImplArgs extends CstDef {\n cache: WeakMap<RuleDef, unknown>;\n context: {\n dataFactory: DataFactory<RDF.BaseQuad>;\n /**\n * Current scoped prefixes. Used for resolving prefixed names.\n */\n prefixes: Record<string, string>;\n /**\n * The base IRI for the query. Used for resolving relative IRIs.\n */\n baseIRI: string | undefined;\n /**\n * Can be used to disable the validation that used variables in a select clause are in scope.\n */\n skipValidation: boolean;\n /**\n * Set of queryModes. Primarily used for note 8, 14.\n */\n parseMode: Set<symbol>;\n };\n}\n\ntype SubRuleFunc = <T extends string, U = unknown, ARGS extends any[] = []>(\n cstDef: RuleDef<T, U, ARGS>,\n ...argument: ARGS\n) => U;\ntype BacktrackFunc = <T extends string, U = unknown, ARGS extends any[] = []>(\n cstDef: RuleDef<T, U, ARGS>,\n ...argument: ARGS\n) => () => boolean;\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 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"]}
1
+ {"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n EmbeddedActionsParser,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n} from '@chevrotain/types';\nimport type {ConsumeMethodOpts, IToken, TokenType} from 'chevrotain';\n\n/**\n * Get the return-type of a RuleDef\n */\nexport type RuleDefReturn<T extends RuleDef> = T extends RuleDef<any, string, infer Ret> ? Ret : never;\n\n/**\n * Type used to declare grammar rules.\n */\nexport type RuleDef<\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 = 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<RuleDef, unknown>;\n}\n\n/**\n * Type definition used by {@link CstDef.SUBRULE} and family.\n */\ntype SubRuleFunc = <T extends string, U = unknown, ARGS = any>(\n cstDef: RuleDef<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 = any>(\n cstDef: RuleDef<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 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"]}
package/lib/index.cjs CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
6
  var __export = (target, all) => {
12
7
  for (var name in all)
13
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,314 +15,8 @@ var __copyProps = (to, from, except, desc) => {
20
15
  }
21
16
  return to;
22
17
  };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
19
 
33
- // ../../node_modules/rdf-data-factory/lib/BlankNode.js
34
- var require_BlankNode = __commonJS({
35
- "../../node_modules/rdf-data-factory/lib/BlankNode.js"(exports2) {
36
- "use strict";
37
- Object.defineProperty(exports2, "__esModule", { value: true });
38
- exports2.BlankNode = void 0;
39
- var BlankNode = class {
40
- constructor(value) {
41
- this.termType = "BlankNode";
42
- this.value = value;
43
- }
44
- equals(other) {
45
- return !!other && other.termType === "BlankNode" && other.value === this.value;
46
- }
47
- };
48
- exports2.BlankNode = BlankNode;
49
- }
50
- });
51
-
52
- // ../../node_modules/rdf-data-factory/lib/DefaultGraph.js
53
- var require_DefaultGraph = __commonJS({
54
- "../../node_modules/rdf-data-factory/lib/DefaultGraph.js"(exports2) {
55
- "use strict";
56
- Object.defineProperty(exports2, "__esModule", { value: true });
57
- exports2.DefaultGraph = void 0;
58
- var DefaultGraph = class {
59
- constructor() {
60
- this.termType = "DefaultGraph";
61
- this.value = "";
62
- }
63
- equals(other) {
64
- return !!other && other.termType === "DefaultGraph";
65
- }
66
- };
67
- exports2.DefaultGraph = DefaultGraph;
68
- DefaultGraph.INSTANCE = new DefaultGraph();
69
- }
70
- });
71
-
72
- // ../../node_modules/rdf-data-factory/lib/NamedNode.js
73
- var require_NamedNode = __commonJS({
74
- "../../node_modules/rdf-data-factory/lib/NamedNode.js"(exports2) {
75
- "use strict";
76
- Object.defineProperty(exports2, "__esModule", { value: true });
77
- exports2.NamedNode = void 0;
78
- var NamedNode = class {
79
- constructor(value) {
80
- this.termType = "NamedNode";
81
- this.value = value;
82
- }
83
- equals(other) {
84
- return !!other && other.termType === "NamedNode" && other.value === this.value;
85
- }
86
- };
87
- exports2.NamedNode = NamedNode;
88
- }
89
- });
90
-
91
- // ../../node_modules/rdf-data-factory/lib/Literal.js
92
- var require_Literal = __commonJS({
93
- "../../node_modules/rdf-data-factory/lib/Literal.js"(exports2) {
94
- "use strict";
95
- Object.defineProperty(exports2, "__esModule", { value: true });
96
- exports2.Literal = void 0;
97
- var NamedNode_1 = require_NamedNode();
98
- var Literal = class _Literal {
99
- constructor(value, languageOrDatatype) {
100
- this.termType = "Literal";
101
- this.value = value;
102
- if (typeof languageOrDatatype === "string") {
103
- this.language = languageOrDatatype;
104
- this.datatype = _Literal.RDF_LANGUAGE_STRING;
105
- this.direction = "";
106
- } else if (languageOrDatatype) {
107
- if ("termType" in languageOrDatatype) {
108
- this.language = "";
109
- this.datatype = languageOrDatatype;
110
- this.direction = "";
111
- } else {
112
- this.language = languageOrDatatype.language;
113
- this.datatype = languageOrDatatype.direction ? _Literal.RDF_DIRECTIONAL_LANGUAGE_STRING : _Literal.RDF_LANGUAGE_STRING;
114
- this.direction = languageOrDatatype.direction || "";
115
- }
116
- } else {
117
- this.language = "";
118
- this.datatype = _Literal.XSD_STRING;
119
- this.direction = "";
120
- }
121
- }
122
- equals(other) {
123
- return !!other && other.termType === "Literal" && other.value === this.value && other.language === this.language && (other.direction === this.direction || !other.direction && this.direction === "") && this.datatype.equals(other.datatype);
124
- }
125
- };
126
- exports2.Literal = Literal;
127
- Literal.RDF_LANGUAGE_STRING = new NamedNode_1.NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
128
- Literal.RDF_DIRECTIONAL_LANGUAGE_STRING = new NamedNode_1.NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString");
129
- Literal.XSD_STRING = new NamedNode_1.NamedNode("http://www.w3.org/2001/XMLSchema#string");
130
- }
131
- });
132
-
133
- // ../../node_modules/rdf-data-factory/lib/Quad.js
134
- var require_Quad = __commonJS({
135
- "../../node_modules/rdf-data-factory/lib/Quad.js"(exports2) {
136
- "use strict";
137
- Object.defineProperty(exports2, "__esModule", { value: true });
138
- exports2.Quad = void 0;
139
- var Quad = class {
140
- constructor(subject, predicate, object, graph) {
141
- this.termType = "Quad";
142
- this.value = "";
143
- this.subject = subject;
144
- this.predicate = predicate;
145
- this.object = object;
146
- this.graph = graph;
147
- }
148
- equals(other) {
149
- return !!other && (other.termType === "Quad" || !other.termType) && this.subject.equals(other.subject) && this.predicate.equals(other.predicate) && this.object.equals(other.object) && this.graph.equals(other.graph);
150
- }
151
- };
152
- exports2.Quad = Quad;
153
- }
154
- });
155
-
156
- // ../../node_modules/rdf-data-factory/lib/Variable.js
157
- var require_Variable = __commonJS({
158
- "../../node_modules/rdf-data-factory/lib/Variable.js"(exports2) {
159
- "use strict";
160
- Object.defineProperty(exports2, "__esModule", { value: true });
161
- exports2.Variable = void 0;
162
- var Variable = class {
163
- constructor(value) {
164
- this.termType = "Variable";
165
- this.value = value;
166
- }
167
- equals(other) {
168
- return !!other && other.termType === "Variable" && other.value === this.value;
169
- }
170
- };
171
- exports2.Variable = Variable;
172
- }
173
- });
174
-
175
- // ../../node_modules/rdf-data-factory/lib/DataFactory.js
176
- var require_DataFactory = __commonJS({
177
- "../../node_modules/rdf-data-factory/lib/DataFactory.js"(exports2) {
178
- "use strict";
179
- Object.defineProperty(exports2, "__esModule", { value: true });
180
- exports2.DataFactory = void 0;
181
- var BlankNode_1 = require_BlankNode();
182
- var DefaultGraph_1 = require_DefaultGraph();
183
- var Literal_1 = require_Literal();
184
- var NamedNode_1 = require_NamedNode();
185
- var Quad_1 = require_Quad();
186
- var Variable_1 = require_Variable();
187
- var dataFactoryCounter = 0;
188
- var DataFactory2 = class {
189
- constructor(options) {
190
- this.blankNodeCounter = 0;
191
- options = options || {};
192
- this.blankNodePrefix = options.blankNodePrefix || `df_${dataFactoryCounter++}_`;
193
- }
194
- /**
195
- * @param value The IRI for the named node.
196
- * @return A new instance of NamedNode.
197
- * @see NamedNode
198
- */
199
- namedNode(value) {
200
- return new NamedNode_1.NamedNode(value);
201
- }
202
- /**
203
- * @param value The optional blank node identifier.
204
- * @return A new instance of BlankNode.
205
- * If the `value` parameter is undefined a new identifier
206
- * for the blank node is generated for each call.
207
- * @see BlankNode
208
- */
209
- blankNode(value) {
210
- return new BlankNode_1.BlankNode(value || `${this.blankNodePrefix}${this.blankNodeCounter++}`);
211
- }
212
- /**
213
- * @param value The literal value.
214
- * @param languageOrDatatype The optional language, datatype, or directional language.
215
- * If `languageOrDatatype` is a NamedNode,
216
- * then it is used for the value of `NamedNode.datatype`.
217
- * If `languageOrDatatype` is a NamedNode, it is used for the value
218
- * of `NamedNode.language`.
219
- * Otherwise, it is used as a directional language,
220
- * from which the language is set to `languageOrDatatype.language`
221
- * and the direction to `languageOrDatatype.direction`.
222
- * @return A new instance of Literal.
223
- * @see Literal
224
- */
225
- literal(value, languageOrDatatype) {
226
- return new Literal_1.Literal(value, languageOrDatatype);
227
- }
228
- /**
229
- * This method is optional.
230
- * @param value The variable name
231
- * @return A new instance of Variable.
232
- * @see Variable
233
- */
234
- variable(value) {
235
- return new Variable_1.Variable(value);
236
- }
237
- /**
238
- * @return An instance of DefaultGraph.
239
- */
240
- defaultGraph() {
241
- return DefaultGraph_1.DefaultGraph.INSTANCE;
242
- }
243
- /**
244
- * @param subject The quad subject term.
245
- * @param predicate The quad predicate term.
246
- * @param object The quad object term.
247
- * @param graph The quad graph term.
248
- * @return A new instance of Quad.
249
- * @see Quad
250
- */
251
- quad(subject, predicate, object, graph) {
252
- return new Quad_1.Quad(subject, predicate, object, graph || this.defaultGraph());
253
- }
254
- /**
255
- * Create a deep copy of the given term using this data factory.
256
- * @param original An RDF term.
257
- * @return A deep copy of the given term.
258
- */
259
- fromTerm(original) {
260
- switch (original.termType) {
261
- case "NamedNode":
262
- return this.namedNode(original.value);
263
- case "BlankNode":
264
- return this.blankNode(original.value);
265
- case "Literal":
266
- if (original.language) {
267
- return this.literal(original.value, original.language);
268
- }
269
- if (!original.datatype.equals(Literal_1.Literal.XSD_STRING)) {
270
- return this.literal(original.value, this.fromTerm(original.datatype));
271
- }
272
- return this.literal(original.value);
273
- case "Variable":
274
- return this.variable(original.value);
275
- case "DefaultGraph":
276
- return this.defaultGraph();
277
- case "Quad":
278
- return this.quad(this.fromTerm(original.subject), this.fromTerm(original.predicate), this.fromTerm(original.object), this.fromTerm(original.graph));
279
- }
280
- }
281
- /**
282
- * Create a deep copy of the given quad using this data factory.
283
- * @param original An RDF quad.
284
- * @return A deep copy of the given quad.
285
- */
286
- fromQuad(original) {
287
- return this.fromTerm(original);
288
- }
289
- /**
290
- * Reset the internal blank node counter.
291
- */
292
- resetBlankNodeCounter() {
293
- this.blankNodeCounter = 0;
294
- }
295
- };
296
- exports2.DataFactory = DataFactory2;
297
- }
298
- });
299
-
300
- // ../../node_modules/rdf-data-factory/index.js
301
- var require_rdf_data_factory = __commonJS({
302
- "../../node_modules/rdf-data-factory/index.js"(exports2) {
303
- "use strict";
304
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
305
- if (k2 === void 0) k2 = k;
306
- var desc = Object.getOwnPropertyDescriptor(m, k);
307
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
308
- desc = { enumerable: true, get: function() {
309
- return m[k];
310
- } };
311
- }
312
- Object.defineProperty(o, k2, desc);
313
- } : function(o, m, k, k2) {
314
- if (k2 === void 0) k2 = k;
315
- o[k2] = m[k];
316
- });
317
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
318
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
319
- };
320
- Object.defineProperty(exports2, "__esModule", { value: true });
321
- __exportStar(require_BlankNode(), exports2);
322
- __exportStar(require_DataFactory(), exports2);
323
- __exportStar(require_DefaultGraph(), exports2);
324
- __exportStar(require_Literal(), exports2);
325
- __exportStar(require_NamedNode(), exports2);
326
- __exportStar(require_Quad(), exports2);
327
- __exportStar(require_Variable(), exports2);
328
- }
329
- });
330
-
331
20
  // lib/index.ts
332
21
  var index_exports = {};
333
22
  __export(index_exports, {
@@ -1706,8 +1395,8 @@ var Promise2 = getNative_default(root_default, "Promise");
1706
1395
  var Promise_default = Promise2;
1707
1396
 
1708
1397
  // ../../node_modules/lodash-es/_Set.js
1709
- var Set2 = getNative_default(root_default, "Set");
1710
- var Set_default = Set2;
1398
+ var Set = getNative_default(root_default, "Set");
1399
+ var Set_default = Set;
1711
1400
 
1712
1401
  // ../../node_modules/lodash-es/_getTag.js
1713
1402
  var mapTag2 = "[object Map]";
@@ -9560,7 +9249,6 @@ var EmbeddedActionsParser = class extends Parser {
9560
9249
  };
9561
9250
 
9562
9251
  // lib/grammar-builder/parserBuilder.ts
9563
- var import_rdf_data_factory = __toESM(require_rdf_data_factory(), 1);
9564
9252
  function listToRuleDefMap(rules) {
9565
9253
  const newRules = {};
9566
9254
  for (const rule of rules) {
@@ -9570,7 +9258,7 @@ function listToRuleDefMap(rules) {
9570
9258
  }
9571
9259
  var Builder = class _Builder {
9572
9260
  /**
9573
- * Create a builder with from some initial grammar rules or an existing builder.
9261
+ * Create a builder from some initial grammar rules or an existing builder.
9574
9262
  * If a builder is provided, a new copy will be created.
9575
9263
  */
9576
9264
  static createBuilder(start) {
@@ -9612,10 +9300,20 @@ var Builder = class _Builder {
9612
9300
  this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
9613
9301
  return this;
9614
9302
  }
9303
+ /**
9304
+ * Delete a grammar rule by its name.
9305
+ */
9615
9306
  deleteRule(ruleName) {
9616
9307
  delete this.rules[ruleName];
9617
9308
  return this;
9618
9309
  }
9310
+ /**
9311
+ * Merge this grammar builder with another.
9312
+ * It is best to merge the bigger grammar with the smaller one.
9313
+ * If the two builders both have a grammar rule with the same name, no error will be thrown case they map to the same ruledef object.
9314
+ * If they map to a different object, an error will be thrown.
9315
+ * To fix this problem, the overridingRules array should contain a rule with the same conflicting name, this rule implementation will be used.
9316
+ */
9619
9317
  merge(builder, overridingRules) {
9620
9318
  const otherRules = { ...builder.rules };
9621
9319
  const myRules = this.rules;
@@ -9637,7 +9335,7 @@ var Builder = class _Builder {
9637
9335
  this.rules = otherRules;
9638
9336
  return this;
9639
9337
  }
9640
- consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }, context = {}) {
9338
+ consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }) {
9641
9339
  const lexer = new Lexer(tokenVocabulary, {
9642
9340
  positionTracking: "onlyStart",
9643
9341
  recoveryEnabled: false,
@@ -9646,10 +9344,10 @@ var Builder = class _Builder {
9646
9344
  ensureOptimizations: true,
9647
9345
  ...lexerConfig
9648
9346
  });
9649
- const parser = this.consume({ tokenVocabulary, config: parserConfig }, context);
9347
+ const parser = this.consume({ tokenVocabulary, config: parserConfig });
9650
9348
  const selfSufficientParser = {};
9651
9349
  for (const rule of Object.values(this.rules)) {
9652
- selfSufficientParser[rule.name] = (input, arg) => {
9350
+ selfSufficientParser[rule.name] = (input, context, arg) => {
9653
9351
  input = input.replaceAll(
9654
9352
  /\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
9655
9353
  (_, unicode4, unicode8) => {
@@ -9669,9 +9367,9 @@ var Builder = class _Builder {
9669
9367
  throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
9670
9368
  }
9671
9369
  const lexResult = lexer.tokenize(input);
9672
- parser.reset();
9673
9370
  parser.input = lexResult.tokens;
9674
- const result = parser[rule.name](arg);
9371
+ parser.setContext(context);
9372
+ const result = parser[rule.name](context, arg);
9675
9373
  if (parser.errors.length > 0) {
9676
9374
  throw new Error(`Parse error on line ${parser.errors.map((x) => x.token.startLine).join(", ")}
9677
9375
  ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
@@ -9681,9 +9379,18 @@ ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
9681
9379
  }
9682
9380
  return selfSufficientParser;
9683
9381
  }
9684
- consume({ tokenVocabulary, config = {} }, context = {}) {
9382
+ consume({ tokenVocabulary, config = {} }) {
9685
9383
  const rules = this.rules;
9686
9384
  class MyParser extends EmbeddedActionsParser {
9385
+ getSafeContext() {
9386
+ if (this.context === void 0) {
9387
+ throw new Error("context was not correctly set");
9388
+ }
9389
+ return this.context;
9390
+ }
9391
+ setContext(context) {
9392
+ this.context = context;
9393
+ }
9687
9394
  constructor() {
9688
9395
  super(tokenVocabulary, {
9689
9396
  // RecoveryEnabled: true,
@@ -9691,42 +9398,21 @@ ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
9691
9398
  // SkipValidations: true,
9692
9399
  ...config
9693
9400
  });
9401
+ this.context = void 0;
9694
9402
  const selfRef = this.getSelfRef();
9695
- this.initialParseContext = {
9696
- dataFactory: new import_rdf_data_factory.DataFactory({ blankNodePrefix: "g_" }),
9697
- baseIRI: void 0,
9698
- parseMode: /* @__PURE__ */ new Set(),
9699
- skipValidation: false,
9700
- ...context,
9701
- prefixes: context.prefixes ? { ...context.prefixes } : {}
9702
- };
9703
- this.runningContext = {
9704
- ...this.initialParseContext,
9705
- prefixes: { ...this.initialParseContext.prefixes },
9706
- parseMode: new Set(this.initialParseContext.parseMode)
9707
- };
9708
9403
  const implArgs = {
9709
9404
  ...selfRef,
9710
- cache: /* @__PURE__ */ new WeakMap(),
9711
- context: this.runningContext
9405
+ cache: /* @__PURE__ */ new WeakMap()
9712
9406
  };
9713
9407
  for (const rule of Object.values(rules)) {
9714
9408
  this[rule.name] = this.RULE(rule.name, rule.impl(implArgs));
9715
9409
  }
9716
9410
  this.performSelfAnalysis();
9717
9411
  }
9718
- reset() {
9719
- super.reset();
9720
- Object.assign(this.runningContext, {
9721
- ...this.initialParseContext
9722
- });
9723
- this.runningContext.prefixes = { ...this.initialParseContext.prefixes };
9724
- this.runningContext.parseMode = new Set(this.initialParseContext.parseMode);
9725
- }
9726
9412
  getSelfRef() {
9727
- const subRuleImpl = (subrule) => {
9728
- return (cstDef, ...args) => {
9729
- return subrule(this[cstDef.name], { ARGS: args });
9413
+ const subRuleImpl = (chevrotainSubrule) => {
9414
+ return (cstDef, arg) => {
9415
+ return chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] });
9730
9416
  };
9731
9417
  };
9732
9418
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@traqula/core",
3
- "version": "0.0.1-alpha.145+b7fd73e",
3
+ "version": "0.0.1-alpha.148+1455821",
4
4
  "description": "Core components of TRAQULA",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -38,12 +38,10 @@
38
38
  "build:transpile": "node \"../../node_modules/esbuild/bin/esbuild\" --format=cjs --bundle --log-level=error --outfile=lib/index.cjs lib/index.ts"
39
39
  },
40
40
  "dependencies": {
41
- "chevrotain": "^11.0.3",
42
- "rdf-data-factory": "^2.0.1"
41
+ "chevrotain": "^11.0.3"
43
42
  },
44
43
  "devDependencies": {
45
- "@chevrotain/types": "^11.0.3",
46
- "@rdfjs/types": "^2.0.0"
44
+ "@chevrotain/types": "^11.0.3"
47
45
  },
48
- "gitHead": "b7fd73efdfc32dec46beaa040431ba031a723b53"
46
+ "gitHead": "14558218b5c59739a791015d2bfbb466c5da9e62"
49
47
  }