parsanol 0.10.44 → 0.10.46

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/runtime.js CHANGED
@@ -44,57 +44,12 @@ function wasm() {
44
44
  }
45
45
  return wasmModule;
46
46
  }
47
- /**
48
- * A loaded, checksum-verified PG artifact with its schema.
49
- * Construction throws when the checksum does not verify.
50
- */
51
- export class PargRuntime {
52
- artifact;
53
- schema;
54
- renderSpec;
55
- entry;
56
- defaultEntry;
57
- /** parsanol-ts#5 provenance: SHA-256 of the .parg source text and the
58
- * compiler version. Null for artifacts compiled before these fields
59
- * existed (unverifiable, not stale). */
60
- sourceHash;
61
- compilerVersion;
62
- source;
63
- /** ruby#377 semantics fingerprint: stable across producer metadata
64
- * (compiler_version, unicode_tables), so gates can tell "re-baked by
65
- * a newer compiler" from "the grammar changed". Null for artifacts
66
- * baked before the field existed (parsanol >= 1.3.117 / rs 0.19.14). */
67
- semanticsHash;
68
- envelope;
47
+ import { PargRuntimeCore } from "./runtime-core.js";
48
+ export { deriveTemplate, renderSegments, materializeFromSchema, RecursionLimitExceeded, CallDepthLimitExceeded, ShapeDepthLimitExceeded } from "./runtime-core.js";
49
+ /** Node entry: preserves synchronous WASM initialization and filesystem helpers. */
50
+ export class PargRuntime extends PargRuntimeCore {
69
51
  constructor(artifactJson, entry) {
70
- const parsed = JSON.parse(artifactJson);
71
- this.envelope = parsed;
72
- // Dynamic artifacts (parsanol-ruby#129 runtime state / custom atoms)
73
- // carry Ruby closures; their grammars deserialize portably but parse
74
- // only on a Ruby runtime. Fail here, at the boundary, with the
75
- // routing answer instead of a wasm deserialization error deep in the
76
- // atom tree.
77
- if (parsed["dynamic"] === true) {
78
- throw new Error("this artifact uses PARG runtime state or custom atoms and parses " +
79
- "only on a Ruby runtime (parsanol-ruby#129)");
80
- }
81
- this.artifact = new (wasm().PargArtifactJs)(artifactJson);
82
- this.schema = JSON.parse(this.artifact.schema());
83
- this.renderSpec =
84
- parsed["render"] ?? {};
85
- // The compiler bakes default_entry: JSON key order is not preserved
86
- // across engines, so the sorted entry list cannot rederive it.
87
- this.defaultEntry = parsed["default_entry"] ?? null;
88
- this.sourceHash = parsed["source_hash"] ?? null;
89
- this.compilerVersion = parsed["compiler_version"] ?? null;
90
- this.source = parsed["source"] ?? null;
91
- this.semanticsHash = parsed["semantics_hash"] ?? null;
92
- this.entry = entry ?? this.defaultEntry ?? this.artifact.entryNames()[0];
93
- }
94
- /** The wire-format family ("parsanol-tree/v2"): a shape bump requires a
95
- * new engine family; same-shape artifacts parse identically forever. */
96
- get shape() {
97
- return this.envelope["shape"] ?? null;
52
+ super(artifactJson, entry, wasm);
98
53
  }
99
54
  /** True when this artifact was compiled from `source` (the current .parg
100
55
  * revision). The compiler bakes a bare hex digest; artifacts without the
@@ -120,130 +75,4 @@ export class PargRuntime {
120
75
  }
121
76
  return PargRuntime.fromFile(join(base, `${grammar}.json`), entry);
122
77
  }
123
- /** Parse with the native wasm engine; returns the parsanol-shape tree. */
124
- parseShape(input) {
125
- return JSON.parse(this.artifact.parseShape(this.entry, input));
126
- }
127
- /**
128
- * Best-effort recovery (TODO.sota/1): never throws. Success returns
129
- * `{ ok: true, shape }`; failure returns
130
- * `{ ok: false, captures, error, consumed_upto }` — the captures
131
- * observed before the failure plus the failure wire.
132
- */
133
- parseShapeRecovering(input) {
134
- return JSON.parse(this.artifact.parseShapeRecovering(this.entry, input));
135
- }
136
- /** Apply the entry's bindings to a parsanol-shape tree. */
137
- applyBindings(shape) {
138
- return JSON.parse(this.artifact.applyBindings(this.entry, JSON.stringify(shape)));
139
- }
140
- /** Apply an entry's DECLARED bindings artifact (parsanol-ruby#432) to
141
- * a parsanol-shape tree. The engine verifies the artifact (kind,
142
- * canonical-JSON checksum, `ts` target pin, binding version) and
143
- * pair-checks it against this artifact by grammar source hash before
144
- * the shared apply core runs — the JSON materialized is the JSON the
145
- * checksum pinned. */
146
- applyBindingsArtifact(bindingsJson, shape) {
147
- return JSON.parse(this.artifact.applyBindingsArtifact(bindingsJson, this.entry, JSON.stringify(shape)));
148
- }
149
- /** Parse and bind in one step. */
150
- parseAndBind(input) {
151
- try {
152
- return JSON.parse(this.artifact.parseAndBind(this.entry, input));
153
- }
154
- catch {
155
- return null;
156
- }
157
- }
158
- /**
159
- * Schema-driven materialization: the schema (from the artifact, not
160
- * hand-written model code) declares the fields a data model must
161
- * implement; the bound captures populate a structurally-typed object.
162
- * Card `1*`/`*` fields become arrays; `0..1` fields become nullable.
163
- */
164
- materialize(input) {
165
- const bound = this.parseAndBind(input);
166
- if (bound === null)
167
- return null;
168
- const schema = this.schema[this.entry];
169
- if (!schema)
170
- throw new Error(`artifact has no schema for entry ${this.entry}`);
171
- return materializeFromSchema(schema, bound);
172
- }
173
- /** Render the identifier string from a bound map (F6). */
174
- render(bound, variant = "default") {
175
- return renderSegments((this.renderSpec[variant] ?? null), bound);
176
- }
177
- /** Parse, bind, and render in one step. */
178
- renderString(input, variant = "default") {
179
- const bound = this.parseAndBind(input);
180
- return bound === null ? null : this.render(bound, variant);
181
- }
182
- /** Evaluate a named derive spec against a bound map (F6). */
183
- derive(name, bound) {
184
- return deriveTemplate((this.envelope["derive"] ?? {}), name, bound);
185
- }
186
- /** Parse, bind, and evaluate a derive spec in one step. */
187
- deriveString(input, name) {
188
- const bound = this.parseAndBind(input);
189
- return bound === null ? null : this.derive(name, bound);
190
- }
191
- /** Run the artifact's embedded tests; empty list means green. */
192
- runTests() {
193
- return JSON.parse(this.artifact.runTests());
194
- }
195
- }
196
- /** F6 v1 derive evaluator: {field} interpolates from the bound map. */
197
- export function deriveTemplate(derive, name, bound) {
198
- const template = derive[name];
199
- if (template === undefined)
200
- throw new Error(`derive spec ${name} not declared`);
201
- return template.replace(/\{(\w+)\}/g, (_, field) => {
202
- const value = bound[field];
203
- return value === undefined || value === null ? "" : String(value);
204
- });
205
- }
206
- /** F6 v1 generic renderer: field / literal / cond-presence segments. */
207
- export function renderSegments(segments, bound) {
208
- let out = "";
209
- for (const segment of segments ?? []) {
210
- if (segment.type === "field") {
211
- const value = bound[segment.field];
212
- out += value === undefined || value === null ? "" : String(value);
213
- }
214
- else if (segment.type === "literal") {
215
- out += segment.text;
216
- }
217
- else if (segment.type === "cond") {
218
- const value = bound[segment.field];
219
- if (value !== undefined && value !== null)
220
- out += renderSegments(segment.then, bound);
221
- }
222
- }
223
- return out;
224
- }
225
- /**
226
- * Schema-driven materialization independent of any wasm handle —
227
- * the same function the model layer will build on (T2 codegen emits the
228
- * static view of exactly these fields).
229
- */
230
- export function materializeFromSchema(schema, bound) {
231
- const attributes = {};
232
- for (const [path, requirements] of Object.entries(schema.fields)) {
233
- const leaf = path.includes("[]")
234
- ? (path.split("].").pop() ?? path)
235
- : path;
236
- const value = bound[leaf];
237
- if (requirements.card.endsWith("*")) {
238
- const list = Array.isArray(value) ? value : value === undefined ? [] : [value];
239
- attributes[leaf] = list;
240
- }
241
- else if (requirements.card === "0..1") {
242
- attributes[leaf] = value === undefined ? null : value;
243
- }
244
- else {
245
- attributes[leaf] = value;
246
- }
247
- }
248
- return { entry: schema.root, attributes };
249
78
  }
package/package.json CHANGED
@@ -1,24 +1,40 @@
1
1
  {
2
2
  "name": "parsanol",
3
- "version": "0.10.44",
3
+ "version": "0.10.46",
4
4
  "description": "PARG artifact runtime for TypeScript — checksum-verified artifact load, wasm parse, bindings, schema-driven materialization",
5
5
  "type": "module",
6
6
  "main": "dist/runtime.js",
7
7
  "types": "dist/runtime.d.ts",
8
8
  "exports": {
9
- ".": "./dist/runtime.js",
10
- "./suite": "./dist/suite.js"
9
+ ".": {
10
+ "browser": {
11
+ "types": "./dist/browser.d.ts",
12
+ "default": "./dist/browser.js"
13
+ },
14
+ "types": "./dist/runtime.d.ts",
15
+ "default": "./dist/runtime.js"
16
+ },
17
+ "./suite": "./dist/suite.js",
18
+ "./browser": {
19
+ "types": "./dist/browser.d.ts",
20
+ "default": "./dist/browser.js"
21
+ }
11
22
  },
12
23
  "files": [
13
24
  "dist/",
14
- "vendor/parsanol-wasm/"
25
+ "vendor/parsanol-wasm/",
26
+ "vendor/parsanol-web/"
15
27
  ],
16
28
  "scripts": {
17
29
  "build": "tsc -p tsconfig.json",
18
30
  "test": "npm run build && npx tsc -p tsconfig.test.json && node --test dist-test/test/*.test.js",
19
31
  "refresh-wasm": "bash scripts/refresh-wasm.sh",
20
32
  "prepublishOnly": "npm run build",
21
- "bench": "node bench/bench.mjs"
33
+ "bench": "node bench/bench.mjs",
34
+ "test:browser": "npm run build && python3 scripts/test-browser.py",
35
+ "refresh-web-wasm": "python3 scripts/refresh-web-wasm.py",
36
+ "refresh-wasm-candidate": "python3 scripts/build-wasm-candidate.py",
37
+ "prepare": "npm run build"
22
38
  },
23
39
  "engines": {
24
40
  "node": ">=22"
@@ -1,2 +1,2 @@
1
- 7257c5c557c569dc14a303349a80feff18032dae
1
+ ca009ee4e8c35f6d09ed2b5be71f65498f29df95
2
2
  built with: wasm-pack build --target=nodejs --features wasm (from parsanol-rs/parsanol)
@@ -0,0 +1,29 @@
1
+ {
2
+ "repository": "https://github.com/parsanol/parsanol-rs",
3
+ "upstream_base": "74d6aa27987db8d3ffa38eb38a7e89c0d1b28da2",
4
+ "source_commit": "ca009ee4e8c35f6d09ed2b5be71f65498f29df95",
5
+ "built_source_commit": "ca009ee4e8c35f6d09ed2b5be71f65498f29df95",
6
+ "source_tree": "d788f65b16879df853bc23b872d641a920b93328",
7
+ "built_source_tree_equal": true,
8
+ "crate_version": "0.20.14",
9
+ "unreleased_candidate": false,
10
+ "target": "nodejs",
11
+ "profile": "release",
12
+ "rust": "1.98.0",
13
+ "wasm_bindgen": "0.2.130",
14
+ "wasm_stack_bytes": 8388608,
15
+ "resource_limits": {
16
+ "rule_reference_recursion": 1000,
17
+ "wasm_vm_atom_calls": 1024
18
+ },
19
+ "lockfile": "scripts/wasm-build/Cargo.lock",
20
+ "lockfile_sha256": "fde2f033284478d85d1d692e1aaf694021554f2a71293b5778cd5f9950099c06",
21
+ "files": {
22
+ "parsanol_bg.wasm": "51aad236d26b19c615e2c7ab41baa07b5e0c415885f20671077fb68f349a6336",
23
+ "parsanol.d.ts": "080f641f566eade5118d0583bad85ad8b8fe428c1e92fe49b41fc115fd0940e2",
24
+ "LICENSE": "47f4778bc0bfbeb3614d173dd1ec09ddd8cab994039193e2d3de2edcd7886c7e",
25
+ "parsanol.cjs": "7f76854b4fae589e870f70480b226fbbf11ab3389de84f33af64890740cad02f",
26
+ "parsanol_bg.wasm.d.ts": "226ea542d938795e094f21f501c4f9e2d9c6b606a92707f3e71a2b6665970448"
27
+ },
28
+ "shape_json_max_depth": 512
29
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ribose Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -150,6 +150,36 @@ class PargArtifactJs {
150
150
  }
151
151
  return takeFromExternrefTable0(ret[0]);
152
152
  }
153
+ /**
154
+ * Explicit compatibility without changing parseShape defaults.
155
+ * The JSON envelope contains either shape or causal error diagnostics;
156
+ * it does not claim best-effort recovery captures.
157
+ * @param {string} entry
158
+ * @param {string} input
159
+ * @param {string} compatibility
160
+ * @returns {string}
161
+ */
162
+ parseShapeWithCompatibility(entry, input, compatibility) {
163
+ let ptr0, len0, ptr1, len1, ptr2, len2;
164
+ try {
165
+ ptr0 = passStringToWasm0(entry, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
166
+ len0 = WASM_VECTOR_LEN;
167
+ ptr1 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
168
+ len1 = WASM_VECTOR_LEN;
169
+ ptr2 = passStringToWasm0(compatibility, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
+ len2 = WASM_VECTOR_LEN;
171
+ } catch (e) {
172
+ if (ptr2) { wasm.__wbindgen_free(ptr2, len2 * 1, 1); }
173
+ if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
174
+ if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
175
+ throw e;
176
+ }
177
+ const ret = wasm.pargartifactjs_parseShapeWithCompatibility(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
178
+ if (ret[2]) {
179
+ throw takeFromExternrefTable0(ret[1]);
180
+ }
181
+ return takeFromExternrefTable0(ret[0]);
182
+ }
153
183
  /**
154
184
  * Parse an entry with the native engine; returns the parsanol-shape
155
185
  * tree as JSON text.
@@ -462,6 +492,10 @@ function __wbg_get_imports() {
462
492
  const ret = new Array();
463
493
  return ret;
464
494
  },
495
+ __wbg_new_787b9fb330d55d78: function(arg0, arg1) {
496
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
497
+ return ret;
498
+ },
465
499
  __wbg_new_bb74001155cb8ca8: function() {
466
500
  const ret = new Error();
467
501
  return ret;
@@ -478,6 +512,9 @@ function __wbg_get_imports() {
478
512
  const ret = Reflect.set(arg0, arg1, arg2);
479
513
  return ret;
480
514
  }, arguments); },
515
+ __wbg_set_name_822e3903f3184979: function(arg0, arg1, arg2) {
516
+ arg0.name = getStringFromWasm0(arg1, arg2);
517
+ },
481
518
  __wbg_stack_575c4e0918581b9c: function(arg0, arg1) {
482
519
  const ret = arg1.stack;
483
520
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -42,6 +42,12 @@ export class PargArtifactJs {
42
42
  * `{"ok": false, "captures": ..., "error": ..., "consumed_upto"}`.
43
43
  */
44
44
  parseShapeRecovering(entry: string, input: string): string;
45
+ /**
46
+ * Explicit compatibility without changing parseShape defaults.
47
+ * The JSON envelope contains either shape or causal error diagnostics;
48
+ * it does not claim best-effort recovery captures.
49
+ */
50
+ parseShapeWithCompatibility(entry: string, input: string, compatibility: string): string;
45
51
  /**
46
52
  * Parse an entry with the native engine; returns the parsanol-shape
47
53
  * tree as JSON text.
@@ -11,10 +11,17 @@ export const pargartifactjs_new: (a: number, b: number) => [number, number, numb
11
11
  export const pargartifactjs_parseAndBind: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
12
12
  export const pargartifactjs_parseShape: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
13
13
  export const pargartifactjs_parseShapeRecovering: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
14
+ export const pargartifactjs_parseShapeWithCompatibility: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
14
15
  export const pargartifactjs_runTests: (a: number) => [number, number, number];
15
16
  export const pargartifactjs_schema: (a: number) => [number, number, number];
16
17
  export const pargartifactjs_schemaTypescript: (a: number) => [number, number, number];
17
18
  export const pargartifactjs_semanticsHash: (a: number) => any;
19
+ export const setPanicHook: () => void;
20
+ export const wasmparser_fromArtifact: (a: number, b: number, c: number, d: number) => [number, number, number];
21
+ export const wasmparser_new: (a: number, b: number) => [number, number, number];
22
+ export const wasmparser_parse: (a: number, b: number, c: number) => [number, number, number];
23
+ export const wasmparser_parse_flat: (a: number, b: number, c: number) => [number, number, number, number];
24
+ export const wasmparser_parse_json: (a: number, b: number, c: number) => [number, number, number, number];
18
25
  export const parsanol_c_last_error: () => number;
19
26
  export const parsanol_c_parse: (a: bigint, b: number, c: number, d: number) => number;
20
27
  export const parsanol_c_parse_len: (a: bigint, b: number, c: number, d: number, e: number) => number;
@@ -29,6 +36,7 @@ export const parsanol_parg_error: (a: number, b: number) => number;
29
36
  export const parsanol_parg_free: (a: number) => void;
30
37
  export const parsanol_parg_parse: (a: number, b: number) => number;
31
38
  export const parsanol_parg_parse_recovering: (a: number, b: number, c: number) => number;
39
+ export const parsanol_parg_parse_with_compatibility: (a: number, b: number, c: number, d: number) => number;
32
40
  export const parsanol_parse: (a: number, b: number, c: number) => number;
33
41
  export const parsanol_parse_end_pos: (a: number, b: number) => number;
34
42
  export const parsanol_parse_simple: (a: number, b: number) => number;
@@ -38,12 +46,6 @@ export const parsanol_result_error: (a: number) => number;
38
46
  export const parsanol_result_free: (a: number) => void;
39
47
  export const parsanol_result_success: (a: number) => number;
40
48
  export const parsanol_version: () => number;
41
- export const setPanicHook: () => void;
42
- export const wasmparser_fromArtifact: (a: number, b: number, c: number, d: number) => [number, number, number];
43
- export const wasmparser_new: (a: number, b: number) => [number, number, number];
44
- export const wasmparser_parse: (a: number, b: number, c: number) => [number, number, number];
45
- export const wasmparser_parse_flat: (a: number, b: number, c: number) => [number, number, number, number];
46
- export const wasmparser_parse_json: (a: number, b: number, c: number) => [number, number, number, number];
47
49
  export const parsanol_string_free: (a: number) => void;
48
50
  export const __wbindgen_malloc: (a: number, b: number) => number;
49
51
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -0,0 +1,17 @@
1
+ {
2
+ "package": "@parsanol/wasm",
3
+ "version": "0.20.14",
4
+ "target": "web",
5
+ "repository": "https://github.com/parsanol/parsanol-rs",
6
+ "tarball": "https://registry.npmjs.org/@parsanol/wasm/-/wasm-0.20.14.tgz",
7
+ "integrity": "sha512-Q+ePDOYQD0HTpcmXOG2nm+hOmtJ9fDq6J/lP15WeJWNLxosRsAiWfTxBKFC4eUTK3HBNbsMG113zjPKbyjTKVg==",
8
+ "tarball_sha256": "f62fc7d7dc9cbad3d7c25bdcf3b61f3a6065829bd525c07ba27383457d1642a9",
9
+ "files": {
10
+ "parsanol.js": "5a2c63258b262951933f6ba5cd31cf66b99fcdb48ab1db2e150ef6872f159ba7",
11
+ "parsanol.d.ts": "dabb75bc30f336da7669f8fabbac8bef438a222b8117e111384e3e860816d38b",
12
+ "parsanol_bg.wasm": "72e943ca98a70fc7eb421a2f8614aff9d6e954b1fe99c800d362fe65aeac41bf",
13
+ "parsanol_bg.wasm.d.ts": "ee98ada66ab5b00ac557631d39e6cdc725e90221e110d32a65395804a46c20ec",
14
+ "README.md": "577c2d75ac98c331379a50698624b68c773eb4603648108f80f4399fde33d339",
15
+ "LICENSE": "47f4778bc0bfbeb3614d173dd1ec09ddd8cab994039193e2d3de2edcd7886c7e"
16
+ }
17
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ribose Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # @parsanol/wasm
2
+
3
+ Parsanol PEG parser — WebAssembly bindings (checksummed
4
+ parsanol-tree/v2 artifacts; parse, shape, recovery, bindings,
5
+ schema types).
6
+
7
+ ## Browser
8
+
9
+ ```js
10
+ import init, { PargArtifactJs } from "@parsanol/wasm";
11
+ await init(); // fetches parsanol_bg.wasm next to the module
12
+ const parg = new PargArtifactJs(artifactJson);
13
+ const bound = parg.parseAndBind("identifier", "iso 12345");
14
+ ```
15
+
16
+ ## Node
17
+
18
+ The default init fetches relative to the module, which Node's fetch
19
+ does not serve; read the bytes and hand them to `initSync` (plain
20
+ `initSync(bytes)` works but warns as deprecated):
21
+
22
+ ```js
23
+ import { initSync, PargArtifactJs } from "@parsanol/wasm";
24
+ import { readFileSync } from "node:fs";
25
+
26
+ initSync({ module: readFileSync("node_modules/@parsanol/wasm/parsanol_bg.wasm") });
27
+ const parg = new PargArtifactJs(artifactJson);
28
+ ```
29
+
30
+ ## Notes
31
+
32
+ - The engine is built with an 8MiB wasm stack
33
+ (`-C link-arg=-zstack-size=8388608`) so deep-recursive parses abort
34
+ with the typed `CallDepthLimitExceeded` instead of trapping.
35
+ - `parseAndBind` returns `{}` when the entry declares no
36
+ `bindings` block — the parse succeeded, nothing was bound.
37
+ - The async bootstrap is the package DEFAULT export
38
+ (`__wbg_init(module_or_path?)`); `setPanicHook` installs the panic
39
+ hook directly and is called by the bootstrap.