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.
Files changed (61) hide show
  1. package/README.md +34 -19
  2. package/dist/analysis/duplication.d.ts +421 -0
  3. package/dist/analysis/duplication.d.ts.map +1 -0
  4. package/dist/analysis/gating.d.ts +25 -0
  5. package/dist/analysis/gating.d.ts.map +1 -1
  6. package/dist/analysis/grammar.d.ts +12 -0
  7. package/dist/analysis/grammar.d.ts.map +1 -0
  8. package/dist/combinators/expect.d.ts +12 -0
  9. package/dist/combinators/expect.d.ts.map +1 -1
  10. package/dist/combinators/parser.d.ts +26 -0
  11. package/dist/combinators/parser.d.ts.map +1 -1
  12. package/dist/compiler/build-arity.d.ts +12 -0
  13. package/dist/compiler/build-arity.d.ts.map +1 -1
  14. package/dist/compiler/codegen.d.ts +43 -1
  15. package/dist/compiler/codegen.d.ts.map +1 -1
  16. package/dist/compiler/linker.d.ts +64 -7
  17. package/dist/compiler/linker.d.ts.map +1 -1
  18. package/dist/cst/host-mode.d.ts +43 -0
  19. package/dist/cst/host-mode.d.ts.map +1 -0
  20. package/dist/functional/doc.d.ts.map +1 -1
  21. package/dist/functional/run.d.ts.map +1 -1
  22. package/dist/index.cjs +1621 -55
  23. package/dist/index.cjs.map +4 -4
  24. package/dist/index.d.ts +6 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1621 -55
  27. package/dist/index.js.map +4 -4
  28. package/dist/language-service/index.cjs +37 -1
  29. package/dist/language-service/index.cjs.map +3 -3
  30. package/dist/language-service/index.js +37 -1
  31. package/dist/language-service/index.js.map +3 -3
  32. package/dist/oracle/corpus.d.ts +32 -0
  33. package/dist/oracle/corpus.d.ts.map +1 -0
  34. package/dist/oracle/digest.d.ts +21 -0
  35. package/dist/oracle/digest.d.ts.map +1 -0
  36. package/dist/oracle/identity.d.ts +117 -0
  37. package/dist/oracle/identity.d.ts.map +1 -0
  38. package/dist/oracle/index.cjs +423 -0
  39. package/dist/oracle/index.cjs.map +7 -0
  40. package/dist/oracle/index.d.ts +37 -0
  41. package/dist/oracle/index.d.ts.map +1 -0
  42. package/dist/oracle/index.js +400 -0
  43. package/dist/oracle/index.js.map +7 -0
  44. package/dist/plugin/index.cjs +1628 -62
  45. package/dist/plugin/index.cjs.map +4 -4
  46. package/dist/plugin/index.d.ts.map +1 -1
  47. package/dist/plugin/index.js +1628 -62
  48. package/dist/plugin/index.js.map +4 -4
  49. package/dist/run/index.cjs +23 -0
  50. package/dist/run/index.cjs.map +3 -3
  51. package/dist/run/index.js +23 -0
  52. package/dist/run/index.js.map +3 -3
  53. package/dist/spec/index.cjs +2977 -56
  54. package/dist/spec/index.cjs.map +4 -4
  55. package/dist/spec/index.js +2977 -56
  56. package/dist/spec/index.js.map +4 -4
  57. package/dist/spec/model.d.ts.map +1 -1
  58. package/dist/types.d.ts +7 -0
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/version.d.ts +1 -1
  61. package/package.json +10 -3
@@ -110,6 +110,23 @@ function captureError(ctx, error) {
110
110
  }
111
111
  var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSetSentinel, capture: captureError };
112
112
 
113
+ // src/cst/host-mode.ts
114
+ var FUSED_HOST_MODE = /* @__PURE__ */ Symbol.for("parseman.fusedHostMode");
115
+ var FUSED_HOST_ELIDED = /* @__PURE__ */ Symbol.for("parseman.fusedHostElided");
116
+ function assertHostModeCompatible(mode, build, hostBranchElided = true) {
117
+ const isCstHost = build?._parsemanCstOutput === true;
118
+ if (mode === "ast" && isCstHost && hostBranchElided) {
119
+ throw new Error(
120
+ "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."
121
+ );
122
+ }
123
+ if (mode === "cst" && !isCstHost) {
124
+ throw new Error(
125
+ '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.'
126
+ );
127
+ }
128
+ }
129
+
113
130
  // src/functional/run.ts
114
131
  var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
115
132
  function runOnce(entry, input, options, phase, profileState) {
@@ -124,6 +141,12 @@ function runOnce(entry, input, options, phase, profileState) {
124
141
  const skipGlobalSinks = phase === "recognizer" || phase === "capture";
125
142
  const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
126
143
  const grammarScanSkip = typeof entry !== "function" ? entry._meta.grammarScanSkip : void 0;
144
+ const stamped = entry;
145
+ assertHostModeCompatible(
146
+ typeof entry === "function" ? stamped[FUSED_HOST_MODE] ?? "ast" : entry._meta.grammarHostMode ?? "ast",
147
+ options.build,
148
+ typeof entry === "function" && stamped[FUSED_HOST_ELIDED] === true
149
+ );
127
150
  const ctx = {
128
151
  trackLines: false,
129
152
  ...skipGlobalSinks ? { _pmProfile: profile } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _pmProfile: profile } },
@@ -204,6 +227,10 @@ function deeperFail(a, b) {
204
227
  return a.span.start >= b.span.start ? a : b;
205
228
  }
206
229
 
230
+ // src/analysis/duplication.ts
231
+ var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
232
+ var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
233
+
207
234
  // src/compiler/scannable-run.ts
208
235
  var META = new Set("()[]{}*+?|^$.".split(""));
209
236
 
@@ -238,6 +265,13 @@ function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, trivi
238
265
  return host;
239
266
  }
240
267
  cstBuildHost._parsemanCstOutput = true;
268
+ function fusedHostModeOf(registry) {
269
+ const m = registry[FUSED_HOST_MODE];
270
+ return m === "cst" ? "cst" : "ast";
271
+ }
272
+ function fusedHostElidedOf(registry) {
273
+ return registry[FUSED_HOST_ELIDED] === true;
274
+ }
241
275
 
242
276
  // src/cst/walk.ts
243
277
  function walk(root, visitor, ctx = void 0) {
@@ -282,7 +316,8 @@ function absoluteSpanCST(root, path) {
282
316
  }
283
317
 
284
318
  // src/functional/doc.ts
285
- function mkCtx(state, build, tolerant) {
319
+ function mkCtx(rawState, build, tolerant) {
320
+ const state = rawState ?? void 0;
286
321
  return tolerant ? { trackLines: false, state, build, _tolerant: true, _rec: REC, _errors: [] } : { trackLines: false, state, build };
287
322
  }
288
323
  function asRuleFn(entry) {
@@ -679,6 +714,7 @@ function collectEmbeddedErrors(node2, base, out) {
679
714
  function parseDoc(registry, rootRule, input, opts = {}) {
680
715
  const entry = registry[rootRule];
681
716
  if (!entry) throw new Error(`No rule '${rootRule}' in registry`);
717
+ assertHostModeCompatible(fusedHostModeOf(registry), opts.build, fusedHostElidedOf(registry));
682
718
  const ctx = mkCtx(opts.state, opts.build, !!opts.tolerant);
683
719
  const r = asRuleFn(entry)(input, 0, ctx);
684
720
  if (r.ok) {