likec4 1.48.0 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/__app__/src/likec4.js +5595 -4127
- package/__app__/src/routes/index.js +3 -153
- package/__app__/src/routes/projects.js +21 -1087
- package/__app__/src/routes/single.js +1221 -16
- package/__app__/src/style.css +1 -1
- package/__app__/src/vendors.js +3507 -894
- package/__app__/src/webcomponent.js +1 -1
- package/config/schema.json +155 -143
- package/dist/THIRD-PARTY-LICENSES.md +1739 -0
- package/dist/_chunks/GraphvizBinaryAdapter.mjs +72 -0
- package/dist/_chunks/filenames.mjs +14 -0
- package/dist/_chunks/index.d.mts +224 -129
- package/dist/_chunks/index2.d.mts +2033 -1908
- package/dist/_chunks/libs/@chevrotain/gast.mjs +1 -3969
- package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
- package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
- package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
- package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
- package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
- package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
- package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +14 -14
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
- package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
- package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
- package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
- package/dist/_chunks/libs/ajv.mjs +1 -777
- package/dist/_chunks/libs/atomically.mjs +1 -362
- package/dist/_chunks/libs/birpc.mjs +1 -201
- package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
- package/dist/_chunks/libs/chevrotain.mjs +55 -6229
- package/dist/_chunks/libs/conf.mjs +1 -2258
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/esm-env.mjs +1 -5
- package/dist/_chunks/libs/eventemitter3.mjs +1 -243
- package/dist/_chunks/libs/fast-equals.mjs +1 -446
- package/dist/_chunks/libs/find-up-simple.mjs +1 -24
- package/dist/_chunks/libs/get-port.mjs +1 -107
- package/dist/_chunks/libs/is-docker.mjs +1 -26
- package/dist/_chunks/libs/is-error-instance.mjs +1 -26
- package/dist/_chunks/libs/is-inside-container.mjs +1 -20
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/isexe.mjs +1 -127
- package/dist/_chunks/libs/json5.mjs +14 -959
- package/dist/_chunks/libs/khroma.mjs +1 -605
- package/dist/_chunks/libs/ky.mjs +2 -807
- package/dist/_chunks/libs/langium.d.mts +2880 -2844
- package/dist/_chunks/libs/langium.mjs +32 -20351
- package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
- package/dist/_chunks/libs/nanostores.mjs +1 -198
- package/dist/_chunks/libs/p-limit.mjs +1 -120
- package/dist/_chunks/libs/p-queue.mjs +1 -449
- package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
- package/dist/_chunks/libs/package-up.mjs +1 -10
- package/dist/_chunks/libs/parse-ms.mjs +1 -36
- package/dist/_chunks/libs/pathe.mjs +1 -0
- package/dist/_chunks/libs/picomatch.mjs +1 -1673
- package/dist/_chunks/libs/pretty-ms.mjs +1 -80
- package/dist/_chunks/libs/remeda.mjs +1 -690
- package/dist/_chunks/libs/safe-stringify.mjs +1 -21
- package/dist/_chunks/libs/strip-indent.mjs +1 -15
- package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
- package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
- package/dist/_chunks/libs/ufo.mjs +1 -240
- package/dist/_chunks/libs/which.mjs +1 -84
- package/dist/_chunks/libs/word-wrap.mjs +12 -43
- package/dist/_chunks/node.mjs +481 -0
- package/dist/_chunks/plugin.mjs +98 -772
- package/dist/_chunks/rolldown-runtime.mjs +1 -48
- package/dist/_chunks/sequence-view.mjs +1 -575
- package/dist/cli/index.mjs +127 -1846
- package/dist/config/index.d.mts +2 -2
- package/dist/config/index.mjs +1 -6
- package/dist/index.d.mts +148 -7
- package/dist/index.mjs +1 -21
- package/dist/model/builder.mjs +1 -3
- package/dist/model/index.d.mts +57 -3
- package/dist/model/index.mjs +1 -5
- package/dist/vite-plugin/index.d.mts +4 -3
- package/dist/vite-plugin/index.mjs +1 -22
- package/dist/vite-plugin/internal.d.mts +5 -5
- package/dist/vite-plugin/internal.mjs +1 -68
- package/package.json +60 -41
- package/react/{index.d.ts → index.d.mts} +112 -70
- package/react/{index.js → index.mjs} +21361 -22064
- package/react/package.json +2 -5
- package/vite-plugin-modules.d.ts +5 -5
- package/dist/_chunks/LikeC4.d.mts +0 -121
- package/dist/_chunks/LikeC4.mjs +0 -202
- package/dist/_chunks/config-app.prod.d.mts +0 -18
- package/dist/_chunks/config-app.prod.mjs +0 -188
- package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
- package/dist/_chunks/define-config.mjs +0 -409
- package/dist/_chunks/index3.d.mts +0 -60
- package/dist/_chunks/index4.d.mts +0 -1
- package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +0 -10
- package/dist/_chunks/libs/hono.mjs +0 -1829
- package/dist/_chunks/libs/nanoid.mjs +0 -29
- package/dist/_chunks/model.mjs +0 -12
- package/dist/_chunks/module.d.mts +0 -71
- package/dist/_chunks/module.mjs +0 -18657
- package/dist/_chunks/vite-build.mjs +0 -69
- package/dist/_chunks/vite-dev.mjs +0 -79
- package/dist/_chunks/vite-preview.mjs +0 -27
- package/dist/language/module.d.mts +0 -5
- package/dist/language/module.mjs +0 -20
- package/dist/vite/vite-build.d.mts +0 -26
- package/dist/vite/vite-build.mjs +0 -27
- package/dist/vite/vite-dev.d.mts +0 -34
- package/dist/vite/vite-dev.mjs +0 -29
- package/dist/vite/vite-preview.d.mts +0 -20
- package/dist/vite/vite-preview.mjs +0 -26
|
@@ -1,850 +1,2 @@
|
|
|
1
|
-
import { C as map_default, D as _baseIteratee_default, T as forEach_default, c as NonTerminal, d as RepetitionMandatory, f as RepetitionMandatoryWithSeparator, h as Terminal, ht as isSymbol_default, l as Option, o as Alternation, p as RepetitionWithSeparator, u as Repetition, ut as identity_default } from "./@chevrotain/gast.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseLt.js
|
|
5
|
-
/**
|
|
6
|
-
* The base implementation of `_.lt` which doesn't coerce arguments.
|
|
7
|
-
*
|
|
8
|
-
* @private
|
|
9
|
-
* @param {*} value The value to compare.
|
|
10
|
-
* @param {*} other The other value to compare.
|
|
11
|
-
* @returns {boolean} Returns `true` if `value` is less than `other`,
|
|
12
|
-
* else `false`.
|
|
13
|
-
*/
|
|
14
|
-
function baseLt(value, other) {
|
|
15
|
-
return value < other;
|
|
16
|
-
}
|
|
17
|
-
var _baseLt_default = baseLt;
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseExtremum.js
|
|
21
|
-
/**
|
|
22
|
-
* The base implementation of methods like `_.max` and `_.min` which accepts a
|
|
23
|
-
* `comparator` to determine the extremum value.
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
26
|
-
* @param {Array} array The array to iterate over.
|
|
27
|
-
* @param {Function} iteratee The iteratee invoked per iteration.
|
|
28
|
-
* @param {Function} comparator The comparator used to compare values.
|
|
29
|
-
* @returns {*} Returns the extremum value.
|
|
30
|
-
*/
|
|
31
|
-
function baseExtremum(array, iteratee, comparator) {
|
|
32
|
-
var index = -1, length = array.length;
|
|
33
|
-
while (++index < length) {
|
|
34
|
-
var value = array[index], current = iteratee(value);
|
|
35
|
-
if (current != null && (computed === void 0 ? current === current && !isSymbol_default(current) : comparator(current, computed))) var computed = current, result = value;
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
var _baseExtremum_default = baseExtremum;
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/min.js
|
|
43
|
-
/**
|
|
44
|
-
* Computes the minimum value of `array`. If `array` is empty or falsey,
|
|
45
|
-
* `undefined` is returned.
|
|
46
|
-
*
|
|
47
|
-
* @static
|
|
48
|
-
* @since 0.1.0
|
|
49
|
-
* @memberOf _
|
|
50
|
-
* @category Math
|
|
51
|
-
* @param {Array} array The array to iterate over.
|
|
52
|
-
* @returns {*} Returns the minimum value.
|
|
53
|
-
* @example
|
|
54
|
-
*
|
|
55
|
-
* _.min([4, 2, 8, 6]);
|
|
56
|
-
* // => 2
|
|
57
|
-
*
|
|
58
|
-
* _.min([]);
|
|
59
|
-
* // => undefined
|
|
60
|
-
*/
|
|
61
|
-
function min(array) {
|
|
62
|
-
return array && array.length ? _baseExtremum_default(array, identity_default, _baseLt_default) : void 0;
|
|
63
|
-
}
|
|
64
|
-
var min_default = min;
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/uniqBy.js
|
|
68
|
-
/**
|
|
69
|
-
* This method is like `_.uniq` except that it accepts `iteratee` which is
|
|
70
|
-
* invoked for each element in `array` to generate the criterion by which
|
|
71
|
-
* uniqueness is computed. The order of result values is determined by the
|
|
72
|
-
* order they occur in the array. The iteratee is invoked with one argument:
|
|
73
|
-
* (value).
|
|
74
|
-
*
|
|
75
|
-
* @static
|
|
76
|
-
* @memberOf _
|
|
77
|
-
* @since 4.0.0
|
|
78
|
-
* @category Array
|
|
79
|
-
* @param {Array} array The array to inspect.
|
|
80
|
-
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|
81
|
-
* @returns {Array} Returns the new duplicate free array.
|
|
82
|
-
* @example
|
|
83
|
-
*
|
|
84
|
-
* _.uniqBy([2.1, 1.2, 2.3], Math.floor);
|
|
85
|
-
* // => [2.1, 1.2]
|
|
86
|
-
*
|
|
87
|
-
* // The `_.property` iteratee shorthand.
|
|
88
|
-
* _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
|
89
|
-
* // => [{ 'x': 1 }, { 'x': 2 }]
|
|
90
|
-
*/
|
|
91
|
-
function uniqBy(array, iteratee) {
|
|
92
|
-
return array && array.length ? _baseUniq_default(array, _baseIteratee_default(iteratee, 2)) : [];
|
|
93
|
-
}
|
|
94
|
-
var uniqBy_default = uniqBy;
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region ../../node_modules/.pnpm/chevrotain-allstar@0.3.1_chevrotain@11.0.3/node_modules/chevrotain-allstar/lib/atn.js
|
|
98
|
-
/******************************************************************************
|
|
99
|
-
* Copyright 2022 TypeFox GmbH
|
|
100
|
-
* This program and the accompanying materials are made available under the
|
|
101
|
-
* terms of the MIT License, which is available in the project root.
|
|
102
|
-
******************************************************************************/
|
|
103
|
-
function buildATNKey(rule, type, occurrence) {
|
|
104
|
-
return `${rule.name}_${type}_${occurrence}`;
|
|
105
|
-
}
|
|
106
|
-
const ATN_BASIC = 1;
|
|
107
|
-
const ATN_RULE_START = 2;
|
|
108
|
-
const ATN_PLUS_BLOCK_START = 4;
|
|
109
|
-
const ATN_STAR_BLOCK_START = 5;
|
|
110
|
-
const ATN_RULE_STOP = 7;
|
|
111
|
-
const ATN_BLOCK_END = 8;
|
|
112
|
-
const ATN_STAR_LOOP_BACK = 9;
|
|
113
|
-
const ATN_STAR_LOOP_ENTRY = 10;
|
|
114
|
-
const ATN_PLUS_LOOP_BACK = 11;
|
|
115
|
-
const ATN_LOOP_END = 12;
|
|
116
|
-
var AbstractTransition = class {
|
|
117
|
-
constructor(target) {
|
|
118
|
-
this.target = target;
|
|
119
|
-
}
|
|
120
|
-
isEpsilon() {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var AtomTransition = class extends AbstractTransition {
|
|
125
|
-
constructor(target, tokenType) {
|
|
126
|
-
super(target);
|
|
127
|
-
this.tokenType = tokenType;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
var EpsilonTransition = class extends AbstractTransition {
|
|
131
|
-
constructor(target) {
|
|
132
|
-
super(target);
|
|
133
|
-
}
|
|
134
|
-
isEpsilon() {
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var RuleTransition = class extends AbstractTransition {
|
|
139
|
-
constructor(ruleStart, rule, followState) {
|
|
140
|
-
super(ruleStart);
|
|
141
|
-
this.rule = rule;
|
|
142
|
-
this.followState = followState;
|
|
143
|
-
}
|
|
144
|
-
isEpsilon() {
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
function createATN(rules) {
|
|
149
|
-
const atn = {
|
|
150
|
-
decisionMap: {},
|
|
151
|
-
decisionStates: [],
|
|
152
|
-
ruleToStartState: /* @__PURE__ */ new Map(),
|
|
153
|
-
ruleToStopState: /* @__PURE__ */ new Map(),
|
|
154
|
-
states: []
|
|
155
|
-
};
|
|
156
|
-
createRuleStartAndStopATNStates(atn, rules);
|
|
157
|
-
const ruleLength = rules.length;
|
|
158
|
-
for (let i = 0; i < ruleLength; i++) {
|
|
159
|
-
const rule = rules[i];
|
|
160
|
-
const ruleBlock = block(atn, rule, rule);
|
|
161
|
-
if (ruleBlock === void 0) continue;
|
|
162
|
-
buildRuleHandle(atn, rule, ruleBlock);
|
|
163
|
-
}
|
|
164
|
-
return atn;
|
|
165
|
-
}
|
|
166
|
-
function createRuleStartAndStopATNStates(atn, rules) {
|
|
167
|
-
const ruleLength = rules.length;
|
|
168
|
-
for (let i = 0; i < ruleLength; i++) {
|
|
169
|
-
const rule = rules[i];
|
|
170
|
-
const start = newState(atn, rule, void 0, { type: ATN_RULE_START });
|
|
171
|
-
const stop = newState(atn, rule, void 0, { type: ATN_RULE_STOP });
|
|
172
|
-
start.stop = stop;
|
|
173
|
-
atn.ruleToStartState.set(rule, start);
|
|
174
|
-
atn.ruleToStopState.set(rule, stop);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function atom(atn, rule, production) {
|
|
178
|
-
if (production instanceof Terminal) return tokenRef(atn, rule, production.terminalType, production);
|
|
179
|
-
else if (production instanceof NonTerminal) return ruleRef(atn, rule, production);
|
|
180
|
-
else if (production instanceof Alternation) return alternation(atn, rule, production);
|
|
181
|
-
else if (production instanceof Option) return option(atn, rule, production);
|
|
182
|
-
else if (production instanceof Repetition) return repetition(atn, rule, production);
|
|
183
|
-
else if (production instanceof RepetitionWithSeparator) return repetitionSep(atn, rule, production);
|
|
184
|
-
else if (production instanceof RepetitionMandatory) return repetitionMandatory(atn, rule, production);
|
|
185
|
-
else if (production instanceof RepetitionMandatoryWithSeparator) return repetitionMandatorySep(atn, rule, production);
|
|
186
|
-
else return block(atn, rule, production);
|
|
187
|
-
}
|
|
188
|
-
function repetition(atn, rule, repetition) {
|
|
189
|
-
const starState = newState(atn, rule, repetition, { type: ATN_STAR_BLOCK_START });
|
|
190
|
-
defineDecisionState(atn, starState);
|
|
191
|
-
return star(atn, rule, repetition, makeAlts(atn, rule, starState, repetition, block(atn, rule, repetition)));
|
|
192
|
-
}
|
|
193
|
-
function repetitionSep(atn, rule, repetition) {
|
|
194
|
-
const starState = newState(atn, rule, repetition, { type: ATN_STAR_BLOCK_START });
|
|
195
|
-
defineDecisionState(atn, starState);
|
|
196
|
-
return star(atn, rule, repetition, makeAlts(atn, rule, starState, repetition, block(atn, rule, repetition)), tokenRef(atn, rule, repetition.separator, repetition));
|
|
197
|
-
}
|
|
198
|
-
function repetitionMandatory(atn, rule, repetition) {
|
|
199
|
-
const plusState = newState(atn, rule, repetition, { type: ATN_PLUS_BLOCK_START });
|
|
200
|
-
defineDecisionState(atn, plusState);
|
|
201
|
-
return plus(atn, rule, repetition, makeAlts(atn, rule, plusState, repetition, block(atn, rule, repetition)));
|
|
202
|
-
}
|
|
203
|
-
function repetitionMandatorySep(atn, rule, repetition) {
|
|
204
|
-
const plusState = newState(atn, rule, repetition, { type: ATN_PLUS_BLOCK_START });
|
|
205
|
-
defineDecisionState(atn, plusState);
|
|
206
|
-
return plus(atn, rule, repetition, makeAlts(atn, rule, plusState, repetition, block(atn, rule, repetition)), tokenRef(atn, rule, repetition.separator, repetition));
|
|
207
|
-
}
|
|
208
|
-
function alternation(atn, rule, alternation) {
|
|
209
|
-
const start = newState(atn, rule, alternation, { type: ATN_BASIC });
|
|
210
|
-
defineDecisionState(atn, start);
|
|
211
|
-
return makeAlts(atn, rule, start, alternation, ...map_default(alternation.definition, (e) => atom(atn, rule, e)));
|
|
212
|
-
}
|
|
213
|
-
function option(atn, rule, option) {
|
|
214
|
-
const start = newState(atn, rule, option, { type: ATN_BASIC });
|
|
215
|
-
defineDecisionState(atn, start);
|
|
216
|
-
return optional(atn, rule, option, makeAlts(atn, rule, start, option, block(atn, rule, option)));
|
|
217
|
-
}
|
|
218
|
-
function block(atn, rule, block) {
|
|
219
|
-
const handles = filter_default(map_default(block.definition, (e) => atom(atn, rule, e)), (e) => e !== void 0);
|
|
220
|
-
if (handles.length === 1) return handles[0];
|
|
221
|
-
else if (handles.length === 0) return;
|
|
222
|
-
else return makeBlock(atn, handles);
|
|
223
|
-
}
|
|
224
|
-
function plus(atn, rule, plus, handle, sep) {
|
|
225
|
-
const blkStart = handle.left;
|
|
226
|
-
const blkEnd = handle.right;
|
|
227
|
-
const loop = newState(atn, rule, plus, { type: ATN_PLUS_LOOP_BACK });
|
|
228
|
-
defineDecisionState(atn, loop);
|
|
229
|
-
const end = newState(atn, rule, plus, { type: ATN_LOOP_END });
|
|
230
|
-
blkStart.loopback = loop;
|
|
231
|
-
end.loopback = loop;
|
|
232
|
-
atn.decisionMap[buildATNKey(rule, sep ? "RepetitionMandatoryWithSeparator" : "RepetitionMandatory", plus.idx)] = loop;
|
|
233
|
-
epsilon(blkEnd, loop);
|
|
234
|
-
if (sep === void 0) {
|
|
235
|
-
epsilon(loop, blkStart);
|
|
236
|
-
epsilon(loop, end);
|
|
237
|
-
} else {
|
|
238
|
-
epsilon(loop, end);
|
|
239
|
-
epsilon(loop, sep.left);
|
|
240
|
-
epsilon(sep.right, blkStart);
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
left: blkStart,
|
|
244
|
-
right: end
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function star(atn, rule, star, handle, sep) {
|
|
248
|
-
const start = handle.left;
|
|
249
|
-
const end = handle.right;
|
|
250
|
-
const entry = newState(atn, rule, star, { type: ATN_STAR_LOOP_ENTRY });
|
|
251
|
-
defineDecisionState(atn, entry);
|
|
252
|
-
const loopEnd = newState(atn, rule, star, { type: ATN_LOOP_END });
|
|
253
|
-
const loop = newState(atn, rule, star, { type: ATN_STAR_LOOP_BACK });
|
|
254
|
-
entry.loopback = loop;
|
|
255
|
-
loopEnd.loopback = loop;
|
|
256
|
-
epsilon(entry, start);
|
|
257
|
-
epsilon(entry, loopEnd);
|
|
258
|
-
epsilon(end, loop);
|
|
259
|
-
if (sep !== void 0) {
|
|
260
|
-
epsilon(loop, loopEnd);
|
|
261
|
-
epsilon(loop, sep.left);
|
|
262
|
-
epsilon(sep.right, start);
|
|
263
|
-
} else epsilon(loop, entry);
|
|
264
|
-
atn.decisionMap[buildATNKey(rule, sep ? "RepetitionWithSeparator" : "Repetition", star.idx)] = entry;
|
|
265
|
-
return {
|
|
266
|
-
left: entry,
|
|
267
|
-
right: loopEnd
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
function optional(atn, rule, optional, handle) {
|
|
271
|
-
const start = handle.left;
|
|
272
|
-
const end = handle.right;
|
|
273
|
-
epsilon(start, end);
|
|
274
|
-
atn.decisionMap[buildATNKey(rule, "Option", optional.idx)] = start;
|
|
275
|
-
return handle;
|
|
276
|
-
}
|
|
277
|
-
function defineDecisionState(atn, state) {
|
|
278
|
-
atn.decisionStates.push(state);
|
|
279
|
-
state.decision = atn.decisionStates.length - 1;
|
|
280
|
-
return state.decision;
|
|
281
|
-
}
|
|
282
|
-
function makeAlts(atn, rule, start, production, ...alts) {
|
|
283
|
-
const end = newState(atn, rule, production, {
|
|
284
|
-
type: ATN_BLOCK_END,
|
|
285
|
-
start
|
|
286
|
-
});
|
|
287
|
-
start.end = end;
|
|
288
|
-
for (const alt of alts) if (alt !== void 0) {
|
|
289
|
-
epsilon(start, alt.left);
|
|
290
|
-
epsilon(alt.right, end);
|
|
291
|
-
} else epsilon(start, end);
|
|
292
|
-
const handle = {
|
|
293
|
-
left: start,
|
|
294
|
-
right: end
|
|
295
|
-
};
|
|
296
|
-
atn.decisionMap[buildATNKey(rule, getProdType(production), production.idx)] = start;
|
|
297
|
-
return handle;
|
|
298
|
-
}
|
|
299
|
-
function getProdType(production) {
|
|
300
|
-
if (production instanceof Alternation) return "Alternation";
|
|
301
|
-
else if (production instanceof Option) return "Option";
|
|
302
|
-
else if (production instanceof Repetition) return "Repetition";
|
|
303
|
-
else if (production instanceof RepetitionWithSeparator) return "RepetitionWithSeparator";
|
|
304
|
-
else if (production instanceof RepetitionMandatory) return "RepetitionMandatory";
|
|
305
|
-
else if (production instanceof RepetitionMandatoryWithSeparator) return "RepetitionMandatoryWithSeparator";
|
|
306
|
-
else throw new Error("Invalid production type encountered");
|
|
307
|
-
}
|
|
308
|
-
function makeBlock(atn, alts) {
|
|
309
|
-
const altsLength = alts.length;
|
|
310
|
-
for (let i = 0; i < altsLength - 1; i++) {
|
|
311
|
-
const handle = alts[i];
|
|
312
|
-
let transition;
|
|
313
|
-
if (handle.left.transitions.length === 1) transition = handle.left.transitions[0];
|
|
314
|
-
const isRuleTransition = transition instanceof RuleTransition;
|
|
315
|
-
const ruleTransition = transition;
|
|
316
|
-
const next = alts[i + 1].left;
|
|
317
|
-
if (handle.left.type === ATN_BASIC && handle.right.type === ATN_BASIC && transition !== void 0 && (isRuleTransition && ruleTransition.followState === handle.right || transition.target === handle.right)) {
|
|
318
|
-
if (isRuleTransition) ruleTransition.followState = next;
|
|
319
|
-
else transition.target = next;
|
|
320
|
-
removeState(atn, handle.right);
|
|
321
|
-
} else epsilon(handle.right, next);
|
|
322
|
-
}
|
|
323
|
-
const first = alts[0];
|
|
324
|
-
const last = alts[altsLength - 1];
|
|
325
|
-
return {
|
|
326
|
-
left: first.left,
|
|
327
|
-
right: last.right
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
function tokenRef(atn, rule, tokenType, production) {
|
|
331
|
-
const left = newState(atn, rule, production, { type: ATN_BASIC });
|
|
332
|
-
const right = newState(atn, rule, production, { type: ATN_BASIC });
|
|
333
|
-
addTransition(left, new AtomTransition(right, tokenType));
|
|
334
|
-
return {
|
|
335
|
-
left,
|
|
336
|
-
right
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
function ruleRef(atn, currentRule, nonTerminal) {
|
|
340
|
-
const rule = nonTerminal.referencedRule;
|
|
341
|
-
const start = atn.ruleToStartState.get(rule);
|
|
342
|
-
const left = newState(atn, currentRule, nonTerminal, { type: ATN_BASIC });
|
|
343
|
-
const right = newState(atn, currentRule, nonTerminal, { type: ATN_BASIC });
|
|
344
|
-
addTransition(left, new RuleTransition(start, rule, right));
|
|
345
|
-
return {
|
|
346
|
-
left,
|
|
347
|
-
right
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
function buildRuleHandle(atn, rule, block) {
|
|
351
|
-
const start = atn.ruleToStartState.get(rule);
|
|
352
|
-
epsilon(start, block.left);
|
|
353
|
-
const stop = atn.ruleToStopState.get(rule);
|
|
354
|
-
epsilon(block.right, stop);
|
|
355
|
-
return {
|
|
356
|
-
left: start,
|
|
357
|
-
right: stop
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
function epsilon(a, b) {
|
|
361
|
-
addTransition(a, new EpsilonTransition(b));
|
|
362
|
-
}
|
|
363
|
-
function newState(atn, rule, production, partial) {
|
|
364
|
-
const t = Object.assign({
|
|
365
|
-
atn,
|
|
366
|
-
production,
|
|
367
|
-
epsilonOnlyTransitions: false,
|
|
368
|
-
rule,
|
|
369
|
-
transitions: [],
|
|
370
|
-
nextTokenWithinRule: [],
|
|
371
|
-
stateNumber: atn.states.length
|
|
372
|
-
}, partial);
|
|
373
|
-
atn.states.push(t);
|
|
374
|
-
return t;
|
|
375
|
-
}
|
|
376
|
-
function addTransition(state, transition) {
|
|
377
|
-
if (state.transitions.length === 0) state.epsilonOnlyTransitions = transition.isEpsilon();
|
|
378
|
-
state.transitions.push(transition);
|
|
379
|
-
}
|
|
380
|
-
function removeState(atn, state) {
|
|
381
|
-
atn.states.splice(atn.states.indexOf(state), 1);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region ../../node_modules/.pnpm/chevrotain-allstar@0.3.1_chevrotain@11.0.3/node_modules/chevrotain-allstar/lib/dfa.js
|
|
386
|
-
/******************************************************************************
|
|
387
|
-
* Copyright 2022 TypeFox GmbH
|
|
388
|
-
* This program and the accompanying materials are made available under the
|
|
389
|
-
* terms of the MIT License, which is available in the project root.
|
|
390
|
-
******************************************************************************/
|
|
391
|
-
const DFA_ERROR = {};
|
|
392
|
-
var ATNConfigSet = class {
|
|
393
|
-
constructor() {
|
|
394
|
-
this.map = {};
|
|
395
|
-
this.configs = [];
|
|
396
|
-
}
|
|
397
|
-
get size() {
|
|
398
|
-
return this.configs.length;
|
|
399
|
-
}
|
|
400
|
-
finalize() {
|
|
401
|
-
this.map = {};
|
|
402
|
-
}
|
|
403
|
-
add(config) {
|
|
404
|
-
const key = getATNConfigKey(config);
|
|
405
|
-
if (!(key in this.map)) {
|
|
406
|
-
this.map[key] = this.configs.length;
|
|
407
|
-
this.configs.push(config);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
get elements() {
|
|
411
|
-
return this.configs;
|
|
412
|
-
}
|
|
413
|
-
get alts() {
|
|
414
|
-
return map_default(this.configs, (e) => e.alt);
|
|
415
|
-
}
|
|
416
|
-
get key() {
|
|
417
|
-
let value = "";
|
|
418
|
-
for (const k in this.map) value += k + ":";
|
|
419
|
-
return value;
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
function getATNConfigKey(config, alt = true) {
|
|
423
|
-
return `${alt ? `a${config.alt}` : ""}s${config.state.stateNumber}:${config.stack.map((e) => e.stateNumber.toString()).join("_")}`;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
//#endregion
|
|
427
|
-
//#region ../../node_modules/.pnpm/chevrotain-allstar@0.3.1_chevrotain@11.0.3/node_modules/chevrotain-allstar/lib/all-star-lookahead.js
|
|
428
|
-
/******************************************************************************
|
|
429
|
-
* Copyright 2022 TypeFox GmbH
|
|
430
|
-
* This program and the accompanying materials are made available under the
|
|
431
|
-
* terms of the MIT License, which is available in the project root.
|
|
432
|
-
******************************************************************************/
|
|
433
|
-
function createDFACache(startState, decision) {
|
|
434
|
-
const map = {};
|
|
435
|
-
return (predicateSet) => {
|
|
436
|
-
const key = predicateSet.toString();
|
|
437
|
-
let existing = map[key];
|
|
438
|
-
if (existing !== void 0) return existing;
|
|
439
|
-
else {
|
|
440
|
-
existing = {
|
|
441
|
-
atnStartState: startState,
|
|
442
|
-
decision,
|
|
443
|
-
states: {}
|
|
444
|
-
};
|
|
445
|
-
map[key] = existing;
|
|
446
|
-
return existing;
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
var PredicateSet = class {
|
|
451
|
-
constructor() {
|
|
452
|
-
this.predicates = [];
|
|
453
|
-
}
|
|
454
|
-
is(index) {
|
|
455
|
-
return index >= this.predicates.length || this.predicates[index];
|
|
456
|
-
}
|
|
457
|
-
set(index, value) {
|
|
458
|
-
this.predicates[index] = value;
|
|
459
|
-
}
|
|
460
|
-
toString() {
|
|
461
|
-
let value = "";
|
|
462
|
-
const size = this.predicates.length;
|
|
463
|
-
for (let i = 0; i < size; i++) value += this.predicates[i] === true ? "1" : "0";
|
|
464
|
-
return value;
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
const EMPTY_PREDICATES = new PredicateSet();
|
|
468
|
-
var LLStarLookaheadStrategy = class extends LLkLookaheadStrategy {
|
|
469
|
-
constructor(options) {
|
|
470
|
-
var _a;
|
|
471
|
-
super();
|
|
472
|
-
this.logging = (_a = options === null || options === void 0 ? void 0 : options.logging) !== null && _a !== void 0 ? _a : ((message) => console.log(message));
|
|
473
|
-
}
|
|
474
|
-
initialize(options) {
|
|
475
|
-
this.atn = createATN(options.rules);
|
|
476
|
-
this.dfas = initATNSimulator(this.atn);
|
|
477
|
-
}
|
|
478
|
-
validateAmbiguousAlternationAlternatives() {
|
|
479
|
-
return [];
|
|
480
|
-
}
|
|
481
|
-
validateEmptyOrAlternatives() {
|
|
482
|
-
return [];
|
|
483
|
-
}
|
|
484
|
-
buildLookaheadForAlternation(options) {
|
|
485
|
-
const { prodOccurrence, rule, hasPredicates, dynamicTokensEnabled } = options;
|
|
486
|
-
const dfas = this.dfas;
|
|
487
|
-
const logging = this.logging;
|
|
488
|
-
const key = buildATNKey(rule, "Alternation", prodOccurrence);
|
|
489
|
-
const decisionIndex = this.atn.decisionMap[key].decision;
|
|
490
|
-
const partialAlts = map_default(getLookaheadPaths({
|
|
491
|
-
maxLookahead: 1,
|
|
492
|
-
occurrence: prodOccurrence,
|
|
493
|
-
prodType: "Alternation",
|
|
494
|
-
rule
|
|
495
|
-
}), (currAlt) => map_default(currAlt, (path) => path[0]));
|
|
496
|
-
if (isLL1Sequence(partialAlts, false) && !dynamicTokensEnabled) {
|
|
497
|
-
const choiceToAlt = reduce_default(partialAlts, (result, currAlt, idx) => {
|
|
498
|
-
forEach_default(currAlt, (currTokType) => {
|
|
499
|
-
if (currTokType) {
|
|
500
|
-
result[currTokType.tokenTypeIdx] = idx;
|
|
501
|
-
forEach_default(currTokType.categoryMatches, (currExtendingType) => {
|
|
502
|
-
result[currExtendingType] = idx;
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
return result;
|
|
507
|
-
}, {});
|
|
508
|
-
if (hasPredicates) return function(orAlts) {
|
|
509
|
-
var _a;
|
|
510
|
-
const prediction = choiceToAlt[this.LA(1).tokenTypeIdx];
|
|
511
|
-
if (orAlts !== void 0 && prediction !== void 0) {
|
|
512
|
-
const gate = (_a = orAlts[prediction]) === null || _a === void 0 ? void 0 : _a.GATE;
|
|
513
|
-
if (gate !== void 0 && gate.call(this) === false) return;
|
|
514
|
-
}
|
|
515
|
-
return prediction;
|
|
516
|
-
};
|
|
517
|
-
else return function() {
|
|
518
|
-
return choiceToAlt[this.LA(1).tokenTypeIdx];
|
|
519
|
-
};
|
|
520
|
-
} else if (hasPredicates) return function(orAlts) {
|
|
521
|
-
const predicates = new PredicateSet();
|
|
522
|
-
const length = orAlts === void 0 ? 0 : orAlts.length;
|
|
523
|
-
for (let i = 0; i < length; i++) {
|
|
524
|
-
const gate = orAlts === null || orAlts === void 0 ? void 0 : orAlts[i].GATE;
|
|
525
|
-
predicates.set(i, gate === void 0 || gate.call(this));
|
|
526
|
-
}
|
|
527
|
-
const result = adaptivePredict.call(this, dfas, decisionIndex, predicates, logging);
|
|
528
|
-
return typeof result === "number" ? result : void 0;
|
|
529
|
-
};
|
|
530
|
-
else return function() {
|
|
531
|
-
const result = adaptivePredict.call(this, dfas, decisionIndex, EMPTY_PREDICATES, logging);
|
|
532
|
-
return typeof result === "number" ? result : void 0;
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
buildLookaheadForOptional(options) {
|
|
536
|
-
const { prodOccurrence, rule, prodType, dynamicTokensEnabled } = options;
|
|
537
|
-
const dfas = this.dfas;
|
|
538
|
-
const logging = this.logging;
|
|
539
|
-
const key = buildATNKey(rule, prodType, prodOccurrence);
|
|
540
|
-
const decisionIndex = this.atn.decisionMap[key].decision;
|
|
541
|
-
const alts = map_default(getLookaheadPaths({
|
|
542
|
-
maxLookahead: 1,
|
|
543
|
-
occurrence: prodOccurrence,
|
|
544
|
-
prodType,
|
|
545
|
-
rule
|
|
546
|
-
}), (e) => {
|
|
547
|
-
return map_default(e, (g) => g[0]);
|
|
548
|
-
});
|
|
549
|
-
if (isLL1Sequence(alts) && alts[0][0] && !dynamicTokensEnabled) {
|
|
550
|
-
const alt = alts[0];
|
|
551
|
-
const singleTokensTypes = flatten_default(alt);
|
|
552
|
-
if (singleTokensTypes.length === 1 && isEmpty_default(singleTokensTypes[0].categoryMatches)) {
|
|
553
|
-
const expectedTokenUniqueKey = singleTokensTypes[0].tokenTypeIdx;
|
|
554
|
-
return function() {
|
|
555
|
-
return this.LA(1).tokenTypeIdx === expectedTokenUniqueKey;
|
|
556
|
-
};
|
|
557
|
-
} else {
|
|
558
|
-
const choiceToAlt = reduce_default(singleTokensTypes, (result, currTokType) => {
|
|
559
|
-
if (currTokType !== void 0) {
|
|
560
|
-
result[currTokType.tokenTypeIdx] = true;
|
|
561
|
-
forEach_default(currTokType.categoryMatches, (currExtendingType) => {
|
|
562
|
-
result[currExtendingType] = true;
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
return result;
|
|
566
|
-
}, {});
|
|
567
|
-
return function() {
|
|
568
|
-
return choiceToAlt[this.LA(1).tokenTypeIdx] === true;
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
return function() {
|
|
573
|
-
const result = adaptivePredict.call(this, dfas, decisionIndex, EMPTY_PREDICATES, logging);
|
|
574
|
-
return typeof result === "object" ? false : result === 0;
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
function isLL1Sequence(sequences, allowEmpty = true) {
|
|
579
|
-
const fullSet = /* @__PURE__ */ new Set();
|
|
580
|
-
for (const alt of sequences) {
|
|
581
|
-
const altSet = /* @__PURE__ */ new Set();
|
|
582
|
-
for (const tokType of alt) {
|
|
583
|
-
if (tokType === void 0) if (allowEmpty) break;
|
|
584
|
-
else return false;
|
|
585
|
-
const indices = [tokType.tokenTypeIdx].concat(tokType.categoryMatches);
|
|
586
|
-
for (const index of indices) if (fullSet.has(index)) {
|
|
587
|
-
if (!altSet.has(index)) return false;
|
|
588
|
-
} else {
|
|
589
|
-
fullSet.add(index);
|
|
590
|
-
altSet.add(index);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return true;
|
|
595
|
-
}
|
|
596
|
-
function initATNSimulator(atn) {
|
|
597
|
-
const decisionLength = atn.decisionStates.length;
|
|
598
|
-
const decisionToDFA = Array(decisionLength);
|
|
599
|
-
for (let i = 0; i < decisionLength; i++) decisionToDFA[i] = createDFACache(atn.decisionStates[i], i);
|
|
600
|
-
return decisionToDFA;
|
|
601
|
-
}
|
|
602
|
-
function adaptivePredict(dfaCaches, decision, predicateSet, logging) {
|
|
603
|
-
const dfa = dfaCaches[decision](predicateSet);
|
|
604
|
-
let start = dfa.start;
|
|
605
|
-
if (start === void 0) {
|
|
606
|
-
start = addDFAState(dfa, newDFAState(computeStartState(dfa.atnStartState)));
|
|
607
|
-
dfa.start = start;
|
|
608
|
-
}
|
|
609
|
-
return performLookahead.apply(this, [
|
|
610
|
-
dfa,
|
|
611
|
-
start,
|
|
612
|
-
predicateSet,
|
|
613
|
-
logging
|
|
614
|
-
]);
|
|
615
|
-
}
|
|
616
|
-
function performLookahead(dfa, s0, predicateSet, logging) {
|
|
617
|
-
let previousD = s0;
|
|
618
|
-
let i = 1;
|
|
619
|
-
const path = [];
|
|
620
|
-
let t = this.LA(i++);
|
|
621
|
-
while (true) {
|
|
622
|
-
let d = getExistingTargetState(previousD, t);
|
|
623
|
-
if (d === void 0) d = computeLookaheadTarget.apply(this, [
|
|
624
|
-
dfa,
|
|
625
|
-
previousD,
|
|
626
|
-
t,
|
|
627
|
-
i,
|
|
628
|
-
predicateSet,
|
|
629
|
-
logging
|
|
630
|
-
]);
|
|
631
|
-
if (d === DFA_ERROR) return buildAdaptivePredictError(path, previousD, t);
|
|
632
|
-
if (d.isAcceptState === true) return d.prediction;
|
|
633
|
-
previousD = d;
|
|
634
|
-
path.push(t);
|
|
635
|
-
t = this.LA(i++);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
function computeLookaheadTarget(dfa, previousD, token, lookahead, predicateSet, logging) {
|
|
639
|
-
const reach = computeReachSet(previousD.configs, token, predicateSet);
|
|
640
|
-
if (reach.size === 0) {
|
|
641
|
-
addDFAEdge(dfa, previousD, token, DFA_ERROR);
|
|
642
|
-
return DFA_ERROR;
|
|
643
|
-
}
|
|
644
|
-
let newState = newDFAState(reach);
|
|
645
|
-
const predictedAlt = getUniqueAlt(reach, predicateSet);
|
|
646
|
-
if (predictedAlt !== void 0) {
|
|
647
|
-
newState.isAcceptState = true;
|
|
648
|
-
newState.prediction = predictedAlt;
|
|
649
|
-
newState.configs.uniqueAlt = predictedAlt;
|
|
650
|
-
} else if (hasConflictTerminatingPrediction(reach)) {
|
|
651
|
-
const prediction = min_default(reach.alts);
|
|
652
|
-
newState.isAcceptState = true;
|
|
653
|
-
newState.prediction = prediction;
|
|
654
|
-
newState.configs.uniqueAlt = prediction;
|
|
655
|
-
reportLookaheadAmbiguity.apply(this, [
|
|
656
|
-
dfa,
|
|
657
|
-
lookahead,
|
|
658
|
-
reach.alts,
|
|
659
|
-
logging
|
|
660
|
-
]);
|
|
661
|
-
}
|
|
662
|
-
newState = addDFAEdge(dfa, previousD, token, newState);
|
|
663
|
-
return newState;
|
|
664
|
-
}
|
|
665
|
-
function reportLookaheadAmbiguity(dfa, lookahead, ambiguityIndices, logging) {
|
|
666
|
-
const prefixPath = [];
|
|
667
|
-
for (let i = 1; i <= lookahead; i++) prefixPath.push(this.LA(i).tokenType);
|
|
668
|
-
const atnState = dfa.atnStartState;
|
|
669
|
-
const topLevelRule = atnState.rule;
|
|
670
|
-
const production = atnState.production;
|
|
671
|
-
logging(buildAmbiguityError({
|
|
672
|
-
topLevelRule,
|
|
673
|
-
ambiguityIndices,
|
|
674
|
-
production,
|
|
675
|
-
prefixPath
|
|
676
|
-
}));
|
|
677
|
-
}
|
|
678
|
-
function buildAmbiguityError(options) {
|
|
679
|
-
const pathMsg = map_default(options.prefixPath, (currtok) => tokenLabel(currtok)).join(", ");
|
|
680
|
-
const occurrence = options.production.idx === 0 ? "" : options.production.idx;
|
|
681
|
-
let currMessage = `Ambiguous Alternatives Detected: <${options.ambiguityIndices.join(", ")}> in <${getProductionDslName(options.production)}${occurrence}> inside <${options.topLevelRule.name}> Rule,\n<${pathMsg}> may appears as a prefix path in all these alternatives.\n`;
|
|
682
|
-
currMessage = currMessage + "See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES\nFor Further details.";
|
|
683
|
-
return currMessage;
|
|
684
|
-
}
|
|
685
|
-
function getProductionDslName(prod) {
|
|
686
|
-
if (prod instanceof NonTerminal) return "SUBRULE";
|
|
687
|
-
else if (prod instanceof Option) return "OPTION";
|
|
688
|
-
else if (prod instanceof Alternation) return "OR";
|
|
689
|
-
else if (prod instanceof RepetitionMandatory) return "AT_LEAST_ONE";
|
|
690
|
-
else if (prod instanceof RepetitionMandatoryWithSeparator) return "AT_LEAST_ONE_SEP";
|
|
691
|
-
else if (prod instanceof RepetitionWithSeparator) return "MANY_SEP";
|
|
692
|
-
else if (prod instanceof Repetition) return "MANY";
|
|
693
|
-
else if (prod instanceof Terminal) return "CONSUME";
|
|
694
|
-
else throw Error("non exhaustive match");
|
|
695
|
-
}
|
|
696
|
-
function buildAdaptivePredictError(path, previous, current) {
|
|
697
|
-
return {
|
|
698
|
-
actualToken: current,
|
|
699
|
-
possibleTokenTypes: uniqBy_default(flatMap_default(previous.configs.elements, (e) => e.state.transitions).filter((e) => e instanceof AtomTransition).map((e) => e.tokenType), (e) => e.tokenTypeIdx),
|
|
700
|
-
tokenPath: path
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
function getExistingTargetState(state, token) {
|
|
704
|
-
return state.edges[token.tokenTypeIdx];
|
|
705
|
-
}
|
|
706
|
-
function computeReachSet(configs, token, predicateSet) {
|
|
707
|
-
const intermediate = new ATNConfigSet();
|
|
708
|
-
const skippedStopStates = [];
|
|
709
|
-
for (const c of configs.elements) {
|
|
710
|
-
if (predicateSet.is(c.alt) === false) continue;
|
|
711
|
-
if (c.state.type === ATN_RULE_STOP) {
|
|
712
|
-
skippedStopStates.push(c);
|
|
713
|
-
continue;
|
|
714
|
-
}
|
|
715
|
-
const transitionLength = c.state.transitions.length;
|
|
716
|
-
for (let i = 0; i < transitionLength; i++) {
|
|
717
|
-
const transition = c.state.transitions[i];
|
|
718
|
-
const target = getReachableTarget(transition, token);
|
|
719
|
-
if (target !== void 0) intermediate.add({
|
|
720
|
-
state: target,
|
|
721
|
-
alt: c.alt,
|
|
722
|
-
stack: c.stack
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
let reach;
|
|
727
|
-
if (skippedStopStates.length === 0 && intermediate.size === 1) reach = intermediate;
|
|
728
|
-
if (reach === void 0) {
|
|
729
|
-
reach = new ATNConfigSet();
|
|
730
|
-
for (const c of intermediate.elements) closure(c, reach);
|
|
731
|
-
}
|
|
732
|
-
if (skippedStopStates.length > 0 && !hasConfigInRuleStopState(reach)) for (const c of skippedStopStates) reach.add(c);
|
|
733
|
-
return reach;
|
|
734
|
-
}
|
|
735
|
-
function getReachableTarget(transition, token) {
|
|
736
|
-
if (transition instanceof AtomTransition && tokenMatcher(token, transition.tokenType)) return transition.target;
|
|
737
|
-
}
|
|
738
|
-
function getUniqueAlt(configs, predicateSet) {
|
|
739
|
-
let alt;
|
|
740
|
-
for (const c of configs.elements) if (predicateSet.is(c.alt) === true) {
|
|
741
|
-
if (alt === void 0) alt = c.alt;
|
|
742
|
-
else if (alt !== c.alt) return;
|
|
743
|
-
}
|
|
744
|
-
return alt;
|
|
745
|
-
}
|
|
746
|
-
function newDFAState(closure) {
|
|
747
|
-
return {
|
|
748
|
-
configs: closure,
|
|
749
|
-
edges: {},
|
|
750
|
-
isAcceptState: false,
|
|
751
|
-
prediction: -1
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
function addDFAEdge(dfa, from, token, to) {
|
|
755
|
-
to = addDFAState(dfa, to);
|
|
756
|
-
from.edges[token.tokenTypeIdx] = to;
|
|
757
|
-
return to;
|
|
758
|
-
}
|
|
759
|
-
function addDFAState(dfa, state) {
|
|
760
|
-
if (state === DFA_ERROR) return state;
|
|
761
|
-
const mapKey = state.configs.key;
|
|
762
|
-
const existing = dfa.states[mapKey];
|
|
763
|
-
if (existing !== void 0) return existing;
|
|
764
|
-
state.configs.finalize();
|
|
765
|
-
dfa.states[mapKey] = state;
|
|
766
|
-
return state;
|
|
767
|
-
}
|
|
768
|
-
function computeStartState(atnState) {
|
|
769
|
-
const configs = new ATNConfigSet();
|
|
770
|
-
const numberOfTransitions = atnState.transitions.length;
|
|
771
|
-
for (let i = 0; i < numberOfTransitions; i++) closure({
|
|
772
|
-
state: atnState.transitions[i].target,
|
|
773
|
-
alt: i,
|
|
774
|
-
stack: []
|
|
775
|
-
}, configs);
|
|
776
|
-
return configs;
|
|
777
|
-
}
|
|
778
|
-
function closure(config, configs) {
|
|
779
|
-
const p = config.state;
|
|
780
|
-
if (p.type === ATN_RULE_STOP) {
|
|
781
|
-
if (config.stack.length > 0) {
|
|
782
|
-
const atnStack = [...config.stack];
|
|
783
|
-
closure({
|
|
784
|
-
state: atnStack.pop(),
|
|
785
|
-
alt: config.alt,
|
|
786
|
-
stack: atnStack
|
|
787
|
-
}, configs);
|
|
788
|
-
} else configs.add(config);
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
if (!p.epsilonOnlyTransitions) configs.add(config);
|
|
792
|
-
const transitionLength = p.transitions.length;
|
|
793
|
-
for (let i = 0; i < transitionLength; i++) {
|
|
794
|
-
const transition = p.transitions[i];
|
|
795
|
-
const c = getEpsilonTarget(config, transition);
|
|
796
|
-
if (c !== void 0) closure(c, configs);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
function getEpsilonTarget(config, transition) {
|
|
800
|
-
if (transition instanceof EpsilonTransition) return {
|
|
801
|
-
state: transition.target,
|
|
802
|
-
alt: config.alt,
|
|
803
|
-
stack: config.stack
|
|
804
|
-
};
|
|
805
|
-
else if (transition instanceof RuleTransition) {
|
|
806
|
-
const stack = [...config.stack, transition.followState];
|
|
807
|
-
return {
|
|
808
|
-
state: transition.target,
|
|
809
|
-
alt: config.alt,
|
|
810
|
-
stack
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
function hasConfigInRuleStopState(configs) {
|
|
815
|
-
for (const c of configs.elements) if (c.state.type === ATN_RULE_STOP) return true;
|
|
816
|
-
return false;
|
|
817
|
-
}
|
|
818
|
-
function allConfigsInRuleStopStates(configs) {
|
|
819
|
-
for (const c of configs.elements) if (c.state.type !== ATN_RULE_STOP) return false;
|
|
820
|
-
return true;
|
|
821
|
-
}
|
|
822
|
-
function hasConflictTerminatingPrediction(configs) {
|
|
823
|
-
if (allConfigsInRuleStopStates(configs)) return true;
|
|
824
|
-
const altSets = getConflictingAltSets(configs.elements);
|
|
825
|
-
return hasConflictingAltSet(altSets) && !hasStateAssociatedWithOneAlt(altSets);
|
|
826
|
-
}
|
|
827
|
-
function getConflictingAltSets(configs) {
|
|
828
|
-
const configToAlts = /* @__PURE__ */ new Map();
|
|
829
|
-
for (const c of configs) {
|
|
830
|
-
const key = getATNConfigKey(c, false);
|
|
831
|
-
let alts = configToAlts.get(key);
|
|
832
|
-
if (alts === void 0) {
|
|
833
|
-
alts = {};
|
|
834
|
-
configToAlts.set(key, alts);
|
|
835
|
-
}
|
|
836
|
-
alts[c.alt] = true;
|
|
837
|
-
}
|
|
838
|
-
return configToAlts;
|
|
839
|
-
}
|
|
840
|
-
function hasConflictingAltSet(altSets) {
|
|
841
|
-
for (const value of Array.from(altSets.values())) if (Object.keys(value).length > 1) return true;
|
|
842
|
-
return false;
|
|
843
|
-
}
|
|
844
|
-
function hasStateAssociatedWithOneAlt(altSets) {
|
|
845
|
-
for (const value of Array.from(altSets.values())) if (Object.keys(value).length === 1) return true;
|
|
846
|
-
return false;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
//#endregion
|
|
850
|
-
export { LLStarLookaheadStrategy as t };
|
|
1
|
+
import{C as map,D as baseIteratee,T as forEach,c as NonTerminal,d as RepetitionMandatory,f as RepetitionMandatoryWithSeparator,h as Terminal,ht as isSymbol,l as Option,o as Alternation,p as RepetitionWithSeparator,u as Repetition,ut as identity}from"./@chevrotain/gast.mjs";import{c as tokenMatcher,d as baseUniq,f as reduce,g as flatten,h as filter,i as getLookaheadPaths,m as flatMap,p as isEmpty,r as LLkLookaheadStrategy,s as tokenLabel}from"./chevrotain.mjs";function baseLt(e,t){return e<t}function baseExtremum(e,t,n){for(var r=-1,i=e.length;++r<i;){var a=e[r],o=t(a);if(o!=null&&(c===void 0?o===o&&!isSymbol(o):n(o,c)))var c=o,l=a}return l}function min(e){return e&&e.length?baseExtremum(e,identity,baseLt):void 0}function uniqBy(e,n){return e&&e.length?baseUniq(e,baseIteratee(n,2)):[]}function buildATNKey(e,t,n){return`${e.name}_${t}_${n}`}var AbstractTransition=class{constructor(e){this.target=e}isEpsilon(){return!1}},AtomTransition=class extends AbstractTransition{constructor(e,t){super(e),this.tokenType=t}},EpsilonTransition=class extends AbstractTransition{constructor(e){super(e)}isEpsilon(){return!0}},RuleTransition=class extends AbstractTransition{constructor(e,t,n){super(e),this.rule=t,this.followState=n}isEpsilon(){return!0}};function createATN(e){let t={decisionMap:{},decisionStates:[],ruleToStartState:new Map,ruleToStopState:new Map,states:[]};createRuleStartAndStopATNStates(t,e);let n=e.length;for(let r=0;r<n;r++){let n=e[r],i=block(t,n,n);i!==void 0&&buildRuleHandle(t,n,i)}return t}function createRuleStartAndStopATNStates(e,t){let n=t.length;for(let r=0;r<n;r++){let n=t[r],i=newState(e,n,void 0,{type:2}),a=newState(e,n,void 0,{type:7});i.stop=a,e.ruleToStartState.set(n,i),e.ruleToStopState.set(n,a)}}function atom(e,t,n){return n instanceof Terminal?tokenRef(e,t,n.terminalType,n):n instanceof NonTerminal?ruleRef(e,t,n):n instanceof Alternation?alternation(e,t,n):n instanceof Option?option(e,t,n):n instanceof Repetition?repetition(e,t,n):n instanceof RepetitionWithSeparator?repetitionSep(e,t,n):n instanceof RepetitionMandatory?repetitionMandatory(e,t,n):n instanceof RepetitionMandatoryWithSeparator?repetitionMandatorySep(e,t,n):block(e,t,n)}function repetition(e,t,n){let r=newState(e,t,n,{type:5});return defineDecisionState(e,r),star(e,t,n,makeAlts(e,t,r,n,block(e,t,n)))}function repetitionSep(e,t,n){let r=newState(e,t,n,{type:5});return defineDecisionState(e,r),star(e,t,n,makeAlts(e,t,r,n,block(e,t,n)),tokenRef(e,t,n.separator,n))}function repetitionMandatory(e,t,n){let r=newState(e,t,n,{type:4});return defineDecisionState(e,r),plus(e,t,n,makeAlts(e,t,r,n,block(e,t,n)))}function repetitionMandatorySep(e,t,n){let r=newState(e,t,n,{type:4});return defineDecisionState(e,r),plus(e,t,n,makeAlts(e,t,r,n,block(e,t,n)),tokenRef(e,t,n.separator,n))}function alternation(t,n,r){let i=newState(t,n,r,{type:1});return defineDecisionState(t,i),makeAlts(t,n,i,r,...map(r.definition,e=>atom(t,n,e)))}function option(e,t,n){let r=newState(e,t,n,{type:1});return defineDecisionState(e,r),optional(e,t,n,makeAlts(e,t,r,n,block(e,t,n)))}function block(t,n,r){let i=filter(map(r.definition,e=>atom(t,n,e)),e=>e!==void 0);return i.length===1?i[0]:i.length===0?void 0:makeBlock(t,i)}function plus(e,t,n,r,i){let a=r.left,o=r.right,s=newState(e,t,n,{type:11});defineDecisionState(e,s);let c=newState(e,t,n,{type:12});return a.loopback=s,c.loopback=s,e.decisionMap[buildATNKey(t,i?`RepetitionMandatoryWithSeparator`:`RepetitionMandatory`,n.idx)]=s,epsilon(o,s),i===void 0?(epsilon(s,a),epsilon(s,c)):(epsilon(s,c),epsilon(s,i.left),epsilon(i.right,a)),{left:a,right:c}}function star(e,t,n,r,i){let a=r.left,o=r.right,s=newState(e,t,n,{type:10});defineDecisionState(e,s);let c=newState(e,t,n,{type:12}),l=newState(e,t,n,{type:9});return s.loopback=l,c.loopback=l,epsilon(s,a),epsilon(s,c),epsilon(o,l),i===void 0?epsilon(l,s):(epsilon(l,c),epsilon(l,i.left),epsilon(i.right,a)),e.decisionMap[buildATNKey(t,i?`RepetitionWithSeparator`:`Repetition`,n.idx)]=s,{left:s,right:c}}function optional(e,t,n,r){let i=r.left,a=r.right;return epsilon(i,a),e.decisionMap[buildATNKey(t,`Option`,n.idx)]=i,r}function defineDecisionState(e,t){return e.decisionStates.push(t),t.decision=e.decisionStates.length-1,t.decision}function makeAlts(e,t,n,r,...i){let a=newState(e,t,r,{type:8,start:n});n.end=a;for(let e of i)e===void 0?epsilon(n,a):(epsilon(n,e.left),epsilon(e.right,a));let o={left:n,right:a};return e.decisionMap[buildATNKey(t,getProdType(r),r.idx)]=n,o}function getProdType(e){if(e instanceof Alternation)return`Alternation`;if(e instanceof Option)return`Option`;if(e instanceof Repetition)return`Repetition`;if(e instanceof RepetitionWithSeparator)return`RepetitionWithSeparator`;if(e instanceof RepetitionMandatory)return`RepetitionMandatory`;if(e instanceof RepetitionMandatoryWithSeparator)return`RepetitionMandatoryWithSeparator`;throw Error(`Invalid production type encountered`)}function makeBlock(e,t){let n=t.length;for(let r=0;r<n-1;r++){let n=t[r],i;n.left.transitions.length===1&&(i=n.left.transitions[0]);let a=i instanceof RuleTransition,o=i,s=t[r+1].left;n.left.type===1&&n.right.type===1&&i!==void 0&&(a&&o.followState===n.right||i.target===n.right)?(a?o.followState=s:i.target=s,removeState(e,n.right)):epsilon(n.right,s)}let r=t[0],i=t[n-1];return{left:r.left,right:i.right}}function tokenRef(e,t,n,r){let i=newState(e,t,r,{type:1}),a=newState(e,t,r,{type:1});return addTransition(i,new AtomTransition(a,n)),{left:i,right:a}}function ruleRef(e,t,n){let r=n.referencedRule,i=e.ruleToStartState.get(r),a=newState(e,t,n,{type:1}),o=newState(e,t,n,{type:1});return addTransition(a,new RuleTransition(i,r,o)),{left:a,right:o}}function buildRuleHandle(e,t,n){let r=e.ruleToStartState.get(t);epsilon(r,n.left);let i=e.ruleToStopState.get(t);return epsilon(n.right,i),{left:r,right:i}}function epsilon(e,t){addTransition(e,new EpsilonTransition(t))}function newState(e,t,n,r){let i=Object.assign({atn:e,production:n,epsilonOnlyTransitions:!1,rule:t,transitions:[],nextTokenWithinRule:[],stateNumber:e.states.length},r);return e.states.push(i),i}function addTransition(e,t){e.transitions.length===0&&(e.epsilonOnlyTransitions=t.isEpsilon()),e.transitions.push(t)}function removeState(e,t){e.states.splice(e.states.indexOf(t),1)}const DFA_ERROR={};var ATNConfigSet=class{constructor(){this.map={},this.configs=[]}get size(){return this.configs.length}finalize(){this.map={}}add(e){let t=getATNConfigKey(e);t in this.map||(this.map[t]=this.configs.length,this.configs.push(e))}get elements(){return this.configs}get alts(){return map(this.configs,e=>e.alt)}get key(){let e=``;for(let t in this.map)e+=t+`:`;return e}};function getATNConfigKey(e,t=!0){return`${t?`a${e.alt}`:``}s${e.state.stateNumber}:${e.stack.map(e=>e.stateNumber.toString()).join(`_`)}`}function createDFACache(e,t){let n={};return r=>{let i=r.toString(),a=n[i];return a===void 0?(a={atnStartState:e,decision:t,states:{}},n[i]=a,a):a}}var PredicateSet=class{constructor(){this.predicates=[]}is(e){return e>=this.predicates.length||this.predicates[e]}set(e,t){this.predicates[e]=t}toString(){let e=``,t=this.predicates.length;for(let n=0;n<t;n++)e+=this.predicates[n]===!0?`1`:`0`;return e}};const EMPTY_PREDICATES=new PredicateSet;var LLStarLookaheadStrategy=class extends LLkLookaheadStrategy{constructor(e){super(),this.logging=e?.logging??(e=>console.log(e))}initialize(e){this.atn=createATN(e.rules),this.dfas=initATNSimulator(this.atn)}validateAmbiguousAlternationAlternatives(){return[]}validateEmptyOrAlternatives(){return[]}buildLookaheadForAlternation(t){let{prodOccurrence:r,rule:i,hasPredicates:a,dynamicTokensEnabled:o}=t,s=this.dfas,c=this.logging,l=buildATNKey(i,`Alternation`,r),u=this.atn.decisionMap[l].decision,d=map(getLookaheadPaths({maxLookahead:1,occurrence:r,prodType:`Alternation`,rule:i}),t=>map(t,e=>e[0]));if(isLL1Sequence(d,!1)&&!o){let e=reduce(d,(e,t,r)=>(forEach(t,t=>{t&&(e[t.tokenTypeIdx]=r,forEach(t.categoryMatches,t=>{e[t]=r}))}),e),{});return a?function(t){let n=e[this.LA(1).tokenTypeIdx];if(t!==void 0&&n!==void 0){let e=t[n]?.GATE;if(e!==void 0&&e.call(this)===!1)return}return n}:function(){return e[this.LA(1).tokenTypeIdx]}}else if(a)return function(e){let t=new PredicateSet,n=e===void 0?0:e.length;for(let r=0;r<n;r++){let n=e?.[r].GATE;t.set(r,n===void 0||n.call(this))}let r=adaptivePredict.call(this,s,u,t,c);return typeof r==`number`?r:void 0};else return function(){let e=adaptivePredict.call(this,s,u,EMPTY_PREDICATES,c);return typeof e==`number`?e:void 0}}buildLookaheadForOptional(t){let{prodOccurrence:r,rule:i,prodType:a,dynamicTokensEnabled:o}=t,s=this.dfas,c=this.logging,l=buildATNKey(i,a,r),u=this.atn.decisionMap[l].decision,d=map(getLookaheadPaths({maxLookahead:1,occurrence:r,prodType:a,rule:i}),t=>map(t,e=>e[0]));if(isLL1Sequence(d)&&d[0][0]&&!o){let e=d[0],t=flatten(e);if(t.length===1&&isEmpty(t[0].categoryMatches)){let e=t[0].tokenTypeIdx;return function(){return this.LA(1).tokenTypeIdx===e}}else{let e=reduce(t,(e,t)=>(t!==void 0&&(e[t.tokenTypeIdx]=!0,forEach(t.categoryMatches,t=>{e[t]=!0})),e),{});return function(){return e[this.LA(1).tokenTypeIdx]===!0}}}return function(){let e=adaptivePredict.call(this,s,u,EMPTY_PREDICATES,c);return typeof e==`object`?!1:e===0}}};function isLL1Sequence(e,t=!0){let n=new Set;for(let r of e){let e=new Set;for(let i of r){if(i===void 0){if(t)break;return!1}let r=[i.tokenTypeIdx].concat(i.categoryMatches);for(let t of r)if(n.has(t)){if(!e.has(t))return!1}else n.add(t),e.add(t)}}return!0}function initATNSimulator(e){let t=e.decisionStates.length,n=Array(t);for(let r=0;r<t;r++)n[r]=createDFACache(e.decisionStates[r],r);return n}function adaptivePredict(e,t,n,r){let i=e[t](n),a=i.start;return a===void 0&&(a=addDFAState(i,newDFAState(computeStartState(i.atnStartState))),i.start=a),performLookahead.apply(this,[i,a,n,r])}function performLookahead(e,t,n,r){let i=t,a=1,o=[],s=this.LA(a++);for(;;){let t=getExistingTargetState(i,s);if(t===void 0&&(t=computeLookaheadTarget.apply(this,[e,i,s,a,n,r])),t===DFA_ERROR)return buildAdaptivePredictError(o,i,s);if(t.isAcceptState===!0)return t.prediction;i=t,o.push(s),s=this.LA(a++)}}function computeLookaheadTarget(e,t,n,r,i,a){let o=computeReachSet(t.configs,n,i);if(o.size===0)return addDFAEdge(e,t,n,DFA_ERROR),DFA_ERROR;let s=newDFAState(o),c=getUniqueAlt(o,i);if(c!==void 0)s.isAcceptState=!0,s.prediction=c,s.configs.uniqueAlt=c;else if(hasConflictTerminatingPrediction(o)){let t=min(o.alts);s.isAcceptState=!0,s.prediction=t,s.configs.uniqueAlt=t,reportLookaheadAmbiguity.apply(this,[e,r,o.alts,a])}return s=addDFAEdge(e,t,n,s),s}function reportLookaheadAmbiguity(e,t,n,r){let i=[];for(let e=1;e<=t;e++)i.push(this.LA(e).tokenType);let a=e.atnStartState,o=a.rule,s=a.production;r(buildAmbiguityError({topLevelRule:o,ambiguityIndices:n,production:s,prefixPath:i}))}function buildAmbiguityError(t){let n=map(t.prefixPath,e=>tokenLabel(e)).join(`, `),r=t.production.idx===0?``:t.production.idx,i=`Ambiguous Alternatives Detected: <${t.ambiguityIndices.join(`, `)}> in <${getProductionDslName(t.production)}${r}> inside <${t.topLevelRule.name}> Rule,\n<${n}> may appears as a prefix path in all these alternatives.\n`;return i+=`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
|
|
2
|
+
For Further details.`,i}function getProductionDslName(e){if(e instanceof NonTerminal)return`SUBRULE`;if(e instanceof Option)return`OPTION`;if(e instanceof Alternation)return`OR`;if(e instanceof RepetitionMandatory)return`AT_LEAST_ONE`;if(e instanceof RepetitionMandatoryWithSeparator)return`AT_LEAST_ONE_SEP`;if(e instanceof RepetitionWithSeparator)return`MANY_SEP`;if(e instanceof Repetition)return`MANY`;if(e instanceof Terminal)return`CONSUME`;throw Error(`non exhaustive match`)}function buildAdaptivePredictError(e,t,n){return{actualToken:n,possibleTokenTypes:uniqBy(flatMap(t.configs.elements,e=>e.state.transitions).filter(e=>e instanceof AtomTransition).map(e=>e.tokenType),e=>e.tokenTypeIdx),tokenPath:e}}function getExistingTargetState(e,t){return e.edges[t.tokenTypeIdx]}function computeReachSet(e,t,n){let r=new ATNConfigSet,i=[];for(let a of e.elements){if(n.is(a.alt)===!1)continue;if(a.state.type===7){i.push(a);continue}let e=a.state.transitions.length;for(let n=0;n<e;n++){let e=a.state.transitions[n],i=getReachableTarget(e,t);i!==void 0&&r.add({state:i,alt:a.alt,stack:a.stack})}}let a;if(i.length===0&&r.size===1&&(a=r),a===void 0){a=new ATNConfigSet;for(let e of r.elements)closure(e,a)}if(i.length>0&&!hasConfigInRuleStopState(a))for(let e of i)a.add(e);return a}function getReachableTarget(e,t){if(e instanceof AtomTransition&&tokenMatcher(t,e.tokenType))return e.target}function getUniqueAlt(e,t){let n;for(let r of e.elements)if(t.is(r.alt)===!0){if(n===void 0)n=r.alt;else if(n!==r.alt)return}return n}function newDFAState(e){return{configs:e,edges:{},isAcceptState:!1,prediction:-1}}function addDFAEdge(e,t,n,r){return r=addDFAState(e,r),t.edges[n.tokenTypeIdx]=r,r}function addDFAState(e,t){if(t===DFA_ERROR)return t;let n=t.configs.key,r=e.states[n];return r===void 0?(t.configs.finalize(),e.states[n]=t,t):r}function computeStartState(e){let t=new ATNConfigSet,n=e.transitions.length;for(let r=0;r<n;r++)closure({state:e.transitions[r].target,alt:r,stack:[]},t);return t}function closure(e,t){let n=e.state;if(n.type===7){if(e.stack.length>0){let n=[...e.stack];closure({state:n.pop(),alt:e.alt,stack:n},t)}else t.add(e);return}n.epsilonOnlyTransitions||t.add(e);let r=n.transitions.length;for(let i=0;i<r;i++){let r=n.transitions[i],a=getEpsilonTarget(e,r);a!==void 0&&closure(a,t)}}function getEpsilonTarget(e,t){if(t instanceof EpsilonTransition)return{state:t.target,alt:e.alt,stack:e.stack};if(t instanceof RuleTransition){let n=[...e.stack,t.followState];return{state:t.target,alt:e.alt,stack:n}}}function hasConfigInRuleStopState(e){for(let t of e.elements)if(t.state.type===7)return!0;return!1}function allConfigsInRuleStopStates(e){for(let t of e.elements)if(t.state.type!==7)return!1;return!0}function hasConflictTerminatingPrediction(e){if(allConfigsInRuleStopStates(e))return!0;let t=getConflictingAltSets(e.elements);return hasConflictingAltSet(t)&&!hasStateAssociatedWithOneAlt(t)}function getConflictingAltSets(e){let t=new Map;for(let n of e){let e=getATNConfigKey(n,!1),r=t.get(e);r===void 0&&(r={},t.set(e,r)),r[n.alt]=!0}return t}function hasConflictingAltSet(e){for(let t of Array.from(e.values()))if(Object.keys(t).length>1)return!0;return!1}function hasStateAssociatedWithOneAlt(e){for(let t of Array.from(e.values()))if(Object.keys(t).length===1)return!0;return!1}export{LLStarLookaheadStrategy as t};
|