@sanbus/galley-core 0.0.1

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 (48) hide show
  1. package/README.md +15 -0
  2. package/build/builder.mjs +276 -0
  3. package/build/fixture.mjs +85 -0
  4. package/build/shim.mjs +216 -0
  5. package/dist/artifact.d.ts +38 -0
  6. package/dist/artifact.js +45 -0
  7. package/dist/artifact.js.map +1 -0
  8. package/dist/constants.d.ts +34 -0
  9. package/dist/constants.js +41 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/diagnostic.d.ts +34 -0
  12. package/dist/diagnostic.js +28 -0
  13. package/dist/diagnostic.js.map +1 -0
  14. package/dist/errors.d.ts +22 -0
  15. package/dist/errors.js +38 -0
  16. package/dist/errors.js.map +1 -0
  17. package/dist/index.d.ts +21 -0
  18. package/dist/index.js +16 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/names.d.ts +20 -0
  21. package/dist/names.js +29 -0
  22. package/dist/names.js.map +1 -0
  23. package/dist/node.d.ts +45 -0
  24. package/dist/node.js +137 -0
  25. package/dist/node.js.map +1 -0
  26. package/dist/port.d.ts +193 -0
  27. package/dist/port.js +14 -0
  28. package/dist/port.js.map +1 -0
  29. package/dist/procedures.d.ts +62 -0
  30. package/dist/procedures.js +154 -0
  31. package/dist/procedures.js.map +1 -0
  32. package/dist/session.d.ts +123 -0
  33. package/dist/session.js +599 -0
  34. package/dist/session.js.map +1 -0
  35. package/dist/text.d.ts +7 -0
  36. package/dist/text.js +16 -0
  37. package/dist/text.js.map +1 -0
  38. package/package.json +31 -0
  39. package/src/artifact.ts +62 -0
  40. package/src/constants.ts +47 -0
  41. package/src/diagnostic.ts +48 -0
  42. package/src/errors.ts +49 -0
  43. package/src/index.ts +53 -0
  44. package/src/node.ts +154 -0
  45. package/src/port.ts +213 -0
  46. package/src/procedures.ts +169 -0
  47. package/src/session.ts +747 -0
  48. package/src/text.ts +19 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Constants mirroring `bindings/c/galley.h` status and kind enumerations.
3
+ * These are the single source for JavaScript consumers; they must stay
4
+ * in sync with the C header.
5
+ */
6
+ export declare const INVALID_NODE = 18446744073709551615n;
7
+ export declare const STATUS_OK = 0;
8
+ export declare const STATUS_ERROR_NULL_ARGUMENT = -1;
9
+ export declare const STATUS_ERROR_SYNTAX = -2;
10
+ export declare const STATUS_ERROR_INDENTATION = -3;
11
+ export declare const STATUS_ERROR_STACK_OVERFLOW = -4;
12
+ export declare const STATUS_ERROR_AST_CAPACITY_EXCEEDED = -5;
13
+ export declare const STATUS_ERROR_UNTERMINATED_RAW_STRING = -6;
14
+ export declare const STATUS_ERROR_OUT_OF_MEMORY = -7;
15
+ export declare const STATUS_ERROR_INTERNAL = -8;
16
+ export declare const STATUS_ERROR_NO_DIAGNOSTIC = -9;
17
+ export declare const STATUS_ERROR_INVALID_NODE = -10;
18
+ export declare const STATUS_ERROR_IO = -11;
19
+ export declare const STATUS_ERROR_SEMANTIC = -12;
20
+ export declare const PARSER_TYPE_LL = 0;
21
+ export declare const PARSER_TYPE_LR = 1;
22
+ export declare const RECOVERY_MODE_DISABLED = 0;
23
+ export declare const RECOVERY_MODE_AUTOMATIC = 1;
24
+ export declare const RECOVERY_MODE_EXPLICIT = 2;
25
+ export declare const KIND_NONE = 0;
26
+ export declare const KIND_SYNTAX = 1;
27
+ export declare const KIND_INDENTATION = 2;
28
+ export declare const KIND_SEMANTIC = 3;
29
+ export declare const RECOVERY_TARGET_NONE = 0;
30
+ export declare const RECOVERY_TARGET_LHS_VARIABLE = 1;
31
+ export declare const RECOVERY_TARGET_PRODUCTION = 2;
32
+ export declare const RECOVERY_TARGET_OCCURRENCE = 3;
33
+ export declare const RESUME_BEFORE = 0;
34
+ export declare const RESUME_AFTER = 1;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Constants mirroring `bindings/c/galley.h` status and kind enumerations.
3
+ * These are the single source for JavaScript consumers; they must stay
4
+ * in sync with the C header.
5
+ */
6
+ export const INVALID_NODE = 0xffffffffffffffffn; // 2^64-1
7
+ // Status codes (negative = failure)
8
+ export const STATUS_OK = 0;
9
+ export const STATUS_ERROR_NULL_ARGUMENT = -1;
10
+ export const STATUS_ERROR_SYNTAX = -2;
11
+ export const STATUS_ERROR_INDENTATION = -3;
12
+ export const STATUS_ERROR_STACK_OVERFLOW = -4;
13
+ export const STATUS_ERROR_AST_CAPACITY_EXCEEDED = -5;
14
+ export const STATUS_ERROR_UNTERMINATED_RAW_STRING = -6;
15
+ export const STATUS_ERROR_OUT_OF_MEMORY = -7;
16
+ export const STATUS_ERROR_INTERNAL = -8;
17
+ export const STATUS_ERROR_NO_DIAGNOSTIC = -9;
18
+ export const STATUS_ERROR_INVALID_NODE = -10;
19
+ export const STATUS_ERROR_IO = -11;
20
+ export const STATUS_ERROR_SEMANTIC = -12;
21
+ // Parser families
22
+ export const PARSER_TYPE_LL = 0;
23
+ export const PARSER_TYPE_LR = 1;
24
+ // Recovery modes
25
+ export const RECOVERY_MODE_DISABLED = 0;
26
+ export const RECOVERY_MODE_AUTOMATIC = 1;
27
+ export const RECOVERY_MODE_EXPLICIT = 2;
28
+ // Diagnostic kinds
29
+ export const KIND_NONE = 0;
30
+ export const KIND_SYNTAX = 1;
31
+ export const KIND_INDENTATION = 2;
32
+ export const KIND_SEMANTIC = 3;
33
+ // Recovery targets
34
+ export const RECOVERY_TARGET_NONE = 0;
35
+ export const RECOVERY_TARGET_LHS_VARIABLE = 1;
36
+ export const RECOVERY_TARGET_PRODUCTION = 2;
37
+ export const RECOVERY_TARGET_OCCURRENCE = 3;
38
+ // Resume sides
39
+ export const RESUME_BEFORE = 0;
40
+ export const RESUME_AFTER = 1;
41
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAA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Aa,GAAG,CAAC,CAAC;AAE/B,mBAAmB;AACnB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,eAAe;AACf,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Read-only snapshot of a parse diagnostic.
3
+ * All `Uint8Array` fields are copies that remain valid after the next parse.
4
+ */
5
+ /**
6
+ * Display name for the synthetic control-byte terminals (end of input and
7
+ * the indentation pair), which never occur as user-typable input. Exact
8
+ * full-token match only; anything else returns null and the caller keeps
9
+ * its existing rendering.
10
+ *
11
+ * Mirrors `tokenDisplayName` in `src/runtime/string.zig` until the general
12
+ * per-grammar mechanism arrives; keep the two tables in sync.
13
+ */
14
+ export declare function displayTokenName(token: Uint8Array): string | null;
15
+ export interface Diagnostic {
16
+ kind: number;
17
+ line: number;
18
+ column: number;
19
+ message: string;
20
+ messageAnsi: string;
21
+ unexpectedToken: Uint8Array | null;
22
+ expectedTokens: Uint8Array[];
23
+ context: string[];
24
+ syntaxErrorCount: number;
25
+ semanticErrorCount: number;
26
+ semantic: [string, string] | null;
27
+ indentation: [number, number] | null;
28
+ recoveryKind: number | null;
29
+ recoveryTerminal: Uint8Array | null;
30
+ recoveryResume: number | null;
31
+ recoveryLhsVariable: string | null;
32
+ recoveryProduction: [string, number] | null;
33
+ recoveryOccurrence: [string, number, number, string] | null;
34
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Read-only snapshot of a parse diagnostic.
3
+ * All `Uint8Array` fields are copies that remain valid after the next parse.
4
+ */
5
+ /**
6
+ * Display name for the synthetic control-byte terminals (end of input and
7
+ * the indentation pair), which never occur as user-typable input. Exact
8
+ * full-token match only; anything else returns null and the caller keeps
9
+ * its existing rendering.
10
+ *
11
+ * Mirrors `tokenDisplayName` in `src/runtime/string.zig` until the general
12
+ * per-grammar mechanism arrives; keep the two tables in sync.
13
+ */
14
+ export function displayTokenName(token) {
15
+ if (token.length !== 1)
16
+ return null;
17
+ switch (token[0]) {
18
+ case 0x00:
19
+ return "End of input";
20
+ case 0x01:
21
+ return "Indent";
22
+ case 0x02:
23
+ return "Dedent";
24
+ default:
25
+ return null;
26
+ }
27
+ }
28
+ //# sourceMappingURL=diagnostic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostic.js","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACjB,KAAK,IAAI;YACP,OAAO,cAAc,CAAC;QACxB,KAAK,IAAI;YACP,OAAO,QAAQ,CAAC;QAClB,KAAK,IAAI;YACP,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Diagnostic } from "./diagnostic.ts";
2
+ /**
3
+ * Failure reported by a Galley operation.
4
+ * Mirrors Python's `galley.Error` (code + diagnostic snapshot).
5
+ */
6
+ export declare class GalleyError extends Error {
7
+ readonly code: number;
8
+ readonly diagnostic: Diagnostic | null;
9
+ constructor(message: string, code: number, diagnostic?: Diagnostic | null);
10
+ }
11
+ /**
12
+ * The parser artifact a binding was told to load is not where it was told.
13
+ * Thrown by every adapter's artifact resolution instead of searching
14
+ * elsewhere. The universal loader catches exactly this class to try the
15
+ * next engine; anything else propagates loudly.
16
+ */
17
+ export declare class MissingArtifactError extends Error {
18
+ readonly code = "galley:missing-artifact";
19
+ constructor(detail: string, buildHint: string);
20
+ /** True for missing-artifact failures even across duplicated installs. */
21
+ static is(error: unknown): error is MissingArtifactError;
22
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Failure reported by a Galley operation.
3
+ * Mirrors Python's `galley.Error` (code + diagnostic snapshot).
4
+ */
5
+ export class GalleyError extends Error {
6
+ code;
7
+ diagnostic;
8
+ constructor(message, code, diagnostic = null) {
9
+ super(message);
10
+ this.name = "GalleyError";
11
+ this.code = code;
12
+ this.diagnostic = diagnostic;
13
+ }
14
+ }
15
+ const MISSING_ARTIFACT_CODE = "galley:missing-artifact";
16
+ /**
17
+ * The parser artifact a binding was told to load is not where it was told.
18
+ * Thrown by every adapter's artifact resolution instead of searching
19
+ * elsewhere. The universal loader catches exactly this class to try the
20
+ * next engine; anything else propagates loudly.
21
+ */
22
+ export class MissingArtifactError extends Error {
23
+ code = MISSING_ARTIFACT_CODE;
24
+ constructor(detail, buildHint) {
25
+ super(`galley: parser artifact not found: ${detail}.\n${buildHint}`);
26
+ this.name = "MissingArtifactError";
27
+ }
28
+ /** True for missing-artifact failures even across duplicated installs. */
29
+ static is(error) {
30
+ if (error instanceof MissingArtifactError)
31
+ return true;
32
+ return (typeof error === "object" &&
33
+ error !== null &&
34
+ error.name === "MissingArtifactError" &&
35
+ error.code === MISSING_ARTIFACT_CODE);
36
+ }
37
+ }
38
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACb,UAAU,CAAoB;IAEvC,YACE,OAAe,EACf,IAAY,EACZ,UAAU,GAAsB,IAAI;QAEpC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,IAAI,GAAG,qBAAqB,CAAC;IAEtC,YAAY,MAAc,EAAE,SAAiB;QAC3C,KAAK,CAAC,sCAAsC,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;IAED,0EAA0E;IAC1E,MAAM,CAAC,EAAE,CAAC,KAAc;QACtB,IAAI,KAAK,YAAY,oBAAoB;YAAE,OAAO,IAAI,CAAC;QACvD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACb,KAA4B,CAAC,IAAI,KAAK,sBAAsB;YAC5D,KAA4B,CAAC,IAAI,KAAK,qBAAqB,CAC7D,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Galley JavaScript core — runtime-neutral public surface.
3
+ *
4
+ * Each adapter package (`@sanbus/galley-node`, `@sanbus/galley-bun`, `@sanbus/galley-deno`)
5
+ * binds these classes to its {@link FfiPort} and re-exports them.
6
+ */
7
+ import { Session, Walker } from "./session.ts";
8
+ import type { SessionOptions, WalkStep } from "./session.ts";
9
+ import { Node } from "./node.ts";
10
+ import { GalleyError, MissingArtifactError } from "./errors.ts";
11
+ import { resolveArtifact, artifactFileName, wasmArtifactFileName } from "./artifact.ts";
12
+ import type { ArtifactHost } from "./artifact.ts";
13
+ import type { Diagnostic } from "./diagnostic.ts";
14
+ import { displayTokenName } from "./diagnostic.ts";
15
+ import type { FfiPort, Handle, SessionCOptions, TreeSnapshot, WalkedStep, DispatchHandler } from "./port.ts";
16
+ import { installProcedure, installProcedures, clearProcedures, listProcedures, ProcedureArguments, dispatchProcedure, setParsingSession, getParsingSession } from "./procedures.ts";
17
+ import type { HookFn } from "./procedures.ts";
18
+ import { encodeUtf8, decodeUtf8, byteLengthUtf8 } from "./text.ts";
19
+ export { Session, Walker, Node, GalleyError, MissingArtifactError, resolveArtifact, artifactFileName, wasmArtifactFileName, displayTokenName, ProcedureArguments, installProcedure, installProcedures, clearProcedures, listProcedures, dispatchProcedure, setParsingSession, getParsingSession, encodeUtf8, decodeUtf8, byteLengthUtf8, };
20
+ export type { Diagnostic, WalkStep, SessionOptions, FfiPort, Handle, SessionCOptions, TreeSnapshot, WalkedStep, DispatchHandler, HookFn, ArtifactHost };
21
+ export * from "./constants.ts";
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Galley JavaScript core — runtime-neutral public surface.
3
+ *
4
+ * Each adapter package (`@sanbus/galley-node`, `@sanbus/galley-bun`, `@sanbus/galley-deno`)
5
+ * binds these classes to its {@link FfiPort} and re-exports them.
6
+ */
7
+ import { Session, Walker } from "./session.js";
8
+ import { Node } from "./node.js";
9
+ import { GalleyError, MissingArtifactError } from "./errors.js";
10
+ import { resolveArtifact, artifactFileName, wasmArtifactFileName } from "./artifact.js";
11
+ import { displayTokenName } from "./diagnostic.js";
12
+ import { installProcedure, installProcedures, clearProcedures, listProcedures, ProcedureArguments, dispatchProcedure, setParsingSession, getParsingSession, } from "./procedures.js";
13
+ import { encodeUtf8, decodeUtf8, byteLengthUtf8 } from "./text.js";
14
+ export { Session, Walker, Node, GalleyError, MissingArtifactError, resolveArtifact, artifactFileName, wasmArtifactFileName, displayTokenName, ProcedureArguments, installProcedure, installProcedures, clearProcedures, listProcedures, dispatchProcedure, setParsingSession, getParsingSession, encodeUtf8, decodeUtf8, byteLengthUtf8, };
15
+ export * from "./constants.js";
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEnE,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,cAAc,GACf,CAAC;AAEF,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Shared library filename mapping for every JavaScript adapter.
3
+ * One library name per platform: `lib<base>.dylib` on macOS, `<base>.dll`
4
+ * on Windows (no `lib` prefix), `lib<base>.so` elsewhere. The platform
5
+ * string comes from the host (`process.platform` under Node/Bun, where
6
+ * Windows reports `win32`; `Deno.build.os`, where it reports `windows`);
7
+ * both spellings map to the Windows name here so the adapters cannot
8
+ * diverge.
9
+ *
10
+ * This file imports nothing, on purpose: strict-mode Deno consumers
11
+ * (notably `deno/build.ts`) import it directly, and any cross-file import
12
+ * with a `.js` suffix breaks Deno's strict resolution. Runtime code takes
13
+ * these through `artifact.ts`; nothing takes them the other way.
14
+ */
15
+ export declare function artifactFileName(base: string, platform: string): string;
16
+ /**
17
+ * Shared wasm artifact filename. WebAssembly modules are platform-neutral:
18
+ * always `lib<base>.wasm`.
19
+ */
20
+ export declare function wasmArtifactFileName(base: string): string;
package/dist/names.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Shared library filename mapping for every JavaScript adapter.
3
+ * One library name per platform: `lib<base>.dylib` on macOS, `<base>.dll`
4
+ * on Windows (no `lib` prefix), `lib<base>.so` elsewhere. The platform
5
+ * string comes from the host (`process.platform` under Node/Bun, where
6
+ * Windows reports `win32`; `Deno.build.os`, where it reports `windows`);
7
+ * both spellings map to the Windows name here so the adapters cannot
8
+ * diverge.
9
+ *
10
+ * This file imports nothing, on purpose: strict-mode Deno consumers
11
+ * (notably `deno/build.ts`) import it directly, and any cross-file import
12
+ * with a `.js` suffix breaks Deno's strict resolution. Runtime code takes
13
+ * these through `artifact.ts`; nothing takes them the other way.
14
+ */
15
+ export function artifactFileName(base, platform) {
16
+ if (platform === "darwin")
17
+ return `lib${base}.dylib`;
18
+ if (platform === "win32" || platform === "windows")
19
+ return `${base}.dll`;
20
+ return `lib${base}.so`;
21
+ }
22
+ /**
23
+ * Shared wasm artifact filename. WebAssembly modules are platform-neutral:
24
+ * always `lib<base>.wasm`.
25
+ */
26
+ export function wasmArtifactFileName(base) {
27
+ return `lib${base}.wasm`;
28
+ }
29
+ //# sourceMappingURL=names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.js","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,QAAgB;IAC7D,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,MAAM,IAAI,QAAQ,CAAC;IACrD,IAAI,QAAQ,KAAK,OAAO,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,GAAG,IAAI,MAAM,CAAC;IACzE,OAAO,MAAM,IAAI,KAAK,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,MAAM,IAAI,OAAO,CAAC;AAC3B,CAAC"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { Session } from "./session.ts";
2
+ /**
3
+ * Session-bound handle for a node in the non-relocating AST storage.
4
+ * Mirrors Python's `galley.Node`: keeps a strong reference to its Session
5
+ * and raises after the session is closed.
6
+ */
7
+ export declare class Node {
8
+ #private;
9
+ constructor(session: Session, address: bigint | number);
10
+ /** Raw address (stable index in the session's node storage). */
11
+ get address(): bigint;
12
+ /** Owning session. */
13
+ get session(): Session;
14
+ private ensureAlive;
15
+ /** Tuple of direct children, from first to last (empty when leaf). */
16
+ children(): Node[];
17
+ /** Text bytes of this node, or null for invalid node. */
18
+ text(): Uint8Array | null;
19
+ /** Symbol name bytes as string, or null for invalid node. Terminal-only nodes → "". */
20
+ symbolName(): string | null;
21
+ /** Raw symbol name bytes (Uint8Array) or null. */
22
+ symbolNameBytes(): Uint8Array | null;
23
+ /** (start, length) byte span, or null. */
24
+ span(): [bigint, bigint] | null;
25
+ /** 1-based (line, column) of first byte, or null. */
26
+ lineColumn(): [number, number] | null;
27
+ /** Parent node, or null for root. */
28
+ parent(): Node | null;
29
+ nextSibling(): Node | null;
30
+ priorSibling(): Node | null;
31
+ firstChild(): Node | null;
32
+ lastChild(): Node | null;
33
+ cleanChildren(): Node | null;
34
+ appendChildren(chain: Node | bigint): void;
35
+ /** Number of direct children. */
36
+ get length(): number;
37
+ /** Child at index (negative indices supported). */
38
+ at(index: number): Node;
39
+ [Symbol.iterator](): Iterator<Node>;
40
+ /** Raw address for `Number(node)` / `BigInt(node)`. */
41
+ valueOf(): bigint;
42
+ toString(): string;
43
+ equals(other: unknown): boolean;
44
+ [Symbol.toPrimitive](hint: string): bigint | string | number;
45
+ }
package/dist/node.js ADDED
@@ -0,0 +1,137 @@
1
+ import { decodeUtf8 } from "./text.js";
2
+ /**
3
+ * Session-bound handle for a node in the non-relocating AST storage.
4
+ * Mirrors Python's `galley.Node`: keeps a strong reference to its Session
5
+ * and raises after the session is closed.
6
+ */
7
+ export class Node {
8
+ #session;
9
+ #address;
10
+ constructor(session, address) {
11
+ this.#session = session;
12
+ this.#address = typeof address === "bigint" ? address : BigInt(address);
13
+ }
14
+ /** Raw address (stable index in the session's node storage). */
15
+ get address() {
16
+ return this.#address;
17
+ }
18
+ /** Owning session. */
19
+ get session() {
20
+ return this.#session;
21
+ }
22
+ ensureAlive() {
23
+ if (this.#session.isClosed) {
24
+ throw new Error("node's session is closed");
25
+ }
26
+ }
27
+ /** Tuple of direct children, from first to last (empty when leaf). */
28
+ children() {
29
+ this.ensureAlive();
30
+ return this.#session.children(this);
31
+ }
32
+ /** Text bytes of this node, or null for invalid node. */
33
+ text() {
34
+ this.ensureAlive();
35
+ return this.#session.text(this);
36
+ }
37
+ /** Symbol name bytes as string, or null for invalid node. Terminal-only nodes → "". */
38
+ symbolName() {
39
+ this.ensureAlive();
40
+ const bytes = this.#session.symbolNameBytes(this);
41
+ if (bytes === null)
42
+ return null;
43
+ return decodeUtf8(bytes);
44
+ }
45
+ /** Raw symbol name bytes (Uint8Array) or null. */
46
+ symbolNameBytes() {
47
+ this.ensureAlive();
48
+ return this.#session.symbolNameBytes(this);
49
+ }
50
+ /** (start, length) byte span, or null. */
51
+ span() {
52
+ this.ensureAlive();
53
+ return this.#session.span(this);
54
+ }
55
+ /** 1-based (line, column) of first byte, or null. */
56
+ lineColumn() {
57
+ this.ensureAlive();
58
+ return this.#session.lineColumn(this);
59
+ }
60
+ /** Parent node, or null for root. */
61
+ parent() {
62
+ this.ensureAlive();
63
+ return this.#session.parent(this);
64
+ }
65
+ nextSibling() {
66
+ this.ensureAlive();
67
+ return this.#session.nextSibling(this);
68
+ }
69
+ priorSibling() {
70
+ this.ensureAlive();
71
+ return this.#session.priorSibling(this);
72
+ }
73
+ firstChild() {
74
+ this.ensureAlive();
75
+ return this.#session.firstChild(this);
76
+ }
77
+ lastChild() {
78
+ this.ensureAlive();
79
+ return this.#session.lastChild(this);
80
+ }
81
+ cleanChildren() {
82
+ this.ensureAlive();
83
+ return this.#session.cleanChildren(this);
84
+ }
85
+ appendChildren(chain) {
86
+ this.ensureAlive();
87
+ this.#session.appendChildren(this, chain);
88
+ }
89
+ /** Number of direct children. */
90
+ get length() {
91
+ this.ensureAlive();
92
+ return this.#session.childCount(this);
93
+ }
94
+ /** Child at index (negative indices supported). */
95
+ at(index) {
96
+ this.ensureAlive();
97
+ const count = this.length;
98
+ let i = index;
99
+ if (i < 0)
100
+ i += count;
101
+ if (i < 0 || i >= count)
102
+ throw new RangeError(`node index ${index} out of range (0..${count - 1})`);
103
+ const arr = this.children();
104
+ return arr[i];
105
+ }
106
+ *[Symbol.iterator]() {
107
+ this.ensureAlive();
108
+ for (const child of this.children())
109
+ yield child;
110
+ }
111
+ /** Raw address for `Number(node)` / `BigInt(node)`. */
112
+ valueOf() {
113
+ return this.#address;
114
+ }
115
+ toString() {
116
+ return `Node(${this.#address.toString()})`;
117
+ }
118
+ equals(other) {
119
+ if (other instanceof Node) {
120
+ return this.#address === other.#address && this.#session === other.#session;
121
+ }
122
+ if (typeof other === "bigint")
123
+ return this.#address === other;
124
+ if (typeof other === "number")
125
+ return this.#address === BigInt(other);
126
+ return false;
127
+ }
128
+ // allow `Number(node)` and `+node`
129
+ [Symbol.toPrimitive](hint) {
130
+ if (hint === "number")
131
+ return Number(this.#address);
132
+ if (hint === "string")
133
+ return this.toString();
134
+ return this.#address;
135
+ }
136
+ }
137
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;GAIG;AACH,MAAM,OAAO,IAAI;IACN,QAAQ,CAAU;IAClB,QAAQ,CAAS;IAE1B,YAAY,O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