parsanol 0.10.4 → 0.10.5
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 +22 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.js +9 -0
- package/package.json +1 -1
- package/vendor/parsanol-wasm/BUILT_FROM +1 -1
- package/vendor/parsanol-wasm/parsanol.cjs +19 -0
- package/vendor/parsanol-wasm/parsanol.d.ts +6 -0
- package/vendor/parsanol-wasm/parsanol_bg.wasm +0 -0
- package/vendor/parsanol-wasm/parsanol_bg.wasm.d.ts +1 -0
package/README.md
CHANGED
|
@@ -42,6 +42,28 @@ means the source moved since compilation — recompile or fall back.
|
|
|
42
42
|
`parsanol-tree/v2` artifact parses identically on every engine, forever;
|
|
43
43
|
a shape bump means a new engine family.
|
|
44
44
|
|
|
45
|
+
## Recovery (best-effort partial parses)
|
|
46
|
+
|
|
47
|
+
`parseShapeRecovering` never throws: on success it returns
|
|
48
|
+
`{ ok: true, shape }`; on failure it returns the "what did match"
|
|
49
|
+
answer alongside the failure —
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const r = rt.parseShapeRecovering("ab 4");
|
|
53
|
+
// { ok: false,
|
|
54
|
+
// error: { offset: 4, expected: [...] },
|
|
55
|
+
// captures: { text: [{ value: "ab", offset: 0, ... }] },
|
|
56
|
+
// consumed_upto: 4 }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- `captures` carries every capture observed before the failure
|
|
60
|
+
(best-effort: it may include captures from branches that later
|
|
61
|
+
failed — same semantics as the rs recovery journal).
|
|
62
|
+
- `consumed_upto` is the furthest position any successful match ended.
|
|
63
|
+
|
|
64
|
+
The strict `parseShape` contract is unchanged; recovery is the
|
|
65
|
+
editors-and-linters answer.
|
|
66
|
+
|
|
45
67
|
## Vendored engine freshness
|
|
46
68
|
|
|
47
69
|
`vendor/parsanol-wasm/BUILT_FROM` records the parsanol-rs commit the
|
package/dist/runtime.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ export declare class PargRuntime {
|
|
|
48
48
|
static load(grammar: string, entry?: string, dir?: string): PargRuntime;
|
|
49
49
|
/** Parse with the native wasm engine; returns the parsanol-shape tree. */
|
|
50
50
|
parseShape(input: string): unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Best-effort recovery (TODO.sota/1): never throws. Success returns
|
|
53
|
+
* `{ ok: true, shape }`; failure returns
|
|
54
|
+
* `{ ok: false, captures, error, consumed_upto }` — the captures
|
|
55
|
+
* observed before the failure plus the failure wire.
|
|
56
|
+
*/
|
|
57
|
+
parseShapeRecovering(input: string): RecoveryEnvelope;
|
|
51
58
|
/** Apply the entry's bindings to a parsanol-shape tree. */
|
|
52
59
|
applyBindings(shape: unknown): Record<string, unknown>;
|
|
53
60
|
/** Parse and bind in one step. */
|
|
@@ -86,6 +93,21 @@ export type RenderSegment = {
|
|
|
86
93
|
/** F6 v1 generic renderer: field / literal / cond-presence segments. */
|
|
87
94
|
export declare function renderSegments(segments: RenderSegment[] | null, bound: Record<string, unknown>): string;
|
|
88
95
|
/** A schema-materialized identifier: typed fields plus provenance. */
|
|
96
|
+
export interface RecoveryError {
|
|
97
|
+
offset: number;
|
|
98
|
+
message?: string;
|
|
99
|
+
expected?: string[];
|
|
100
|
+
line?: number;
|
|
101
|
+
column?: number;
|
|
102
|
+
}
|
|
103
|
+
/** The parseShapeRecovering envelope (TODO.sota/1). */
|
|
104
|
+
export interface RecoveryEnvelope {
|
|
105
|
+
ok: boolean;
|
|
106
|
+
shape?: unknown;
|
|
107
|
+
captures?: Record<string, unknown[]>;
|
|
108
|
+
error?: RecoveryError;
|
|
109
|
+
consumed_upto?: number;
|
|
110
|
+
}
|
|
89
111
|
export interface Materialized {
|
|
90
112
|
entry: string;
|
|
91
113
|
attributes: Record<string, unknown>;
|
package/dist/runtime.js
CHANGED
|
@@ -107,6 +107,15 @@ export class PargRuntime {
|
|
|
107
107
|
parseShape(input) {
|
|
108
108
|
return JSON.parse(this.artifact.parseShape(this.entry, input));
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Best-effort recovery (TODO.sota/1): never throws. Success returns
|
|
112
|
+
* `{ ok: true, shape }`; failure returns
|
|
113
|
+
* `{ ok: false, captures, error, consumed_upto }` — the captures
|
|
114
|
+
* observed before the failure plus the failure wire.
|
|
115
|
+
*/
|
|
116
|
+
parseShapeRecovering(input) {
|
|
117
|
+
return JSON.parse(this.artifact.parseShapeRecovering(this.entry, input));
|
|
118
|
+
}
|
|
110
119
|
/** Apply the entry's bindings to a parsanol-shape tree. */
|
|
111
120
|
applyBindings(shape) {
|
|
112
121
|
return JSON.parse(this.artifact.applyBindings(this.entry, JSON.stringify(shape)));
|
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
32937dcf6f5d7998a1f543292c88fe86b7a5a812
|
|
2
2
|
built with: wasm-pack build --target=nodejs --features wasm (from parsanol-rs/parsanol)
|
|
@@ -75,6 +75,25 @@ class PargArtifactJs {
|
|
|
75
75
|
}
|
|
76
76
|
return takeFromExternrefTable0(ret[0]);
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Best-effort recovery (TODO.sota/1): success returns
|
|
80
|
+
* `{"ok": true, "shape": ...}`; failure returns
|
|
81
|
+
* `{"ok": false, "captures": ..., "error": ..., "consumed_upto"}`.
|
|
82
|
+
* @param {string} entry
|
|
83
|
+
* @param {string} input
|
|
84
|
+
* @returns {string}
|
|
85
|
+
*/
|
|
86
|
+
parseShapeRecovering(entry, input) {
|
|
87
|
+
const ptr0 = passStringToWasm0(entry, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
88
|
+
const len0 = WASM_VECTOR_LEN;
|
|
89
|
+
const ptr1 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
90
|
+
const len1 = WASM_VECTOR_LEN;
|
|
91
|
+
const ret = wasm.pargartifactjs_parseShapeRecovering(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
92
|
+
if (ret[2]) {
|
|
93
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
94
|
+
}
|
|
95
|
+
return takeFromExternrefTable0(ret[0]);
|
|
96
|
+
}
|
|
78
97
|
/**
|
|
79
98
|
* Parse an entry with the native engine; returns the parsanol-shape
|
|
80
99
|
* tree as JSON text.
|
|
@@ -25,6 +25,12 @@ export class PargArtifactJs {
|
|
|
25
25
|
* Parse and bind in one step.
|
|
26
26
|
*/
|
|
27
27
|
parseAndBind(entry: string, input: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Best-effort recovery (TODO.sota/1): success returns
|
|
30
|
+
* `{"ok": true, "shape": ...}`; failure returns
|
|
31
|
+
* `{"ok": false, "captures": ..., "error": ..., "consumed_upto"}`.
|
|
32
|
+
*/
|
|
33
|
+
parseShapeRecovering(entry: string, input: string): string;
|
|
28
34
|
/**
|
|
29
35
|
* Parse an entry with the native engine; returns the parsanol-shape
|
|
30
36
|
* tree as JSON text.
|
|
Binary file
|
|
@@ -9,6 +9,7 @@ export const pargartifactjs_entryNames: (a: number) => [number, number];
|
|
|
9
9
|
export const pargartifactjs_new: (a: number, b: number) => [number, number, number];
|
|
10
10
|
export const pargartifactjs_parseAndBind: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
11
11
|
export const pargartifactjs_parseShape: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
12
|
+
export const pargartifactjs_parseShapeRecovering: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
12
13
|
export const pargartifactjs_runTests: (a: number) => [number, number, number];
|
|
13
14
|
export const pargartifactjs_schema: (a: number) => [number, number, number];
|
|
14
15
|
export const parsanol_c_last_error: () => number;
|