parseman 0.26.3 → 0.27.1
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/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +8 -0
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/fields.d.ts +20 -0
- package/dist/compiler/fields.d.ts.map +1 -1
- package/dist/compiler/inline-callback.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/cst/trivia-entries.d.ts +2 -0
- package/dist/cst/trivia-entries.d.ts.map +1 -1
- package/dist/functional/run.d.ts +29 -0
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +231 -36
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +231 -36
- package/dist/index.js.map +2 -2
- package/dist/language-service/index.cjs +39 -4
- package/dist/language-service/index.cjs.map +2 -2
- package/dist/language-service/index.js +39 -4
- package/dist/language-service/index.js.map +2 -2
- package/dist/plugin/direct-builder-static.d.ts +8 -0
- package/dist/plugin/direct-builder-static.d.ts.map +1 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +378 -44
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +378 -44
- package/dist/plugin/index.js.map +4 -4
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -112,7 +112,7 @@ var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSet
|
|
|
112
112
|
|
|
113
113
|
// src/functional/run.ts
|
|
114
114
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
115
|
-
function
|
|
115
|
+
function runOnce(entry, input, options, phase, profileState) {
|
|
116
116
|
if (typeof entry !== "function" && typeof entry?.parse !== "function") {
|
|
117
117
|
throw new TypeError(
|
|
118
118
|
`run(): start production is ${entry === null ? "null" : typeof entry}, not a rule \u2014 the requested grammar rule does not exist (check the rule name).`
|
|
@@ -120,11 +120,12 @@ function run(entry, input, options = {}) {
|
|
|
120
120
|
}
|
|
121
121
|
const triviaLog = [];
|
|
122
122
|
const errors = [];
|
|
123
|
+
const profile = profileState ?? (phase === void 0 ? void 0 : { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 });
|
|
124
|
+
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
123
125
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
124
126
|
const ctx = {
|
|
125
127
|
trackLines: false,
|
|
126
|
-
_triviaLog: triviaLog,
|
|
127
|
-
_errors: errors,
|
|
128
|
+
...skipGlobalSinks ? { _pmProfile: profile } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _pmProfile: profile } },
|
|
128
129
|
build: options.build,
|
|
129
130
|
state: options.state,
|
|
130
131
|
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
@@ -151,6 +152,38 @@ function run(entry, input, options = {}) {
|
|
|
151
152
|
unconsumedFrom
|
|
152
153
|
};
|
|
153
154
|
}
|
|
155
|
+
function clonePassState(state) {
|
|
156
|
+
if (state === null || typeof state !== "object") return state;
|
|
157
|
+
return Array.isArray(state) ? [...state] : { ...state };
|
|
158
|
+
}
|
|
159
|
+
function profilePass(entry, input, options, phase) {
|
|
160
|
+
const state = { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 };
|
|
161
|
+
const passOptions = options.state === void 0 ? options : { ...options, state: clonePassState(options.state) };
|
|
162
|
+
const start = performance.now();
|
|
163
|
+
const result = runOnce(entry, input, passOptions, phase, state);
|
|
164
|
+
const { phase: _phase, ...counts } = state;
|
|
165
|
+
return { result, profile: { ms: performance.now() - start, ...counts } };
|
|
166
|
+
}
|
|
167
|
+
function run(entry, input, options = {}) {
|
|
168
|
+
if (!options.profile) return runOnce(entry, input, options);
|
|
169
|
+
if (typeof entry !== "function") {
|
|
170
|
+
throw new TypeError("run({ profile: true }) requires a compiled parser entry");
|
|
171
|
+
}
|
|
172
|
+
const recognizer = profilePass(entry, input, options, "recognizer");
|
|
173
|
+
const capture = profilePass(entry, input, options, "capture");
|
|
174
|
+
const host = profilePass(entry, input, options, "host");
|
|
175
|
+
if (recognizer.result.ok !== host.result.ok || capture.result.ok !== host.result.ok || recognizer.result.unconsumedFrom !== host.result.unconsumedFrom || capture.result.unconsumedFrom !== host.result.unconsumedFrom) {
|
|
176
|
+
throw new Error("run({ profile: true }) changed recognition; the grammar is not profile-safe");
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
...host.result,
|
|
180
|
+
profile: {
|
|
181
|
+
recognizer: recognizer.profile,
|
|
182
|
+
structuralCapture: capture.profile,
|
|
183
|
+
hostConstruction: host.profile
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
154
187
|
|
|
155
188
|
// src/combinators/completions.ts
|
|
156
189
|
function completionsAt(target, input, offset, options = {}) {
|
|
@@ -175,7 +208,7 @@ var META = new Set("()[]{}*+?|^$.".split(""));
|
|
|
175
208
|
var CAP_RECORD = [
|
|
176
209
|
` if (_cap && _e > _pos) {`,
|
|
177
210
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
|
|
178
|
-
` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
211
|
+
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
179
212
|
` }`
|
|
180
213
|
].join("\n");
|
|
181
214
|
|
|
@@ -197,9 +230,11 @@ function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, trivi
|
|
|
197
230
|
}
|
|
198
231
|
const collapse = normalizeCstCollapse(typeOrOptions?.collapse);
|
|
199
232
|
const host = (type, children2, fields, span2, rawChildren2, triviaLog2, state2) => buildCstNode(type, children2, fields, span2, rawChildren2, triviaLog2, state2);
|
|
233
|
+
host._parsemanCstOutput = true;
|
|
200
234
|
if (collapse) host._parsemanCstCollapse = collapse;
|
|
201
235
|
return host;
|
|
202
236
|
}
|
|
237
|
+
cstBuildHost._parsemanCstOutput = true;
|
|
203
238
|
|
|
204
239
|
// src/cst/walk.ts
|
|
205
240
|
function walk(root, visitor, ctx = void 0) {
|