@gmb/bitmark-parser 6.11.1 → 7.1.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 +361 -57
- package/dist/browser/bitmark-parser.min.js +4 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- package/dist/browser/cjs/index.cjs +966 -372
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +642 -70
- package/dist/browser/esm/index.d.ts +642 -70
- package/dist/browser/esm/index.js +958 -371
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +790 -247
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
- package/dist/index.cjs +163 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +637 -70
- package/dist/index.d.ts +637 -70
- package/dist/index.js +155 -123
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +8 -30
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.d.cts +0 -2
- package/dist/legacy.d.ts +0 -2
- package/dist/legacy.js +8 -30
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs +1 -5
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +7 -7
- package/schema/bitmark.schema.json +507 -141
- package/wasm/bitmark_wasm.d.ts +65 -26
- package/wasm/bitmark_wasm.js +348 -116
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +6 -3
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +56 -15
- package/wasm-bitmark-json/bitmark_json_wasm.js +321 -77
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +5 -2
- package/wasm-bitmark-json/package.json +1 -1
- package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +65 -26
- package/wasm-browser-full/bitmark_browser_full_wasm.js +348 -116
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +6 -3
- package/wasm-browser-full/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -31,24 +31,31 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
ALL_LANGUAGES: () => ALL_LANGUAGES,
|
|
34
|
+
CompletionItemKind: () => CompletionItemKind,
|
|
35
|
+
CompletionItemTag: () => CompletionItemTag,
|
|
36
|
+
DiagnosticSeverity: () => DiagnosticSeverity,
|
|
34
37
|
NotInitializedError: () => NotInitializedError,
|
|
35
38
|
RegisterError: () => RegisterError,
|
|
36
39
|
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
37
40
|
bitmarkToObjects: () => bitmarkToObjects,
|
|
38
41
|
breakscapeText: () => breakscapeText,
|
|
39
42
|
canonicalize: () => canonicalize,
|
|
43
|
+
complete: () => complete,
|
|
40
44
|
convert: () => convert,
|
|
41
45
|
countBits: () => countBits,
|
|
46
|
+
diagnostics: () => diagnostics,
|
|
42
47
|
diff: () => diff,
|
|
43
48
|
diffBits: () => diffBits,
|
|
49
|
+
hover: () => hover,
|
|
44
50
|
info: () => info,
|
|
45
51
|
init: () => init,
|
|
46
52
|
initSync: () => initSync,
|
|
47
53
|
legacy: () => legacy_exports,
|
|
48
|
-
lex: () => lex,
|
|
49
54
|
objectsToBitmark: () => objectsToBitmark,
|
|
50
55
|
patchEntry: () => patchEntry,
|
|
51
56
|
register: () => register,
|
|
57
|
+
resolve: () => resolve,
|
|
58
|
+
semanticTokens: () => semanticTokens,
|
|
52
59
|
splitBits: () => splitBits,
|
|
53
60
|
transform: () => transform,
|
|
54
61
|
transformParallel: () => transformParallel,
|
|
@@ -68,7 +75,7 @@ var import_node_module = require("module");
|
|
|
68
75
|
// src/generated/package_info.ts
|
|
69
76
|
var PACKAGE_INFO = {
|
|
70
77
|
"name": "@gmb/bitmark-parser",
|
|
71
|
-
"version": "
|
|
78
|
+
"version": "7.1.0",
|
|
72
79
|
"author": "Get More Brain Ltd <info@getmorebrain.com>",
|
|
73
80
|
"license": "ISC",
|
|
74
81
|
"description": "A parser for bitmark text, powered by WebAssembly."
|
|
@@ -107,8 +114,11 @@ function getActive() {
|
|
|
107
114
|
}
|
|
108
115
|
function setActive(feature, module2) {
|
|
109
116
|
for (const [type, data] of registrations) {
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
try {
|
|
118
|
+
module2.register(type, data);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw new RegisterError(e instanceof Error ? e.message : String(e));
|
|
121
|
+
}
|
|
112
122
|
}
|
|
113
123
|
active = module2;
|
|
114
124
|
activeFeature = feature;
|
|
@@ -124,13 +134,6 @@ function variant() {
|
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
// src/core/hooked-transform.ts
|
|
127
|
-
function isError(s) {
|
|
128
|
-
return s.startsWith("error:");
|
|
129
|
-
}
|
|
130
|
-
function errorString(e) {
|
|
131
|
-
const m = e instanceof Error ? e.message : String(e);
|
|
132
|
-
return m.startsWith("error:") ? m : `error: ${m}`;
|
|
133
|
-
}
|
|
134
137
|
function stripArray(doc) {
|
|
135
138
|
const t = doc.trim();
|
|
136
139
|
return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
|
|
@@ -142,17 +145,13 @@ function patchJsonOf(patch) {
|
|
|
142
145
|
}
|
|
143
146
|
function buildUnits(wasm, input, inputIsBitmark) {
|
|
144
147
|
if (inputIsBitmark) {
|
|
145
|
-
const
|
|
146
|
-
if (isError(out2)) throw new Error(out2);
|
|
147
|
-
const slices = JSON.parse(out2);
|
|
148
|
+
const slices = JSON.parse(wasm.split_bits(input));
|
|
148
149
|
return slices.map((s) => ({
|
|
149
150
|
view: { format: "bitmark", index: s.index, total: slices.length, source: s.source },
|
|
150
151
|
source: s.source
|
|
151
152
|
}));
|
|
152
153
|
}
|
|
153
|
-
const
|
|
154
|
-
if (isError(out)) throw new Error(out);
|
|
155
|
-
const envelopes = JSON.parse(out);
|
|
154
|
+
const envelopes = JSON.parse(wasm.split_json_bits(input));
|
|
156
155
|
return envelopes.map((env, index) => ({
|
|
157
156
|
view: { format: "json", index, total: envelopes.length, bit: env.bit ?? {} },
|
|
158
157
|
// Per-bit transform consumes a one-bit JSON document.
|
|
@@ -168,6 +167,7 @@ function planTransform(wasm, input, options) {
|
|
|
168
167
|
const sel = options.inputFormat ?? "auto";
|
|
169
168
|
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
170
169
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
170
|
+
wasm.transform("", "bitmark", output, mode, "", false, indent, spacesAroundValues);
|
|
171
171
|
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
172
172
|
const total = units.length;
|
|
173
173
|
const hooked = [];
|
|
@@ -183,9 +183,9 @@ function planTransform(wasm, input, options) {
|
|
|
183
183
|
if (patchJson === "") {
|
|
184
184
|
resolved = units.map((_, index) => ({ source: index, bit: null, patch: [] }));
|
|
185
185
|
} else {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
resolved = JSON.parse(
|
|
187
|
+
wasm.resolve_patch_document(input, inputFormat, patchJson)
|
|
188
|
+
);
|
|
189
189
|
}
|
|
190
190
|
const jobs = [];
|
|
191
191
|
const views = [];
|
|
@@ -232,25 +232,18 @@ function computeBit(wasm, job) {
|
|
|
232
232
|
2,
|
|
233
233
|
job.spacesAroundValues
|
|
234
234
|
);
|
|
235
|
-
if (isError(out)) return out;
|
|
236
235
|
return job.outputFormat === "json" ? stripArray(out) : out;
|
|
237
236
|
}
|
|
238
237
|
function recombine(wasm, elements, output, pretty, indent) {
|
|
239
|
-
if (output
|
|
238
|
+
if (output !== "json") return elements.join("\n");
|
|
240
239
|
const arr = `[${elements.join(",")}]`;
|
|
241
240
|
return pretty ? wasm.prettify(arr, indent) : arr;
|
|
242
241
|
}
|
|
243
242
|
function runHookedTransform(wasm, input, options) {
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
plan = planTransform(wasm, input, options);
|
|
247
|
-
} catch (e) {
|
|
248
|
-
return errorString(e);
|
|
249
|
-
}
|
|
243
|
+
const plan = planTransform(wasm, input, options);
|
|
250
244
|
const rendered = [];
|
|
251
245
|
for (let i = 0; i < plan.jobs.length; i++) {
|
|
252
246
|
const element = computeBit(wasm, plan.jobs[i]);
|
|
253
|
-
if (isError(element)) return element;
|
|
254
247
|
options.postHook?.(plan.views[i], element);
|
|
255
248
|
rendered.push(element);
|
|
256
249
|
}
|
|
@@ -259,20 +252,9 @@ function runHookedTransform(wasm, input, options) {
|
|
|
259
252
|
|
|
260
253
|
// src/core/parallel.ts
|
|
261
254
|
async function orchestrateParallel(wasm, input, options, runJobs) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
plan = planTransform(wasm, input, options);
|
|
265
|
-
} catch (e) {
|
|
266
|
-
return errorString(e);
|
|
267
|
-
}
|
|
268
|
-
let elements;
|
|
269
|
-
try {
|
|
270
|
-
elements = await runJobs(plan.jobs, options.workers ?? 4);
|
|
271
|
-
} catch (e) {
|
|
272
|
-
return errorString(e);
|
|
273
|
-
}
|
|
255
|
+
const plan = planTransform(wasm, input, options);
|
|
256
|
+
const elements = await runJobs(plan.jobs, options.workers ?? 4);
|
|
274
257
|
for (let i = 0; i < elements.length; i++) {
|
|
275
|
-
if (isError(elements[i])) return elements[i];
|
|
276
258
|
options.postHook?.(plan.views[i], elements[i]);
|
|
277
259
|
}
|
|
278
260
|
return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
|
|
@@ -281,62 +263,57 @@ async function orchestrateParallel(wasm, input, options, runJobs) {
|
|
|
281
263
|
// src/node/pool.ts
|
|
282
264
|
var import_node_url = require("url");
|
|
283
265
|
var import_node_worker_threads = require("worker_threads");
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
function runJobsParallel(jobs, workers, feature) {
|
|
266
|
+
|
|
267
|
+
// src/core/pool.ts
|
|
268
|
+
function runJobsWithPool(jobs, workers, spawn) {
|
|
288
269
|
if (jobs.length === 0) return Promise.resolve([]);
|
|
289
270
|
const poolSize = Math.max(1, Math.min(workers, jobs.length));
|
|
290
|
-
|
|
291
|
-
return new Promise((resolve, reject) => {
|
|
271
|
+
return new Promise((resolve2, reject) => {
|
|
292
272
|
const results = new Array(jobs.length);
|
|
293
273
|
let next = 0;
|
|
294
274
|
let settled = 0;
|
|
295
275
|
let done = false;
|
|
296
276
|
const pool = [];
|
|
297
|
-
const
|
|
298
|
-
for (const w of pool) void w.terminate();
|
|
299
|
-
};
|
|
300
|
-
const fail = (err) => {
|
|
277
|
+
const finish = (err) => {
|
|
301
278
|
if (done) return;
|
|
302
279
|
done = true;
|
|
303
|
-
|
|
304
|
-
reject(err);
|
|
280
|
+
for (const w of pool) w.terminate();
|
|
281
|
+
if (err) reject(err);
|
|
282
|
+
else resolve2(results);
|
|
305
283
|
};
|
|
306
284
|
const dispatch = (w) => {
|
|
307
|
-
if (done) return;
|
|
308
|
-
if (next >= jobs.length) return;
|
|
285
|
+
if (done || next >= jobs.length) return;
|
|
309
286
|
const id = next++;
|
|
310
|
-
w.
|
|
287
|
+
w.post({ id, job: jobs[id] });
|
|
311
288
|
};
|
|
312
289
|
for (let i = 0; i < poolSize; i++) {
|
|
313
|
-
const w =
|
|
314
|
-
pool.push(w);
|
|
315
|
-
w.on("message", (res) => {
|
|
290
|
+
const w = spawn((res) => {
|
|
316
291
|
if (done) return;
|
|
317
|
-
if (!res.ok)
|
|
318
|
-
fail(new Error(res.error ?? "worker job failed"));
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
292
|
+
if (!res.ok) return finish(new Error(res.error ?? "worker job failed"));
|
|
321
293
|
results[res.id] = res.element;
|
|
322
|
-
settled
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
resolve(results);
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
dispatch(w);
|
|
330
|
-
});
|
|
331
|
-
w.on("error", fail);
|
|
332
|
-
w.on("exit", (code) => {
|
|
333
|
-
if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));
|
|
334
|
-
});
|
|
294
|
+
if (++settled === jobs.length) finish();
|
|
295
|
+
else dispatch(w);
|
|
296
|
+
}, finish);
|
|
297
|
+
pool.push(w);
|
|
335
298
|
}
|
|
336
299
|
for (const w of pool) dispatch(w);
|
|
337
300
|
});
|
|
338
301
|
}
|
|
339
302
|
|
|
303
|
+
// src/node/pool.ts
|
|
304
|
+
function runJobsParallel(jobs, workers, feature) {
|
|
305
|
+
const path2 = (0, import_node_url.fileURLToPath)(new URL("./worker-entry.cjs", importMetaUrl));
|
|
306
|
+
return runJobsWithPool(jobs, workers, (onResult, onError) => {
|
|
307
|
+
const w = new import_node_worker_threads.Worker(path2, { workerData: { feature } });
|
|
308
|
+
w.on("message", (res) => onResult(res));
|
|
309
|
+
w.on("error", onError);
|
|
310
|
+
w.on("exit", (code) => {
|
|
311
|
+
if (code !== 0) onError(new Error(`worker exited with code ${code}`));
|
|
312
|
+
});
|
|
313
|
+
return { post: (msg) => w.postMessage(msg), terminate: () => void w.terminate() };
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
340
317
|
// src/node/transform-parallel.ts
|
|
341
318
|
function runParallelTransform(wasm, input, options) {
|
|
342
319
|
const feature = variant() ?? "full";
|
|
@@ -627,10 +604,7 @@ var Builder = class {
|
|
|
627
604
|
}
|
|
628
605
|
}
|
|
629
606
|
this.parseStringTexts(bit);
|
|
630
|
-
const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false);
|
|
631
|
-
if (out.startsWith("error:")) {
|
|
632
|
-
throw new Error(out.slice("error:".length).trim());
|
|
633
|
-
}
|
|
607
|
+
const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false, "", "");
|
|
634
608
|
const entries = JSON.parse(out);
|
|
635
609
|
const built = entries[0]?.bit ?? bit;
|
|
636
610
|
for (const [key, value] of Object.entries(bit)) {
|
|
@@ -767,8 +741,7 @@ var BitmarkParserGenerator = class {
|
|
|
767
741
|
const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
|
|
768
742
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
769
743
|
const includeUnknown = !jsonOptions.excludeUnknownProperties;
|
|
770
|
-
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false);
|
|
771
|
-
this.throwOnError(out);
|
|
744
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false, "", "");
|
|
772
745
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
773
746
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
774
747
|
}
|
|
@@ -802,7 +775,6 @@ var BitmarkParserGenerator = class {
|
|
|
802
775
|
);
|
|
803
776
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
804
777
|
const out = wasm.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
|
|
805
|
-
this.throwOnError(out);
|
|
806
778
|
if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
807
779
|
if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
808
780
|
if (pretty || jsonOptions.stringify) return out;
|
|
@@ -819,7 +791,6 @@ var BitmarkParserGenerator = class {
|
|
|
819
791
|
const { pretty, indent } = prettyIndent(opts.prettify);
|
|
820
792
|
const coreFormat = format === "pojo" ? "json" : format;
|
|
821
793
|
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true, "");
|
|
822
|
-
this.throwOnError(out);
|
|
823
794
|
if (format === "pojo") return JSON.parse(out);
|
|
824
795
|
return out;
|
|
825
796
|
}
|
|
@@ -851,8 +822,7 @@ var BitmarkParserGenerator = class {
|
|
|
851
822
|
const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
|
|
852
823
|
if (!isHtmlInput) {
|
|
853
824
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
854
|
-
const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false);
|
|
855
|
-
this.throwOnError(out2);
|
|
825
|
+
const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false, "", "");
|
|
856
826
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
857
827
|
}
|
|
858
828
|
const bitType = opts.tableFormat === "table" ? "table" : "table-extended";
|
|
@@ -861,13 +831,11 @@ var BitmarkParserGenerator = class {
|
|
|
861
831
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
862
832
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
863
833
|
if (outputFormat === "html") {
|
|
864
|
-
const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false);
|
|
865
|
-
this.throwOnError(out2);
|
|
834
|
+
const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false, "", "");
|
|
866
835
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
867
836
|
}
|
|
868
837
|
const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
|
|
869
|
-
const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false);
|
|
870
|
-
this.throwOnError(out);
|
|
838
|
+
const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false, "", "");
|
|
871
839
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
872
840
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
873
841
|
}
|
|
@@ -891,8 +859,7 @@ var BitmarkParserGenerator = class {
|
|
|
891
859
|
const opts = Object.assign({}, options);
|
|
892
860
|
const wasm = getLegacyWasm();
|
|
893
861
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
894
|
-
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false);
|
|
895
|
-
this.throwOnError(out);
|
|
862
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false, "", "");
|
|
896
863
|
return makePseudoAst(JSON.parse(out));
|
|
897
864
|
}
|
|
898
865
|
/**
|
|
@@ -944,11 +911,9 @@ var BitmarkParserGenerator = class {
|
|
|
944
911
|
}
|
|
945
912
|
if (ast !== void 0) {
|
|
946
913
|
const out2 = isBitmarkText ? wasm.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
|
|
947
|
-
this.throwOnError(out2);
|
|
948
914
|
return this.deliver(out2, opts.outputFile, opts.fileOptions);
|
|
949
915
|
}
|
|
950
916
|
const out = wasm.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
|
|
951
|
-
this.throwOnError(out);
|
|
952
917
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
953
918
|
const outStr = pretty ? wasm.prettify(out, indent) : out;
|
|
954
919
|
if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
|
|
@@ -966,7 +931,6 @@ var BitmarkParserGenerator = class {
|
|
|
966
931
|
"bitmark++",
|
|
967
932
|
"body"
|
|
968
933
|
);
|
|
969
|
-
this.throwOnError(out);
|
|
970
934
|
return out;
|
|
971
935
|
}
|
|
972
936
|
/**
|
|
@@ -981,7 +945,6 @@ var BitmarkParserGenerator = class {
|
|
|
981
945
|
if (inputFormat === "bitmarkText") {
|
|
982
946
|
const ast = wasm.convert_text(String(input), "textToAst", "bitmark++", "body");
|
|
983
947
|
const out2 = wasm.convert_text(ast, "astToPlainText", "bitmark++", "body");
|
|
984
|
-
this.throwOnError(out2);
|
|
985
948
|
return out2;
|
|
986
949
|
}
|
|
987
950
|
if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm.is_bitmark(input)) {
|
|
@@ -998,8 +961,7 @@ var BitmarkParserGenerator = class {
|
|
|
998
961
|
}
|
|
999
962
|
}
|
|
1000
963
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
1001
|
-
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false);
|
|
1002
|
-
this.throwOnError(out);
|
|
964
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false, "", "");
|
|
1003
965
|
return out;
|
|
1004
966
|
}
|
|
1005
967
|
/** If `s` parses as a TextAst JSON array, return it. */
|
|
@@ -1103,12 +1065,6 @@ var BitmarkParserGenerator = class {
|
|
|
1103
1065
|
encoding: fileOptions?.encoding ?? "utf8"
|
|
1104
1066
|
});
|
|
1105
1067
|
}
|
|
1106
|
-
/** The core reports failures as `error:`-prefixed strings; bpg throws. */
|
|
1107
|
-
throwOnError(out) {
|
|
1108
|
-
if (out.startsWith("error:")) {
|
|
1109
|
-
throw new Error(out.slice("error:".length).trim());
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
1068
|
};
|
|
1113
1069
|
function extractHtmlTables(html) {
|
|
1114
1070
|
const tables = [];
|
|
@@ -1145,7 +1101,6 @@ function extractHtmlTables(html) {
|
|
|
1145
1101
|
}
|
|
1146
1102
|
function bitmarkTextParse(text) {
|
|
1147
1103
|
const out = getLegacyWasm().convert_text(text, "textToAst", "bitmark++", "body");
|
|
1148
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1149
1104
|
return JSON.parse(out);
|
|
1150
1105
|
}
|
|
1151
1106
|
|
|
@@ -1468,6 +1423,24 @@ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
|
|
|
1468
1423
|
var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
|
|
1469
1424
|
var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
|
|
1470
1425
|
|
|
1426
|
+
// src/editor-types.ts
|
|
1427
|
+
var DiagnosticSeverity = {
|
|
1428
|
+
Error: 1,
|
|
1429
|
+
Warning: 2,
|
|
1430
|
+
Information: 3,
|
|
1431
|
+
Hint: 4
|
|
1432
|
+
};
|
|
1433
|
+
var CompletionItemKind = {
|
|
1434
|
+
Class: 7,
|
|
1435
|
+
Property: 10,
|
|
1436
|
+
Value: 12,
|
|
1437
|
+
Keyword: 14,
|
|
1438
|
+
Snippet: 15,
|
|
1439
|
+
EnumMember: 20,
|
|
1440
|
+
TypeParameter: 25
|
|
1441
|
+
};
|
|
1442
|
+
var CompletionItemTag = { Deprecated: 1 };
|
|
1443
|
+
|
|
1471
1444
|
// src/types.ts
|
|
1472
1445
|
function patchEntry(path2, op, value) {
|
|
1473
1446
|
return value === void 0 ? { path: path2, op } : { path: path2, op, value };
|
|
@@ -1475,11 +1448,6 @@ function patchEntry(path2, op, value) {
|
|
|
1475
1448
|
var ALL_LANGUAGES = "all";
|
|
1476
1449
|
|
|
1477
1450
|
// src/core/api.ts
|
|
1478
|
-
function lex(input, options = {}) {
|
|
1479
|
-
const wasm = getActive();
|
|
1480
|
-
if (typeof wasm.lex !== "function") throw new UnsupportedFeatureError("lex", variant());
|
|
1481
|
-
return wasm.lex(input, options.stage ?? "lex");
|
|
1482
|
-
}
|
|
1483
1451
|
function bitmarkToObjects(input, options = {}) {
|
|
1484
1452
|
const out = getActive().convert(
|
|
1485
1453
|
input,
|
|
@@ -1490,9 +1458,10 @@ function bitmarkToObjects(input, options = {}) {
|
|
|
1490
1458
|
2,
|
|
1491
1459
|
1,
|
|
1492
1460
|
options.includeUnknownProperties ?? false,
|
|
1493
|
-
false
|
|
1461
|
+
false,
|
|
1462
|
+
"",
|
|
1463
|
+
""
|
|
1494
1464
|
);
|
|
1495
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1496
1465
|
return JSON.parse(out);
|
|
1497
1466
|
}
|
|
1498
1467
|
function objectsToBitmark(bits, options = {}) {
|
|
@@ -1508,9 +1477,10 @@ function objectsToBitmark(bits, options = {}) {
|
|
|
1508
1477
|
2,
|
|
1509
1478
|
1,
|
|
1510
1479
|
false,
|
|
1511
|
-
false
|
|
1480
|
+
false,
|
|
1481
|
+
"",
|
|
1482
|
+
""
|
|
1512
1483
|
);
|
|
1513
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1514
1484
|
return out;
|
|
1515
1485
|
}
|
|
1516
1486
|
function convert(input, options = {}) {
|
|
@@ -1523,7 +1493,65 @@ function convert(input, options = {}) {
|
|
|
1523
1493
|
options.indent ?? 2,
|
|
1524
1494
|
options.spacesAroundValues ?? 1,
|
|
1525
1495
|
options.includeUnknownProperties ?? false,
|
|
1526
|
-
options.mappingReport ?? false
|
|
1496
|
+
options.mappingReport ?? false,
|
|
1497
|
+
options.positionEncoding ?? "",
|
|
1498
|
+
options.tokensLayout ?? ""
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
function semanticTokens(input, options = {}) {
|
|
1502
|
+
return JSON.parse(
|
|
1503
|
+
convert(input, {
|
|
1504
|
+
inputFormat: "bitmark",
|
|
1505
|
+
outputFormat: "semantic-tokens",
|
|
1506
|
+
positionEncoding: options.positionEncoding,
|
|
1507
|
+
tokensLayout: options.tokensLayout
|
|
1508
|
+
})
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
function diagnostics(input, options = {}) {
|
|
1512
|
+
return JSON.parse(
|
|
1513
|
+
convert(input, {
|
|
1514
|
+
inputFormat: "bitmark",
|
|
1515
|
+
outputFormat: "diagnostics",
|
|
1516
|
+
positionEncoding: options.positionEncoding
|
|
1517
|
+
})
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
function complete(input, position, options = {}) {
|
|
1521
|
+
const wasm = getActive();
|
|
1522
|
+
if (typeof wasm.complete !== "function") throw new UnsupportedFeatureError("complete", variant());
|
|
1523
|
+
return JSON.parse(
|
|
1524
|
+
wasm.complete(
|
|
1525
|
+
input,
|
|
1526
|
+
position.line,
|
|
1527
|
+
position.character,
|
|
1528
|
+
options.positionEncoding ?? "",
|
|
1529
|
+
options.includeDeprecated ?? false,
|
|
1530
|
+
options.triggerCharacter ?? ""
|
|
1531
|
+
)
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
function resolve(input, position, item, options = {}) {
|
|
1535
|
+
const wasm = getActive();
|
|
1536
|
+
if (typeof wasm.resolve !== "function") throw new UnsupportedFeatureError("resolve", variant());
|
|
1537
|
+
const resolved = JSON.parse(
|
|
1538
|
+
wasm.resolve(
|
|
1539
|
+
input,
|
|
1540
|
+
position.line,
|
|
1541
|
+
position.character,
|
|
1542
|
+
options.positionEncoding ?? "",
|
|
1543
|
+
options.includeDeprecated ?? false,
|
|
1544
|
+
item.label,
|
|
1545
|
+
item.kind
|
|
1546
|
+
)
|
|
1547
|
+
);
|
|
1548
|
+
return resolved ?? item;
|
|
1549
|
+
}
|
|
1550
|
+
function hover(input, position, options = {}) {
|
|
1551
|
+
const wasm = getActive();
|
|
1552
|
+
if (typeof wasm.hover !== "function") throw new UnsupportedFeatureError("hover", variant());
|
|
1553
|
+
return JSON.parse(
|
|
1554
|
+
wasm.hover(input, position.line, position.character, options.positionEncoding ?? "")
|
|
1527
1555
|
);
|
|
1528
1556
|
}
|
|
1529
1557
|
function canonicalize(input, options = {}) {
|
|
@@ -1537,9 +1565,7 @@ function canonicalize(input, options = {}) {
|
|
|
1537
1565
|
);
|
|
1538
1566
|
}
|
|
1539
1567
|
function countBits(input) {
|
|
1540
|
-
|
|
1541
|
-
if (out.startsWith("error:")) throw new Error(out);
|
|
1542
|
-
return Number.parseInt(out, 10);
|
|
1568
|
+
return Number.parseInt(getActive().count_bits(input), 10);
|
|
1543
1569
|
}
|
|
1544
1570
|
function splitBits(input) {
|
|
1545
1571
|
return JSON.parse(getActive().split_bits(input));
|
|
@@ -1575,7 +1601,6 @@ function diff(a, b, options = {}) {
|
|
|
1575
1601
|
options.bboxTolerance ?? 8,
|
|
1576
1602
|
options.spacesAroundValues ?? 0
|
|
1577
1603
|
);
|
|
1578
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1579
1604
|
return out;
|
|
1580
1605
|
}
|
|
1581
1606
|
function diffBits(a, b, options = {}) {
|
|
@@ -1601,7 +1626,11 @@ function info(options = {}) {
|
|
|
1601
1626
|
const onlyDeprecated = options.onlyDeprecated ?? false;
|
|
1602
1627
|
const full = options.full ?? false;
|
|
1603
1628
|
const language = typeof options.language === "string" ? options.language : options.language?.join(",") ?? "";
|
|
1604
|
-
|
|
1629
|
+
const wasm = getActive();
|
|
1630
|
+
if (format !== "json" && typeof wasm.info_text_supported !== "function") {
|
|
1631
|
+
throw new UnsupportedFeatureError('info (format: "text")', variant());
|
|
1632
|
+
}
|
|
1633
|
+
return wasm.info(
|
|
1605
1634
|
infoType,
|
|
1606
1635
|
format,
|
|
1607
1636
|
bit,
|
|
@@ -1614,8 +1643,11 @@ function info(options = {}) {
|
|
|
1614
1643
|
);
|
|
1615
1644
|
}
|
|
1616
1645
|
function register(options) {
|
|
1617
|
-
|
|
1618
|
-
|
|
1646
|
+
try {
|
|
1647
|
+
getActive().register(options.type, options.data);
|
|
1648
|
+
} catch (e) {
|
|
1649
|
+
throw new RegisterError(e instanceof Error ? e.message : String(e));
|
|
1650
|
+
}
|
|
1619
1651
|
rememberRegistration(options.type, options.data);
|
|
1620
1652
|
}
|
|
1621
1653
|
|
|
@@ -1651,24 +1683,31 @@ function transformParallel(input, options = {}) {
|
|
|
1651
1683
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1652
1684
|
0 && (module.exports = {
|
|
1653
1685
|
ALL_LANGUAGES,
|
|
1686
|
+
CompletionItemKind,
|
|
1687
|
+
CompletionItemTag,
|
|
1688
|
+
DiagnosticSeverity,
|
|
1654
1689
|
NotInitializedError,
|
|
1655
1690
|
RegisterError,
|
|
1656
1691
|
UnsupportedFeatureError,
|
|
1657
1692
|
bitmarkToObjects,
|
|
1658
1693
|
breakscapeText,
|
|
1659
1694
|
canonicalize,
|
|
1695
|
+
complete,
|
|
1660
1696
|
convert,
|
|
1661
1697
|
countBits,
|
|
1698
|
+
diagnostics,
|
|
1662
1699
|
diff,
|
|
1663
1700
|
diffBits,
|
|
1701
|
+
hover,
|
|
1664
1702
|
info,
|
|
1665
1703
|
init,
|
|
1666
1704
|
initSync,
|
|
1667
1705
|
legacy,
|
|
1668
|
-
lex,
|
|
1669
1706
|
objectsToBitmark,
|
|
1670
1707
|
patchEntry,
|
|
1671
1708
|
register,
|
|
1709
|
+
resolve,
|
|
1710
|
+
semanticTokens,
|
|
1672
1711
|
splitBits,
|
|
1673
1712
|
transform,
|
|
1674
1713
|
transformParallel,
|