parseman 0.35.0 → 0.37.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 +34 -19
- package/dist/analysis/duplication.d.ts +421 -0
- package/dist/analysis/duplication.d.ts.map +1 -0
- package/dist/analysis/gating.d.ts +25 -0
- package/dist/analysis/gating.d.ts.map +1 -1
- package/dist/analysis/grammar.d.ts +12 -0
- package/dist/analysis/grammar.d.ts.map +1 -0
- package/dist/combinators/expect.d.ts +12 -0
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts +26 -0
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/build-arity.d.ts +12 -0
- package/dist/compiler/build-arity.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +43 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +64 -7
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/cst/host-mode.d.ts +43 -0
- package/dist/cst/host-mode.d.ts.map +1 -0
- package/dist/functional/doc.d.ts.map +1 -1
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +1621 -55
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1621 -55
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +37 -1
- package/dist/language-service/index.cjs.map +3 -3
- package/dist/language-service/index.js +37 -1
- package/dist/language-service/index.js.map +3 -3
- package/dist/oracle/corpus.d.ts +32 -0
- package/dist/oracle/corpus.d.ts.map +1 -0
- package/dist/oracle/digest.d.ts +21 -0
- package/dist/oracle/digest.d.ts.map +1 -0
- package/dist/oracle/identity.d.ts +117 -0
- package/dist/oracle/identity.d.ts.map +1 -0
- package/dist/oracle/index.cjs +423 -0
- package/dist/oracle/index.cjs.map +7 -0
- package/dist/oracle/index.d.ts +37 -0
- package/dist/oracle/index.d.ts.map +1 -0
- package/dist/oracle/index.js +400 -0
- package/dist/oracle/index.js.map +7 -0
- package/dist/plugin/index.cjs +1628 -62
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1628 -62
- package/dist/plugin/index.js.map +4 -4
- package/dist/run/index.cjs +23 -0
- package/dist/run/index.cjs.map +3 -3
- package/dist/run/index.js +23 -0
- package/dist/run/index.js.map +3 -3
- package/dist/spec/index.cjs +2977 -56
- package/dist/spec/index.cjs.map +4 -4
- package/dist/spec/index.js +2977 -56
- package/dist/spec/index.js.map +4 -4
- package/dist/spec/model.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +10 -3
|
@@ -136,6 +136,23 @@ function captureError(ctx, error) {
|
|
|
136
136
|
}
|
|
137
137
|
var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSetSentinel, capture: captureError };
|
|
138
138
|
|
|
139
|
+
// src/cst/host-mode.ts
|
|
140
|
+
var FUSED_HOST_MODE = /* @__PURE__ */ Symbol.for("parseman.fusedHostMode");
|
|
141
|
+
var FUSED_HOST_ELIDED = /* @__PURE__ */ Symbol.for("parseman.fusedHostElided");
|
|
142
|
+
function assertHostModeCompatible(mode, build, hostBranchElided = true) {
|
|
143
|
+
const isCstHost = build?._parsemanCstOutput === true;
|
|
144
|
+
if (mode === "ast" && isCstHost && hostBranchElided) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
"parseman: this parser was compiled for host mode \"ast\" (the default), so its nodes build through their own `build` callbacks and no positioned-CST branch was emitted. It cannot be driven with a positioned-CST host (cstBuildHost / a language-service host). Compile a second artifact from the SAME grammar with `compile(grammar, { hostMode: 'cst' })` \u2014 or, under the macro, a second `rules({ hostMode: 'cst' }, factory)` call site \u2014 and drive that one instead."
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
if (mode === "cst" && !isCstHost) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
'parseman: this parser was compiled for host mode "cst", so every node builds through a positioned-CST `ctx.build` host. Pass one (e.g. `{ build: cstBuildHost }`), or use an artifact compiled with the default `hostMode: "ast"` to get the grammar\'s own AST.'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
// src/functional/run.ts
|
|
140
157
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
141
158
|
function runOnce(entry, input, options, phase, profileState) {
|
|
@@ -150,6 +167,12 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
150
167
|
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
151
168
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
152
169
|
const grammarScanSkip = typeof entry !== "function" ? entry._meta.grammarScanSkip : void 0;
|
|
170
|
+
const stamped = entry;
|
|
171
|
+
assertHostModeCompatible(
|
|
172
|
+
typeof entry === "function" ? stamped[FUSED_HOST_MODE] ?? "ast" : entry._meta.grammarHostMode ?? "ast",
|
|
173
|
+
options.build,
|
|
174
|
+
typeof entry === "function" && stamped[FUSED_HOST_ELIDED] === true
|
|
175
|
+
);
|
|
153
176
|
const ctx = {
|
|
154
177
|
trackLines: false,
|
|
155
178
|
...skipGlobalSinks ? { _pmProfile: profile } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _pmProfile: profile } },
|
|
@@ -230,6 +253,10 @@ function deeperFail(a, b) {
|
|
|
230
253
|
return a.span.start >= b.span.start ? a : b;
|
|
231
254
|
}
|
|
232
255
|
|
|
256
|
+
// src/analysis/duplication.ts
|
|
257
|
+
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
258
|
+
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
259
|
+
|
|
233
260
|
// src/compiler/scannable-run.ts
|
|
234
261
|
var META = new Set("()[]{}*+?|^$.".split(""));
|
|
235
262
|
|
|
@@ -264,6 +291,13 @@ function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, trivi
|
|
|
264
291
|
return host;
|
|
265
292
|
}
|
|
266
293
|
cstBuildHost._parsemanCstOutput = true;
|
|
294
|
+
function fusedHostModeOf(registry) {
|
|
295
|
+
const m = registry[FUSED_HOST_MODE];
|
|
296
|
+
return m === "cst" ? "cst" : "ast";
|
|
297
|
+
}
|
|
298
|
+
function fusedHostElidedOf(registry) {
|
|
299
|
+
return registry[FUSED_HOST_ELIDED] === true;
|
|
300
|
+
}
|
|
267
301
|
|
|
268
302
|
// src/cst/walk.ts
|
|
269
303
|
function walk(root, visitor, ctx = void 0) {
|
|
@@ -308,7 +342,8 @@ function absoluteSpanCST(root, path) {
|
|
|
308
342
|
}
|
|
309
343
|
|
|
310
344
|
// src/functional/doc.ts
|
|
311
|
-
function mkCtx(
|
|
345
|
+
function mkCtx(rawState, build, tolerant) {
|
|
346
|
+
const state = rawState ?? void 0;
|
|
312
347
|
return tolerant ? { trackLines: false, state, build, _tolerant: true, _rec: REC, _errors: [] } : { trackLines: false, state, build };
|
|
313
348
|
}
|
|
314
349
|
function asRuleFn(entry) {
|
|
@@ -705,6 +740,7 @@ function collectEmbeddedErrors(node2, base, out) {
|
|
|
705
740
|
function parseDoc(registry, rootRule, input, opts = {}) {
|
|
706
741
|
const entry = registry[rootRule];
|
|
707
742
|
if (!entry) throw new Error(`No rule '${rootRule}' in registry`);
|
|
743
|
+
assertHostModeCompatible(fusedHostModeOf(registry), opts.build, fusedHostElidedOf(registry));
|
|
708
744
|
const ctx = mkCtx(opts.state, opts.build, !!opts.tolerant);
|
|
709
745
|
const r = asRuleFn(entry)(input, 0, ctx);
|
|
710
746
|
if (r.ok) {
|