parsanol 0.10.34 → 0.10.36

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.
@@ -0,0 +1,29 @@
1
+ export declare const BINDINGS_ARTIFACT_KIND = "parg-bindings";
2
+ export declare const BINDING_TARGETS: readonly ["ruby", "rs", "ts", "python"];
3
+ export type BindingTarget = (typeof BINDING_TARGETS)[number];
4
+ export interface BindingRecord {
5
+ capture: string;
6
+ path: string;
7
+ type: string;
8
+ card: string | null;
9
+ preprocess: string | null;
10
+ }
11
+ export interface BindingsArtifactPayload {
12
+ artifact_kind: string;
13
+ target: BindingTarget;
14
+ binding_version: number;
15
+ grammar: string;
16
+ grammar_version: string;
17
+ grammar_source_hash: string;
18
+ shape: string;
19
+ entries: Record<string, {
20
+ bindings: BindingRecord[];
21
+ }>;
22
+ checksum: string;
23
+ }
24
+ /** Structural parse of a declared bindings artifact. Throws with the
25
+ * verification duty named when the payload is not an object, declares a
26
+ * foreign kind or an unknown target, or when the caller pinned a
27
+ * different target. Checksum verification rides the engine (see
28
+ * `PargRuntime.applyBindingsArtifact`). */
29
+ export declare function parseBindingsArtifact(json: string, expectedTarget?: BindingTarget): BindingsArtifactPayload;
@@ -0,0 +1,44 @@
1
+ //! The declared per-target binding artifact (parsanol-ruby#432): from
2
+ //! one compiled grammar the toolchain emits one checksummed bindings
3
+ //! artifact per target, pinned to its grammar by source hash. Declared
4
+ //! and diffable, not baked.
5
+ //!
6
+ //! Boundary: the records carry AST construction only — the
7
+ //! production-to-binding mapping. Semantics live in the model layer
8
+ //! (LML). Full verification (kind, canonical-JSON checksum, target pin,
9
+ //! binding version) and pairing (grammar / version / source hash)
10
+ //! happen in the ENGINE — `PargRuntime.applyBindingsArtifact` on the
11
+ //! paired artifact — so the JSON the engine materializes is the JSON
12
+ //! the checksum pinned; this module adds only the structural parse and
13
+ //! the typed surface.
14
+ export const BINDINGS_ARTIFACT_KIND = "parg-bindings";
15
+ export const BINDING_TARGETS = ["ruby", "rs", "ts", "python"];
16
+ /** Structural parse of a declared bindings artifact. Throws with the
17
+ * verification duty named when the payload is not an object, declares a
18
+ * foreign kind or an unknown target, or when the caller pinned a
19
+ * different target. Checksum verification rides the engine (see
20
+ * `PargRuntime.applyBindingsArtifact`). */
21
+ export function parseBindingsArtifact(json, expectedTarget) {
22
+ let payload;
23
+ try {
24
+ payload = JSON.parse(json);
25
+ }
26
+ catch (error) {
27
+ throw new Error(`bindings artifact is not valid JSON: ${String(error)}`);
28
+ }
29
+ const object = payload;
30
+ if (object["artifact_kind"] !== BINDINGS_ARTIFACT_KIND) {
31
+ throw new Error(`not a ${BINDINGS_ARTIFACT_KIND} artifact (artifact_kind ${JSON.stringify(object["artifact_kind"])})`);
32
+ }
33
+ const target = object["target"];
34
+ if (!BINDING_TARGETS.includes(target)) {
35
+ throw new Error(`unknown binding target ${JSON.stringify(target)}`);
36
+ }
37
+ if (expectedTarget !== undefined && target !== expectedTarget) {
38
+ throw new Error(`bindings artifact targets ${JSON.stringify(target)}, not ${JSON.stringify(expectedTarget)}`);
39
+ }
40
+ if (typeof object["entries"] !== "object" || object["entries"] === null) {
41
+ throw new Error("bindings artifact carries no entries map");
42
+ }
43
+ return payload;
44
+ }
package/dist/runtime.d.ts CHANGED
@@ -71,6 +71,13 @@ export declare class PargRuntime {
71
71
  parseShapeRecovering(input: string): RecoveryEnvelope;
72
72
  /** Apply the entry's bindings to a parsanol-shape tree. */
73
73
  applyBindings(shape: unknown): Record<string, unknown>;
74
+ /** Apply an entry's DECLARED bindings artifact (parsanol-ruby#432) to
75
+ * a parsanol-shape tree. The engine verifies the artifact (kind,
76
+ * canonical-JSON checksum, `ts` target pin, binding version) and
77
+ * pair-checks it against this artifact by grammar source hash before
78
+ * the shared apply core runs — the JSON materialized is the JSON the
79
+ * checksum pinned. */
80
+ applyBindingsArtifact(bindingsJson: string, shape: unknown): Record<string, unknown>;
74
81
  /** Parse and bind in one step. */
75
82
  parseAndBind(input: string): Record<string, unknown> | null;
76
83
  /**
package/dist/runtime.js CHANGED
@@ -137,6 +137,15 @@ export class PargRuntime {
137
137
  applyBindings(shape) {
138
138
  return JSON.parse(this.artifact.applyBindings(this.entry, JSON.stringify(shape)));
139
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
+ }
140
149
  /** Parse and bind in one step. */
141
150
  parseAndBind(input) {
142
151
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parsanol",
3
- "version": "0.10.34",
3
+ "version": "0.10.36",
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",
@@ -1,2 +1,2 @@
1
- a78e4b528e29450232906551bdcdd09950d24fea
1
+ 8e3a886535949e47090620579370862eee6c42e8
2
2
  built with: wasm-pack build --target=nodejs --features wasm (from parsanol-rs/parsanol)
@@ -16,6 +16,38 @@ class PargArtifactJs {
16
16
  const ptr = this.__destroy_into_raw();
17
17
  wasm.__wbg_pargartifactjs_free(ptr, 0);
18
18
  }
19
+ /**
20
+ * Apply an entry's DECLARED bindings artifact (parsanol-ruby#432)
21
+ * to a parsanol-shape tree. The bindings artifact is verified
22
+ * (kind, checksum, `ts` target, binding version) and pair-checked
23
+ * against this parse artifact by grammar source hash before the
24
+ * shared apply core runs.
25
+ * @param {string} bindings_json
26
+ * @param {string} entry
27
+ * @param {string} shape_json
28
+ * @returns {string}
29
+ */
30
+ applyBindingsArtifact(bindings_json, entry, shape_json) {
31
+ let ptr0, len0, ptr1, len1, ptr2, len2;
32
+ try {
33
+ ptr0 = passStringToWasm0(bindings_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
34
+ len0 = WASM_VECTOR_LEN;
35
+ ptr1 = passStringToWasm0(entry, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ len1 = WASM_VECTOR_LEN;
37
+ ptr2 = passStringToWasm0(shape_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
38
+ len2 = WASM_VECTOR_LEN;
39
+ } catch (e) {
40
+ if (ptr2) { wasm.__wbindgen_free(ptr2, len2 * 1, 1); }
41
+ if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
42
+ if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
43
+ throw e;
44
+ }
45
+ const ret = wasm.pargartifactjs_applyBindingsArtifact(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
46
+ if (ret[2]) {
47
+ throw takeFromExternrefTable0(ret[1]);
48
+ }
49
+ return takeFromExternrefTable0(ret[0]);
50
+ }
19
51
  /**
20
52
  * Apply an entry's bindings to a parsanol-shape tree (JSON text).
21
53
  * @param {string} entry
@@ -9,6 +9,14 @@
9
9
  export class PargArtifactJs {
10
10
  free(): void;
11
11
  [Symbol.dispose](): void;
12
+ /**
13
+ * Apply an entry's DECLARED bindings artifact (parsanol-ruby#432)
14
+ * to a parsanol-shape tree. The bindings artifact is verified
15
+ * (kind, checksum, `ts` target, binding version) and pair-checked
16
+ * against this parse artifact by grammar source hash before the
17
+ * shared apply core runs.
18
+ */
19
+ applyBindingsArtifact(bindings_json: string, entry: string, shape_json: string): string;
12
20
  /**
13
21
  * Apply an entry's bindings to a parsanol-shape tree (JSON text).
14
22
  */
@@ -5,6 +5,7 @@ export const __wbg_pargartifactjs_free: (a: number, b: number) => void;
5
5
  export const __wbg_wasmparser_free: (a: number, b: number) => void;
6
6
  export const compileSource: (a: number, b: number) => [number, number, number, number];
7
7
  export const pargartifactjs_applyBindings: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
8
+ export const pargartifactjs_applyBindingsArtifact: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
8
9
  export const pargartifactjs_entryNames: (a: number) => [number, number];
9
10
  export const pargartifactjs_new: (a: number, b: number) => [number, number, number];
10
11
  export const pargartifactjs_parseAndBind: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];