sh-ast 0.3.1 → 0.4.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.
Files changed (84) hide show
  1. package/README.md +116 -144
  2. package/dist/analyze/ansi-c-escapes.d.ts +1 -1
  3. package/dist/analyze/ansi-c-escapes.js +1 -1
  4. package/dist/analyze/enumerate-commands.d.ts +11 -16
  5. package/dist/analyze/enumerate-commands.d.ts.map +1 -1
  6. package/dist/analyze/enumerate-commands.js +82 -92
  7. package/dist/analyze/enumerate-commands.js.map +1 -1
  8. package/dist/analyze/index.d.ts +3 -2
  9. package/dist/analyze/index.d.ts.map +1 -1
  10. package/dist/analyze/index.js +1 -1
  11. package/dist/analyze/node-helpers.d.ts +10 -21
  12. package/dist/analyze/node-helpers.d.ts.map +1 -1
  13. package/dist/analyze/node-helpers.js +16 -27
  14. package/dist/analyze/node-helpers.js.map +1 -1
  15. package/dist/analyze/resolve-argv0.d.ts +6 -6
  16. package/dist/analyze/resolve-argv0.js +6 -6
  17. package/dist/analyze/resolve-word.d.ts +7 -10
  18. package/dist/analyze/resolve-word.d.ts.map +1 -1
  19. package/dist/analyze/resolve-word.js +39 -22
  20. package/dist/analyze/resolve-word.js.map +1 -1
  21. package/dist/analyze.d.ts +3780 -397
  22. package/dist/errors.d.ts +6 -79
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/errors.js +5 -64
  25. package/dist/errors.js.map +1 -1
  26. package/dist/index.d.ts +16 -14
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +23 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/sh-ast.d.ts +3503 -1027
  31. package/dist/syntax-errors.d.ts +56 -0
  32. package/dist/syntax-errors.d.ts.map +1 -0
  33. package/dist/syntax-errors.js +80 -0
  34. package/dist/syntax-errors.js.map +1 -0
  35. package/dist/syntax-snapshot.d.ts +47 -0
  36. package/dist/syntax-snapshot.d.ts.map +1 -0
  37. package/dist/syntax-snapshot.js +121 -0
  38. package/dist/syntax-snapshot.js.map +1 -0
  39. package/dist/syntax-wire.d.ts +31 -0
  40. package/dist/syntax-wire.d.ts.map +1 -0
  41. package/dist/syntax-wire.js +202 -0
  42. package/dist/syntax-wire.js.map +1 -0
  43. package/dist/syntax.d.ts +65 -0
  44. package/dist/syntax.d.ts.map +1 -0
  45. package/dist/syntax.js +152 -0
  46. package/dist/syntax.js.map +1 -0
  47. package/dist/wasm-instance.d.ts +5 -8
  48. package/dist/wasm-instance.d.ts.map +1 -1
  49. package/dist/wasm-instance.js +44 -47
  50. package/dist/wasm-instance.js.map +1 -1
  51. package/generated/syntax-constants.d.ts +1652 -0
  52. package/generated/syntax-constants.js +1384 -0
  53. package/generated/syntax-schema.d.ts +60 -0
  54. package/generated/syntax-schema.js +1740 -0
  55. package/generated/syntax-types.d.ts +1977 -0
  56. package/package.json +2 -2
  57. package/shim/sh-ast.wasm +0 -0
  58. package/dist/normalize.d.ts +0 -52
  59. package/dist/normalize.d.ts.map +0 -1
  60. package/dist/normalize.js +0 -260
  61. package/dist/normalize.js.map +0 -1
  62. package/dist/parse.d.ts +0 -50
  63. package/dist/parse.d.ts.map +0 -1
  64. package/dist/parse.js +0 -125
  65. package/dist/parse.js.map +0 -1
  66. package/dist/types.d.ts +0 -74
  67. package/dist/types.d.ts.map +0 -1
  68. package/dist/types.js +0 -2
  69. package/dist/types.js.map +0 -1
  70. package/dist/visitor-keys.d.ts +0 -21
  71. package/dist/visitor-keys.d.ts.map +0 -1
  72. package/dist/visitor-keys.js +0 -23
  73. package/dist/visitor-keys.js.map +0 -1
  74. package/dist/walk.d.ts +0 -18
  75. package/dist/walk.d.ts.map +0 -1
  76. package/dist/walk.js +0 -40
  77. package/dist/walk.js.map +0 -1
  78. package/generated/child-type-schema.d.ts +0 -14
  79. package/generated/child-type-schema.js +0 -188
  80. package/generated/node-types.d.ts +0 -1002
  81. package/generated/position-fields.d.ts +0 -21
  82. package/generated/position-fields.js +0 -50
  83. package/generated/visitor-keys.d.ts +0 -11
  84. package/generated/visitor-keys.js +0 -50
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Error adaptation for the upstream syntax interface. Exceptions retain the Go
3
+ * error's structured information and partial result; JavaScript's display message
4
+ * is never the only copy of a byte-bearing upstream value.
5
+ */
6
+ import type { File, GoString, SyntaxPos } from '../generated/syntax-types.js';
7
+ import { ShAstError } from './errors.js';
8
+ /**
9
+ * A source grammar error reported by mvdan/sh, with the partial parsed file.
10
+ * @public
11
+ */
12
+ export declare class ParseError extends ShAstError {
13
+ readonly Message: GoString;
14
+ readonly Filename: GoString;
15
+ readonly Pos: SyntaxPos;
16
+ readonly Text: GoString;
17
+ readonly Incomplete: boolean;
18
+ readonly File: File | null;
19
+ /** Identifies a source grammar failure independently of its display text. */
20
+ readonly code = "SH_AST_SYNTAX_PARSE";
21
+ /**
22
+ * Keeps the original Go fields. Message is the formatted upstream error;
23
+ * Text is its unformatted diagnostic, and File is the result returned with it.
24
+ */
25
+ constructor(Message: GoString, Filename: GoString, Pos: SyntaxPos, Text: GoString, Incomplete: boolean, File: File | null);
26
+ }
27
+ /**
28
+ * A syntax feature rejected for the selected upstream language variant.
29
+ * @public
30
+ */
31
+ export declare class LangError extends ShAstError {
32
+ readonly Message: GoString;
33
+ readonly Filename: GoString;
34
+ readonly Pos: SyntaxPos;
35
+ readonly Feature: GoString;
36
+ readonly Langs: readonly number[];
37
+ readonly LangUsed: number;
38
+ readonly File: File | null;
39
+ /** Identifies a dialect-specific syntax failure. */
40
+ readonly code = "SH_AST_SYNTAX_LANG";
41
+ /** Preserves the feature, permitted variants, actual variant and partial tree. */
42
+ constructor(Message: GoString, Filename: GoString, Pos: SyntaxPos, Feature: GoString, Langs: readonly number[], LangUsed: number, File: File | null);
43
+ }
44
+ /**
45
+ * An argument cannot be represented by the binding or violates an upstream
46
+ * operation's input constraint. It is distinct from malformed shell source.
47
+ * @public
48
+ */
49
+ export declare class InputError extends ShAstError {
50
+ readonly Message: GoString;
51
+ /** Identifies caller input that cannot be passed faithfully to the operation. */
52
+ readonly code = "SH_AST_SYNTAX_INPUT";
53
+ /** Retains exact upstream message bytes even when Error.message needs text. */
54
+ constructor(Message: GoString);
55
+ }
56
+ //# sourceMappingURL=syntax-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-errors.d.ts","sourceRoot":"","sources":["../src/syntax-errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,qBAAa,UAAW,SAAQ,UAAU;IAStC,QAAQ,CAAC,OAAO,EAAE,QAAQ;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ;IAC3B,QAAQ,CAAC,GAAG,EAAE,SAAS;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ;IACvB,QAAQ,CAAC,UAAU,EAAE,OAAO;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAb5B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,yBAAyB;IAEtC;;;OAGG;gBAEQ,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,OAAO,EACnB,IAAI,EAAE,IAAI,GAAG,IAAI;CAK7B;AAED;;;GAGG;AACH,qBAAa,SAAU,SAAQ,UAAU;IAMrC,QAAQ,CAAC,OAAO,EAAE,QAAQ;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ;IAC3B,QAAQ,CAAC,GAAG,EAAE,SAAS;IACvB,QAAQ,CAAC,OAAO,EAAE,QAAQ;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAX5B,oDAAoD;IACpD,QAAQ,CAAC,IAAI,wBAAwB;IAErC,kFAAkF;gBAEvE,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,IAAI,GAAG,IAAI;CAK7B;AAED;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,UAAU;IAK5B,QAAQ,CAAC,OAAO,EAAE,QAAQ;IAJtC,iFAAiF;IACjF,QAAQ,CAAC,IAAI,yBAAyB;IAEtC,+EAA+E;gBAC1D,OAAO,EAAE,QAAQ;CAIvC"}
@@ -0,0 +1,80 @@
1
+ import { ShAstError } from './errors.js';
2
+ /**
3
+ * A source grammar error reported by mvdan/sh, with the partial parsed file.
4
+ * @public
5
+ */
6
+ export class ParseError extends ShAstError {
7
+ Message;
8
+ Filename;
9
+ Pos;
10
+ Text;
11
+ Incomplete;
12
+ File;
13
+ /** Identifies a source grammar failure independently of its display text. */
14
+ code = 'SH_AST_SYNTAX_PARSE';
15
+ /**
16
+ * Keeps the original Go fields. Message is the formatted upstream error;
17
+ * Text is its unformatted diagnostic, and File is the result returned with it.
18
+ */
19
+ constructor(Message, Filename, Pos, Text, Incomplete, File) {
20
+ super(displayMessage(Message));
21
+ this.Message = Message;
22
+ this.Filename = Filename;
23
+ this.Pos = Pos;
24
+ this.Text = Text;
25
+ this.Incomplete = Incomplete;
26
+ this.File = File;
27
+ this.name = 'ParseError';
28
+ }
29
+ }
30
+ /**
31
+ * A syntax feature rejected for the selected upstream language variant.
32
+ * @public
33
+ */
34
+ export class LangError extends ShAstError {
35
+ Message;
36
+ Filename;
37
+ Pos;
38
+ Feature;
39
+ Langs;
40
+ LangUsed;
41
+ File;
42
+ /** Identifies a dialect-specific syntax failure. */
43
+ code = 'SH_AST_SYNTAX_LANG';
44
+ /** Preserves the feature, permitted variants, actual variant and partial tree. */
45
+ constructor(Message, Filename, Pos, Feature, Langs, LangUsed, File) {
46
+ super(displayMessage(Message));
47
+ this.Message = Message;
48
+ this.Filename = Filename;
49
+ this.Pos = Pos;
50
+ this.Feature = Feature;
51
+ this.Langs = Langs;
52
+ this.LangUsed = LangUsed;
53
+ this.File = File;
54
+ this.name = 'LangError';
55
+ }
56
+ }
57
+ /**
58
+ * An argument cannot be represented by the binding or violates an upstream
59
+ * operation's input constraint. It is distinct from malformed shell source.
60
+ * @public
61
+ */
62
+ export class InputError extends ShAstError {
63
+ Message;
64
+ /** Identifies caller input that cannot be passed faithfully to the operation. */
65
+ code = 'SH_AST_SYNTAX_INPUT';
66
+ /** Retains exact upstream message bytes even when Error.message needs text. */
67
+ constructor(Message) {
68
+ super(displayMessage(Message));
69
+ this.Message = Message;
70
+ this.name = 'InputError';
71
+ }
72
+ }
73
+ /**
74
+ * Error.message is a human-readable rendering only. The public Message property
75
+ * retains original bytes when the Go value is not valid UTF-8.
76
+ */
77
+ function displayMessage(value) {
78
+ return typeof value === 'string' ? value : new TextDecoder().decode(value);
79
+ }
80
+ //# sourceMappingURL=syntax-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-errors.js","sourceRoot":"","sources":["../src/syntax-errors.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAS7B;IACA;IACA;IACA;IACA;IACA;IAbX,6EAA6E;IACpE,IAAI,GAAG,qBAAqB,CAAC;IAEtC;;;OAGG;IACH,YACW,OAAiB,EACjB,QAAkB,EAClB,GAAc,EACd,IAAc,EACd,UAAmB,EACnB,IAAiB;QAE1B,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAPtB,YAAO,GAAP,OAAO,CAAU;QACjB,aAAQ,GAAR,QAAQ,CAAU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CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { File, Node, SyntaxPos } from '../generated/syntax-types.js';
2
+ /**
3
+ * A node's upstream bounds as observed during parsing. These values refer to the
4
+ * original source, even when the corresponding syntax record is later edited.
5
+ * @public
6
+ */
7
+ export interface NodePositions {
8
+ /** Starting byte position observed for the original parsed node. */
9
+ readonly Pos: Readonly<SyntaxPos>;
10
+ /** Exclusive ending byte position observed for the original parsed node. */
11
+ readonly End: Readonly<SyntaxPos>;
12
+ }
13
+ /**
14
+ * Identity-based lookup of the original parse's bounds. A new or copied node has
15
+ * no observation. The index never calls WASM or recalculates edited node bounds.
16
+ * @public
17
+ */
18
+ export interface PositionSnapshot {
19
+ /**
20
+ * Returns the captured pair for a node from this parse, or undefined for a
21
+ * foreign node. If either upstream observation failed, throws the captured
22
+ * InputError without changing the successfully parsed File. Use nodePos or
23
+ * nodeEnd to request a live, independent bound from current edited fields.
24
+ */
25
+ get(node: Node): NodePositions | undefined;
26
+ }
27
+ /**
28
+ * Mutable upstream syntax together with a separate source-bound position view.
29
+ * Editing File never updates Positions; source consumers can retain original
30
+ * spans while transformations query live nodePos/nodeEnd as needed.
31
+ * @public
32
+ */
33
+ export interface ParsedFile {
34
+ /** The complete mutable upstream File; no bounds or consumer fields are added. */
35
+ readonly File: File;
36
+ /** Immutable original observations, keyed by this File's node identities. */
37
+ readonly Positions: PositionSnapshot;
38
+ }
39
+ /**
40
+ * Validates complete sidecar coverage once, then stores immutable observations in
41
+ * a weak identity map. Missing or duplicate metadata is a transport defect; no
42
+ * per-node live-position fallback may disguise it or multiply WASM transfers.
43
+ * The File must already have passed the full syntax boundary validator.
44
+ * @internal
45
+ */
46
+ export declare function createPositionSnapshot(file: File, raw: unknown): PositionSnapshot;
47
+ //# sourceMappingURL=syntax-snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-snapshot.d.ts","sourceRoot":"","sources":["../src/syntax-snapshot.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAY,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAKpF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClC,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;CACtC;AAgED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAmDjF"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Correlates parse-time upstream position observations with the decoded syntax
3
+ * records. Snapshots belong to one parse and never track later edits; live
4
+ * nodePos/nodeEnd remain a separate responsibility. No traversal order or
5
+ * visitor-control protocol is exposed by this lookup-only view.
6
+ */
7
+ import { SYNTAX_INTERFACES, SYNTAX_SCHEMA } from '../generated/syntax-schema.js';
8
+ import { ShInternalError } from './errors.js';
9
+ import { InputError } from './syntax-errors.js';
10
+ import { isGoString, isRecord, isSyntaxPos } from './syntax-wire.js';
11
+ /**
12
+ * Checks only node identity within an already fully validated File. Revalidating
13
+ * each subtree here would reintroduce work proportional to all descendant sizes.
14
+ */
15
+ function isNodeIdentity(value) {
16
+ return ((typeof value.Type === 'string' && SYNTAX_INTERFACES.Node.includes(value.Type)) ||
17
+ (value.Type === 'TypedNil' &&
18
+ typeof value.Kind === 'string' &&
19
+ SYNTAX_INTERFACES.Node.includes(value.Kind)));
20
+ }
21
+ /**
22
+ * Indexes child-bearing fields once, including paths through auxiliary records.
23
+ * Metadata order is irrelevant: paths correlate observations without inventing a
24
+ * Walk order or equating auxiliary records with syntax.Node values.
25
+ */
26
+ function nodesByPath(file) {
27
+ const nodes = new Map();
28
+ const visit = (value, path) => {
29
+ if (!isRecord(value) || typeof value.Type !== 'string')
30
+ return;
31
+ if (isNodeIdentity(value))
32
+ nodes.set(JSON.stringify(path), value);
33
+ if (!Object.hasOwn(SYNTAX_SCHEMA, value.Type))
34
+ return;
35
+ for (const [name, field] of Object.entries(SYNTAX_SCHEMA[value.Type].fields)) {
36
+ if (field.kind !== 'struct' && field.kind !== 'interface')
37
+ continue;
38
+ const child = value[name];
39
+ if (Array.isArray(child)) {
40
+ child.forEach((item, index) => {
41
+ visit(item, [...path, name, index]);
42
+ });
43
+ }
44
+ else {
45
+ visit(child, [...path, name]);
46
+ }
47
+ }
48
+ };
49
+ visit(file, []);
50
+ return nodes;
51
+ }
52
+ /** Accepts the exact field/index domain used by the upstream observation sidecar. */
53
+ function isPath(value) {
54
+ return (Array.isArray(value) &&
55
+ value.every((component) => typeof component === 'string' ||
56
+ (typeof component === 'number' && Number.isSafeInteger(component) && component >= 0)));
57
+ }
58
+ /** An upstream method produced exactly one position or one preserved failure. */
59
+ function isObservation(position, error) {
60
+ return (isSyntaxPos(position) && error === null) || (position === null && isGoString(error));
61
+ }
62
+ /**
63
+ * Validates complete sidecar coverage once, then stores immutable observations in
64
+ * a weak identity map. Missing or duplicate metadata is a transport defect; no
65
+ * per-node live-position fallback may disguise it or multiply WASM transfers.
66
+ * The File must already have passed the full syntax boundary validator.
67
+ * @internal
68
+ */
69
+ export function createPositionSnapshot(file, raw) {
70
+ const nodes = nodesByPath(file);
71
+ if (!Array.isArray(raw) || raw.length !== nodes.size)
72
+ throw new ShInternalError('The syntax snapshot does not cover every parsed node');
73
+ const observations = new WeakMap();
74
+ const remaining = new Map(nodes);
75
+ for (const entry of raw) {
76
+ if (!isRecord(entry) ||
77
+ Object.keys(entry).length !== 5 ||
78
+ !isPath(entry.Path) ||
79
+ !isObservation(entry.Pos, entry.PosError) ||
80
+ !isObservation(entry.End, entry.EndError)) {
81
+ throw new ShInternalError('The syntax snapshot contains an invalid position observation');
82
+ }
83
+ const path = JSON.stringify(entry.Path);
84
+ const node = remaining.get(path);
85
+ if (node === undefined)
86
+ throw new ShInternalError('The syntax snapshot contains an unknown or duplicate node path');
87
+ remaining.delete(path);
88
+ if (isGoString(entry.PosError)) {
89
+ observations.set(node, { error: entry.PosError });
90
+ }
91
+ else if (isGoString(entry.EndError)) {
92
+ observations.set(node, { error: entry.EndError });
93
+ }
94
+ else if (isSyntaxPos(entry.Pos) && isSyntaxPos(entry.End)) {
95
+ observations.set(node, {
96
+ positions: Object.freeze({
97
+ Pos: Object.freeze({ ...entry.Pos }),
98
+ End: Object.freeze({ ...entry.End }),
99
+ }),
100
+ });
101
+ }
102
+ else {
103
+ throw new ShInternalError('The syntax snapshot dropped an upstream method outcome');
104
+ }
105
+ }
106
+ if (remaining.size !== 0)
107
+ throw new ShInternalError('The syntax snapshot omitted parsed node observations');
108
+ return Object.freeze({
109
+ get(node) {
110
+ const observation = observations.get(node);
111
+ if (observation === undefined)
112
+ return undefined;
113
+ if ('error' in observation) {
114
+ // An exception may be edited by its catcher; retain the captured bytes.
115
+ throw new InputError(typeof observation.error === 'string' ? observation.error : observation.error.slice());
116
+ }
117
+ return observation.positions;
118
+ },
119
+ });
120
+ }
121
+ //# sourceMappingURL=syntax-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-snapshot.js","sourceRoot":"","sources":["../src/syntax-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MA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K,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5D,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE;gBACrB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;oBACvB,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;oBACpC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;iBACrC,CAAC;aACH,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,eAAe,CAAC,wDAAwD,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC;QACtB,MAAM,IAAI,eAAe,CAAC,sDAAsD,CAAC,CAAC;IACpF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,CAAC,IAAU;YACZ,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,WAAW,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAChD,IAAI,OAAO,IAAI,WAAW,EAAE,CAAC;gBAC3B,wEAAwE;gBACxE,MAAM,IAAI,UAAU,CAClB,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,CACtF,CAAC;YACJ,CAAC;YACD,OAAO,WAAW,CAAC,SAAS,CAAC;QAC/B,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { File, GoString, Node, SyntaxPos } from '../generated/syntax-types.js';
2
+ /** Values after JSON parsing have no inherited application behavior. @internal */
3
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
4
+ /**
5
+ * Rejects unpaired UTF-16 surrogates before TextEncoder can replace them. Callers
6
+ * with source bytes use Uint8Array and receive the upstream byte-input behavior.
7
+ * @internal
8
+ */
9
+ export declare function assertUnicodeString(value: string): void;
10
+ /**
11
+ * Encodes bytes and exact integers without relying on JSON's number precision or
12
+ * Uint8Array property enumeration. Circular input is a caller error, not a stack
13
+ * overflow or a partially transferred request.
14
+ * @internal
15
+ */
16
+ export declare function encodeWire(value: unknown): string;
17
+ /**
18
+ * Restores byte-bearing Go values. Ordinary syntax fields retain their spelling,
19
+ * nulls, defaults, and ordering; no source location or synthetic node is added.
20
+ * @internal
21
+ */
22
+ export declare function decodeWire(text: string): unknown;
23
+ /** A Go string is text only when every original byte is valid UTF-8. @internal */
24
+ export declare function isGoString(value: unknown): value is GoString;
25
+ /** Checks the observable uint32-backed position shape without inventing bounds. @internal */
26
+ export declare function isSyntaxPos(value: unknown): value is SyntaxPos;
27
+ /** Narrows complete syntax.Nodes or typed nil Node interfaces; auxiliaries are excluded. @internal */
28
+ export declare function isSyntaxNode(value: unknown): value is Node;
29
+ /** The public parser's root is the precise upstream File representation. @internal */
30
+ export declare function isSyntaxFile(value: unknown): value is File;
31
+ //# sourceMappingURL=syntax-wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-wire.d.ts","sourceRoot":"","sources":["../src/syntax-wire.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEpF,kFAAkF;AAClF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CASvD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgCjD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAmBhD;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAwB9D;AA4ED,sGAAsG;AACtG,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAS1D;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAE1D"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Lossless JSON adaptation at the JS/Go boundary. Go strings are byte sequences;
3
+ * integer arguments may span 64 bits. Tagged encodings preserve those domains
4
+ * without changing the public syntax records into a second tree model.
5
+ */
6
+ import { InputError } from './syntax-errors.js';
7
+ import { ShInternalError } from './errors.js';
8
+ import { SYNTAX_INTERFACES, SYNTAX_SCHEMA, } from '../generated/syntax-schema.js';
9
+ /** Values after JSON parsing have no inherited application behavior. @internal */
10
+ export function isRecord(value) {
11
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
12
+ }
13
+ /**
14
+ * Rejects unpaired UTF-16 surrogates before TextEncoder can replace them. Callers
15
+ * with source bytes use Uint8Array and receive the upstream byte-input behavior.
16
+ * @internal
17
+ */
18
+ export function assertUnicodeString(value) {
19
+ for (const character of value) {
20
+ const point = character.codePointAt(0);
21
+ if (point !== undefined && point >= 0xd800 && point <= 0xdfff) {
22
+ throw new InputError('A string contains an unpaired UTF-16 surrogate; supply exact bytes instead');
23
+ }
24
+ }
25
+ }
26
+ /**
27
+ * Encodes bytes and exact integers without relying on JSON's number precision or
28
+ * Uint8Array property enumeration. Circular input is a caller error, not a stack
29
+ * overflow or a partially transferred request.
30
+ * @internal
31
+ */
32
+ export function encodeWire(value) {
33
+ const ancestors = new Set();
34
+ const visit = (item) => {
35
+ if (typeof item === 'string') {
36
+ assertUnicodeString(item);
37
+ return item;
38
+ }
39
+ if (typeof item === 'bigint')
40
+ return { Int: item.toString() };
41
+ if (item instanceof Uint8Array)
42
+ return { Bytes: Buffer.from(item).toString('base64') };
43
+ if (item === null || typeof item === 'boolean')
44
+ return item;
45
+ if (typeof item === 'number') {
46
+ if (!Number.isSafeInteger(item))
47
+ throw new InputError('Numeric values must be safe integers; use bigint for 64-bit arguments');
48
+ return item;
49
+ }
50
+ if (typeof item !== 'object')
51
+ throw new InputError('Syntax wire values must be data records, arrays, bytes, or scalar values');
52
+ if (ancestors.has(item))
53
+ throw new InputError('Syntax records cannot contain cycles');
54
+ ancestors.add(item);
55
+ try {
56
+ if (Array.isArray(item))
57
+ return item.map(visit);
58
+ if (!isRecord(item))
59
+ throw new InputError('Expected a syntax data record');
60
+ return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, visit(child)]));
61
+ }
62
+ finally {
63
+ ancestors.delete(item);
64
+ }
65
+ };
66
+ return JSON.stringify(visit(value));
67
+ }
68
+ /**
69
+ * Restores byte-bearing Go values. Ordinary syntax fields retain their spelling,
70
+ * nulls, defaults, and ordering; no source location or synthetic node is added.
71
+ * @internal
72
+ */
73
+ export function decodeWire(text) {
74
+ let parsed;
75
+ try {
76
+ parsed = JSON.parse(text);
77
+ }
78
+ catch (cause) {
79
+ throw new ShInternalError(`Invalid syntax bridge JSON: ${String(cause)}`);
80
+ }
81
+ const visit = (item) => {
82
+ if (Array.isArray(item))
83
+ return item.map(visit);
84
+ if (!isRecord(item))
85
+ return item;
86
+ if (Object.keys(item).length === 1 && typeof item.Bytes === 'string') {
87
+ const bytes = Buffer.from(item.Bytes, 'base64');
88
+ if (bytes.toString('base64') !== item.Bytes)
89
+ throw new ShInternalError('Invalid base64 in syntax bridge response');
90
+ return new Uint8Array(bytes);
91
+ }
92
+ return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, visit(child)]));
93
+ };
94
+ return visit(parsed);
95
+ }
96
+ /** A Go string is text only when every original byte is valid UTF-8. @internal */
97
+ export function isGoString(value) {
98
+ return typeof value === 'string' || value instanceof Uint8Array;
99
+ }
100
+ /** Checks the observable uint32-backed position shape without inventing bounds. @internal */
101
+ export function isSyntaxPos(value) {
102
+ if (!isRecord(value))
103
+ return false;
104
+ const uint = (item, maximum) => typeof item === 'number' && Number.isInteger(item) && item >= 0 && item <= maximum;
105
+ const shape = Object.keys(value).length === 6 &&
106
+ uint(value.Offset, 0xffff_ffff - 11) &&
107
+ uint(value.Line, 0x3_ffff) &&
108
+ uint(value.Col, 0x3fff) &&
109
+ typeof value.IsValid === 'boolean' &&
110
+ typeof value.IsRecovered === 'boolean' &&
111
+ typeof value.OffsetOverflow === 'boolean';
112
+ if (!shape)
113
+ return false;
114
+ if (value.IsRecovered) {
115
+ return (value.OffsetOverflow === true &&
116
+ value.IsValid === false &&
117
+ value.Offset === 0 &&
118
+ value.Line === 0 &&
119
+ value.Col === 0);
120
+ }
121
+ if (value.OffsetOverflow)
122
+ return value.IsValid === false && value.Offset === 0;
123
+ return value.IsValid === (value.Line !== 0 || value.Col !== 0);
124
+ }
125
+ /**
126
+ * A Go interface can hold a nil pointer with a concrete dynamic type. Its tag
127
+ * preserves that type without inventing fields for a nonexistent record.
128
+ */
129
+ function isTypedNil(value, implementers) {
130
+ return (isRecord(value) &&
131
+ value.Type === 'TypedNil' &&
132
+ typeof value.Kind === 'string' &&
133
+ Object.keys(value).length === 2 &&
134
+ implementers.includes(value.Kind));
135
+ }
136
+ /**
137
+ * Validates complete records against the pinned schema, including nil-bearing
138
+ * boundaries. This is a boundary check, not a semantic shell interpretation.
139
+ */
140
+ function matchesRecord(value, active) {
141
+ if (!isRecord(value) || typeof value.Type !== 'string' || active.has(value))
142
+ return false;
143
+ if (!Object.hasOwn(SYNTAX_SCHEMA, value.Type))
144
+ return false;
145
+ const descriptor = SYNTAX_SCHEMA[value.Type];
146
+ if (Object.keys(value).length !== Object.keys(descriptor.fields).length + 1)
147
+ return false;
148
+ active.add(value);
149
+ try {
150
+ return Object.entries(descriptor.fields).every(([name, field]) => Object.hasOwn(value, name) && matchesField(value[name], field, active));
151
+ }
152
+ finally {
153
+ active.delete(value);
154
+ }
155
+ }
156
+ /** Checks one upstream field without conflating a nil slice with an empty one. */
157
+ function matchesField(value, field, active) {
158
+ if (value === null)
159
+ return field.nullable;
160
+ if (field.slice) {
161
+ return (Array.isArray(value) &&
162
+ value.every((item) => item === null ? field.elementNullable : matchesScalar(item, field, active)));
163
+ }
164
+ return matchesScalar(value, field, active);
165
+ }
166
+ /** Each scalar category retains its upstream domain rather than JS coercions. */
167
+ function matchesScalar(value, field, active) {
168
+ switch (field.kind) {
169
+ case 'boolean':
170
+ return typeof value === 'boolean';
171
+ case 'string':
172
+ return isGoString(value);
173
+ case 'position':
174
+ return isSyntaxPos(value);
175
+ case 'operator':
176
+ return (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 0xffff_ffff);
177
+ case 'struct':
178
+ return isRecord(value) && value.Type === field.type && matchesRecord(value, active);
179
+ case 'interface':
180
+ return (isRecord(value) &&
181
+ typeof value.Type === 'string' &&
182
+ field.type !== null &&
183
+ Object.hasOwn(SYNTAX_INTERFACES, field.type) &&
184
+ (isTypedNil(value, SYNTAX_INTERFACES[field.type]) ||
185
+ (SYNTAX_INTERFACES[field.type].includes(value.Type) && matchesRecord(value, active))));
186
+ }
187
+ }
188
+ /** Narrows complete syntax.Nodes or typed nil Node interfaces; auxiliaries are excluded. @internal */
189
+ export function isSyntaxNode(value) {
190
+ if (isTypedNil(value, SYNTAX_INTERFACES.Node))
191
+ return true;
192
+ return (isRecord(value) &&
193
+ typeof value.Type === 'string' &&
194
+ Object.hasOwn(SYNTAX_SCHEMA, value.Type) &&
195
+ SYNTAX_SCHEMA[value.Type].node &&
196
+ matchesRecord(value, new Set()));
197
+ }
198
+ /** The public parser's root is the precise upstream File representation. @internal */
199
+ export function isSyntaxFile(value) {
200
+ return isSyntaxNode(value) && value.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I,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACtF,KAAK,WAAW;YACd,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;gBACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAC9B,KAAK,CAAC,IAAI,KAAK,IAAI;gBACnB,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,KAAK,CAAC,IAAI,CAAC;gBAC5C,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC/C,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CACxF,CAAC;IACN,CAAC;AACH,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,UAAU,CAAC,KAAK,EAAE,iBAAiB,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC;QACxC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI;QAC9B,aAAa,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAChC,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;AACtD,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { OperatorFamily, RawOperator } from '../generated/syntax-constants.js';
2
+ import type { File, GoString, Node, SyntaxPos } from '../generated/syntax-types.js';
3
+ import { type ParsedFile } from './syntax-snapshot.js';
4
+ export type { ParsedFile, PositionSnapshot, NodePositions } from './syntax-snapshot.js';
5
+ export { InputError, LangError, ParseError } from './syntax-errors.js';
6
+ /**
7
+ * Whole-file parser inputs corresponding to upstream controls. Defaults match
8
+ * NewParser; in particular comments are retained only when KeepComments is true.
9
+ * Numeric int arguments accept bigint because Go's WASM int is signed 64-bit.
10
+ * @public
11
+ */
12
+ export interface ParseOptions {
13
+ /** Source identity carried by File/errors; no file is opened by the binding. */
14
+ Filename?: GoString;
15
+ /** Retains comment nodes when true; upstream defaults to false. */
16
+ KeepComments?: boolean;
17
+ /** Upstream LangVariant value. Variant rejects unsupported values, including LangAuto. */
18
+ Variant?: number | bigint;
19
+ /** Lexer delimiter with upstream byte-length, whitespace and prefix semantics. */
20
+ StopAt?: GoString;
21
+ /** Maximum number of recoverable missing grammar tokens, using upstream behavior. */
22
+ RecoverErrors?: number | bigint;
23
+ }
24
+ /**
25
+ * Parses exact source bytes, or well-formed Unicode text encoded as UTF-8. First
26
+ * use synchronously initializes WASM. The existing conservative nesting guard is
27
+ * an explicit binding resource limit, not an upstream grammar restriction.
28
+ * @public
29
+ */
30
+ export declare function parseSync(source: string | Uint8Array, options?: ParseOptions): File;
31
+ /**
32
+ * Parses once while observing every real node's upstream bounds in Go. The
33
+ * separate immutable lookup describes this original parse; it never replaces
34
+ * live nodePos/nodeEnd or tracks edits. Source adapters avoid reconstructing
35
+ * each descendant subtree just to display the original source locations.
36
+ * @public
37
+ */
38
+ export declare function parseWithPositionsSync(source: string | Uint8Array, options?: ParseOptions): ParsedFile;
39
+ /**
40
+ * Computes a node's starting position from its current fields using upstream's
41
+ * Pos method. No cached parse-time position can override subsequent tree edits.
42
+ * @public
43
+ */
44
+ export declare function nodePos(node: Node): SyntaxPos;
45
+ /**
46
+ * Computes a node's ending position using upstream's End method, including
47
+ * recovered/invalid behavior and changes to text or child nodes.
48
+ * @public
49
+ */
50
+ export declare function nodeEnd(node: Node): SyntaxPos;
51
+ /**
52
+ * Constructs an upstream position. uint64 arguments use bigint when outside the
53
+ * safe-number range; upstream clamps offsets and zeroes overflowing line/column
54
+ * values. The binding does not replace those rules with its own range policy.
55
+ * @public
56
+ */
57
+ export declare function newPos(offset: number | bigint, line: number | bigint, column: number | bigint): SyntaxPos;
58
+ /**
59
+ * Represents an unnamed value in an upstream uint32 operator family. Named
60
+ * constants remain precise literal unions; this explicit path preserves other Go
61
+ * values without claiming an operation such as Print accepts them.
62
+ * @public
63
+ */
64
+ export declare function rawOperator<Family extends OperatorFamily>(family: Family, value: number): RawOperator<Family>;
65
+ //# sourceMappingURL=syntax.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAepF,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/E,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,mEAAmE;IACnE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,kFAAkF;IAClF,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED;;;;;GAKG;AACH,w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