sh-ast 0.3.1 → 0.5.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.
- package/README.md +199 -143
- package/dist/analyze/ansi-c-escapes.d.ts +1 -1
- package/dist/analyze/ansi-c-escapes.js +1 -1
- package/dist/analyze/enumerate-commands.d.ts +11 -16
- package/dist/analyze/enumerate-commands.d.ts.map +1 -1
- package/dist/analyze/enumerate-commands.js +82 -92
- package/dist/analyze/enumerate-commands.js.map +1 -1
- package/dist/analyze/index.d.ts +3 -2
- package/dist/analyze/index.d.ts.map +1 -1
- package/dist/analyze/index.js +1 -1
- package/dist/analyze/node-helpers.d.ts +10 -21
- package/dist/analyze/node-helpers.d.ts.map +1 -1
- package/dist/analyze/node-helpers.js +16 -27
- package/dist/analyze/node-helpers.js.map +1 -1
- package/dist/analyze/resolve-argv0.d.ts +6 -6
- package/dist/analyze/resolve-argv0.js +6 -6
- package/dist/analyze/resolve-word.d.ts +7 -10
- package/dist/analyze/resolve-word.d.ts.map +1 -1
- package/dist/analyze/resolve-word.js +39 -22
- package/dist/analyze/resolve-word.js.map +1 -1
- package/dist/analyze.d.ts +3780 -397
- package/dist/errors.d.ts +6 -79
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -64
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +20 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/sh-ast.d.ts +3616 -1020
- package/dist/syntax-errors.d.ts +56 -0
- package/dist/syntax-errors.d.ts.map +1 -0
- package/dist/syntax-errors.js +80 -0
- package/dist/syntax-errors.js.map +1 -0
- package/dist/syntax-print-errors.d.ts +35 -0
- package/dist/syntax-print-errors.d.ts.map +1 -0
- package/dist/syntax-print-errors.js +37 -0
- package/dist/syntax-print-errors.js.map +1 -0
- package/dist/syntax-print.d.ts +49 -0
- package/dist/syntax-print.d.ts.map +1 -0
- package/dist/syntax-print.js +86 -0
- package/dist/syntax-print.js.map +1 -0
- package/dist/syntax-snapshot.d.ts +47 -0
- package/dist/syntax-snapshot.d.ts.map +1 -0
- package/dist/syntax-snapshot.js +121 -0
- package/dist/syntax-snapshot.js.map +1 -0
- package/dist/syntax-walk-bounds.d.ts +18 -0
- package/dist/syntax-walk-bounds.d.ts.map +1 -0
- package/dist/syntax-walk-bounds.js +188 -0
- package/dist/syntax-walk-bounds.js.map +1 -0
- package/dist/syntax-walk-errors.d.ts +19 -0
- package/dist/syntax-walk-errors.d.ts.map +1 -0
- package/dist/syntax-walk-errors.js +23 -0
- package/dist/syntax-walk-errors.js.map +1 -0
- package/dist/syntax-walk-license.d.ts +3 -0
- package/dist/syntax-walk-license.d.ts.map +1 -0
- package/dist/syntax-walk-license.js +37 -0
- package/dist/syntax-walk-license.js.map +1 -0
- package/dist/syntax-walk.d.ts +46 -0
- package/dist/syntax-walk.d.ts.map +1 -0
- package/dist/syntax-walk.js +322 -0
- package/dist/syntax-walk.js.map +1 -0
- package/dist/syntax-wire.d.ts +31 -0
- package/dist/syntax-wire.d.ts.map +1 -0
- package/dist/syntax-wire.js +202 -0
- package/dist/syntax-wire.js.map +1 -0
- package/dist/syntax.d.ts +65 -0
- package/dist/syntax.d.ts.map +1 -0
- package/dist/syntax.js +152 -0
- package/dist/syntax.js.map +1 -0
- package/dist/wasm-instance.d.ts +5 -8
- package/dist/wasm-instance.d.ts.map +1 -1
- package/dist/wasm-instance.js +44 -47
- package/dist/wasm-instance.js.map +1 -1
- package/generated/syntax-constants.d.ts +1652 -0
- package/generated/syntax-constants.js +1384 -0
- package/generated/syntax-schema.d.ts +60 -0
- package/generated/syntax-schema.js +1740 -0
- package/generated/syntax-types.d.ts +1977 -0
- package/package.json +2 -2
- package/shim/sh-ast.wasm +0 -0
- package/dist/normalize.d.ts +0 -52
- package/dist/normalize.d.ts.map +0 -1
- package/dist/normalize.js +0 -260
- package/dist/normalize.js.map +0 -1
- package/dist/parse.d.ts +0 -50
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js +0 -125
- package/dist/parse.js.map +0 -1
- package/dist/types.d.ts +0 -74
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/visitor-keys.d.ts +0 -21
- package/dist/visitor-keys.d.ts.map +0 -1
- package/dist/visitor-keys.js +0 -23
- package/dist/visitor-keys.js.map +0 -1
- package/dist/walk.d.ts +0 -18
- package/dist/walk.d.ts.map +0 -1
- package/dist/walk.js +0 -40
- package/dist/walk.js.map +0 -1
- package/generated/child-type-schema.d.ts +0 -14
- package/generated/child-type-schema.js +0 -188
- package/generated/node-types.d.ts +0 -1002
- package/generated/position-fields.d.ts +0 -21
- package/generated/position-fields.js +0 -50
- package/generated/visitor-keys.d.ts +0 -11
- package/generated/visitor-keys.js +0 -50
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { InputError } from './syntax-errors.js';
|
|
2
|
+
import { afterItemStart, atStatementEnd } from './syntax-walk-bounds.js';
|
|
3
|
+
import { nilDereference, WalkPanicError } from './syntax-walk-errors.js';
|
|
4
|
+
export { WalkPanicError } from './syntax-walk-errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Walks synchronously using the pinned upstream case ordering. Each accepted entry is followed by its
|
|
7
|
+
* children and a null exit. Returning false prunes the entry without an exit;
|
|
8
|
+
* boolean exit return values are ignored. Every callback must return a boolean
|
|
9
|
+
* synchronously; other results produce InputError. Callback exceptions retain their identity,
|
|
10
|
+
* and upstream deferred comment callbacks still run during exception unwinding.
|
|
11
|
+
*
|
|
12
|
+
* Children and later fields are read live. Each list captures its array reference
|
|
13
|
+
* and length when traversal reaches that list, then reads existing later slots
|
|
14
|
+
* when reached. Replacing or reordering later slots is observed and can cause
|
|
15
|
+
* a node to be skipped or revisited. Indices added beyond the captured extent
|
|
16
|
+
* are not visited by that active list. Replacing the owner's array field does not
|
|
17
|
+
* redirect an active list, but a later walk or print sees the current field.
|
|
18
|
+
* Changes made before a list is reached are observed when it starts.
|
|
19
|
+
*
|
|
20
|
+
* Supported edits preserve each node's Type (and TypedNil.Kind), required field
|
|
21
|
+
* shapes and every index within each active list's captured extent. Leaving
|
|
22
|
+
* holes or shrinking an array below that extent (for example through truncation,
|
|
23
|
+
* deletion, or length-reducing splice/shift) is outside the mutation contract.
|
|
24
|
+
* These are not runtime validation rules. Ordinary JavaScript object and array
|
|
25
|
+
* aliases remain shared; the binding does not model distinct Go slice headers or
|
|
26
|
+
* capacity-dependent allocation over shared backing storage.
|
|
27
|
+
*
|
|
28
|
+
* Comments on Stmt, CaseItem and ArrayElem are copied before their callbacks,
|
|
29
|
+
* including position and byte-string values; editing a copy does not edit the
|
|
30
|
+
* stored comment. Last/CondLast/ThenLast/DoLast callbacks receive the stored
|
|
31
|
+
* JavaScript Comment object. Replacing its array slot leaves any previously
|
|
32
|
+
* retained callback object unchanged: there is no Go value-slot pointer identity.
|
|
33
|
+
* Reentrant walks maintain independent traversal state.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export function walk(node, callback) {
|
|
37
|
+
visit(node, callback);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Calls user code without intercepting its exceptions, then enforces Go's bool
|
|
41
|
+
* return domain before traversal can consume the result. Exit results share
|
|
42
|
+
* that domain even though their boolean values do not control traversal.
|
|
43
|
+
*/
|
|
44
|
+
function invokeCallback(node, callback) {
|
|
45
|
+
const result = callback(node);
|
|
46
|
+
if (typeof result !== 'boolean') {
|
|
47
|
+
throw new InputError('Walk callbacks must return a boolean synchronously');
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/** An unconditional concrete-pointer child is observable even when the pointer is nil. */
|
|
52
|
+
function pointer(node, kind, callback) {
|
|
53
|
+
visit(node ?? { Type: 'TypedNil', Kind: kind }, callback);
|
|
54
|
+
}
|
|
55
|
+
/** Optional fields skip null; a typed-nil interface is nevertheless a non-null interface. */
|
|
56
|
+
function optional(node, callback) {
|
|
57
|
+
if (node !== null) {
|
|
58
|
+
visit(node, callback);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Captures one ordinary array and its initial extent when this list is reached.
|
|
63
|
+
* Later existing slots are read live; appends and owner-field replacements cannot
|
|
64
|
+
* extend or redirect the active list. Removing indices within its captured
|
|
65
|
+
* extent is unsupported.
|
|
66
|
+
*/
|
|
67
|
+
function list(nodes, kind, callback) {
|
|
68
|
+
if (nodes === null) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const length = nodes.length;
|
|
72
|
+
for (let index = 0; index < length; index++) {
|
|
73
|
+
const node = nodes[index] ?? null;
|
|
74
|
+
if (kind === null) {
|
|
75
|
+
visit(node, callback);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
pointer(node, kind, callback);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Visits stored JavaScript Comment objects, unlike the copies used by item loops.
|
|
84
|
+
* Later slot replacement is read live, but retained objects do not become Go
|
|
85
|
+
* pointers to replacement values. The active array and extent remain captured.
|
|
86
|
+
*/
|
|
87
|
+
function comments(nodes, callback) {
|
|
88
|
+
if (nodes === null) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const length = nodes.length;
|
|
92
|
+
for (let index = 0; index < length; index++) {
|
|
93
|
+
pointer(nodes[index] ?? null, 'Comment', callback);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Auxiliary pointers are reread after callbacks may replace or clear their owner field. */
|
|
97
|
+
function dereference(value) {
|
|
98
|
+
if (value === null) {
|
|
99
|
+
return nilDereference();
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
/** Go copies a Comment's position and immutable string value before its callback. */
|
|
104
|
+
function copyComment(node) {
|
|
105
|
+
return {
|
|
106
|
+
Type: 'Comment',
|
|
107
|
+
Hash: { ...node.Hash },
|
|
108
|
+
Text: typeof node.Text === 'string' ? node.Text : node.Text.slice(),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A single defer belongs to this occurrence. The try/finally surrounds all child
|
|
113
|
+
* work and the null exit, preserving Go's unwind order and replacement exception.
|
|
114
|
+
*/
|
|
115
|
+
function visit(node, callback) {
|
|
116
|
+
if (!invokeCallback(node, callback)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (node === null) {
|
|
120
|
+
throw new WalkPanicError('syntax.Walk: unexpected node type <nil>');
|
|
121
|
+
}
|
|
122
|
+
if (node.Type === 'TypedNil') {
|
|
123
|
+
if (node.Kind === 'BraceExp') {
|
|
124
|
+
throw new WalkPanicError('syntax.Walk: unexpected node type *syntax.BraceExp');
|
|
125
|
+
}
|
|
126
|
+
if (node.Kind !== 'Lit' && node.Kind !== 'Comment' && node.Kind !== 'SglQuoted') {
|
|
127
|
+
nilDereference();
|
|
128
|
+
}
|
|
129
|
+
invokeCallback(null, callback);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let deferred;
|
|
133
|
+
try {
|
|
134
|
+
switch (node.Type) {
|
|
135
|
+
case 'File':
|
|
136
|
+
list(node.Stmts, 'Stmt', callback);
|
|
137
|
+
comments(node.Last, callback);
|
|
138
|
+
break;
|
|
139
|
+
case 'Comment':
|
|
140
|
+
case 'Lit':
|
|
141
|
+
case 'SglQuoted':
|
|
142
|
+
break;
|
|
143
|
+
case 'Stmt': {
|
|
144
|
+
const values = node.Comments;
|
|
145
|
+
const length = values?.length ?? 0;
|
|
146
|
+
for (let index = 0; values !== null && index < length; index++) {
|
|
147
|
+
const value = copyComment(values[index]);
|
|
148
|
+
if (atStatementEnd(node, value.Hash)) {
|
|
149
|
+
deferred = value;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
visit(value, callback);
|
|
153
|
+
}
|
|
154
|
+
optional(node.Cmd, callback);
|
|
155
|
+
list(node.Redirs, 'Redirect', callback);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'Assign':
|
|
159
|
+
optional(node.Name, callback);
|
|
160
|
+
optional(node.Value, callback);
|
|
161
|
+
optional(node.Index, callback);
|
|
162
|
+
optional(node.Array, callback);
|
|
163
|
+
break;
|
|
164
|
+
case 'Redirect':
|
|
165
|
+
optional(node.N, callback);
|
|
166
|
+
pointer(node.Word, 'Word', callback);
|
|
167
|
+
optional(node.Hdoc, callback);
|
|
168
|
+
break;
|
|
169
|
+
case 'CallExpr':
|
|
170
|
+
list(node.Assigns, 'Assign', callback);
|
|
171
|
+
list(node.Args, 'Word', callback);
|
|
172
|
+
break;
|
|
173
|
+
case 'Subshell':
|
|
174
|
+
case 'Block':
|
|
175
|
+
case 'CmdSubst':
|
|
176
|
+
case 'ProcSubst':
|
|
177
|
+
list(node.Stmts, 'Stmt', callback);
|
|
178
|
+
comments(node.Last, callback);
|
|
179
|
+
break;
|
|
180
|
+
case 'IfClause':
|
|
181
|
+
list(node.Cond, 'Stmt', callback);
|
|
182
|
+
comments(node.CondLast, callback);
|
|
183
|
+
list(node.Then, 'Stmt', callback);
|
|
184
|
+
comments(node.ThenLast, callback);
|
|
185
|
+
optional(node.Else, callback);
|
|
186
|
+
break;
|
|
187
|
+
case 'WhileClause':
|
|
188
|
+
list(node.Cond, 'Stmt', callback);
|
|
189
|
+
comments(node.CondLast, callback);
|
|
190
|
+
list(node.Do, 'Stmt', callback);
|
|
191
|
+
comments(node.DoLast, callback);
|
|
192
|
+
break;
|
|
193
|
+
case 'ForClause':
|
|
194
|
+
visit(node.Loop, callback);
|
|
195
|
+
list(node.Do, 'Stmt', callback);
|
|
196
|
+
comments(node.DoLast, callback);
|
|
197
|
+
break;
|
|
198
|
+
case 'WordIter':
|
|
199
|
+
pointer(node.Name, 'Lit', callback);
|
|
200
|
+
list(node.Items, 'Word', callback);
|
|
201
|
+
break;
|
|
202
|
+
case 'CStyleLoop':
|
|
203
|
+
optional(node.Init, callback);
|
|
204
|
+
optional(node.Cond, callback);
|
|
205
|
+
optional(node.Post, callback);
|
|
206
|
+
break;
|
|
207
|
+
case 'BinaryCmd':
|
|
208
|
+
pointer(node.X, 'Stmt', callback);
|
|
209
|
+
pointer(node.Y, 'Stmt', callback);
|
|
210
|
+
break;
|
|
211
|
+
case 'FuncDecl':
|
|
212
|
+
optional(node.Name, callback);
|
|
213
|
+
list(node.Names, 'Lit', callback);
|
|
214
|
+
pointer(node.Body, 'Stmt', callback);
|
|
215
|
+
break;
|
|
216
|
+
case 'Word':
|
|
217
|
+
case 'DblQuoted':
|
|
218
|
+
list(node.Parts, null, callback);
|
|
219
|
+
break;
|
|
220
|
+
case 'ParamExp':
|
|
221
|
+
optional(node.Flags, callback);
|
|
222
|
+
optional(node.Param, callback);
|
|
223
|
+
optional(node.NestedParam, callback);
|
|
224
|
+
optional(node.Index, callback);
|
|
225
|
+
if (node.Slice !== null) {
|
|
226
|
+
optional(node.Slice.Offset, callback);
|
|
227
|
+
optional(dereference(node.Slice).Length, callback);
|
|
228
|
+
}
|
|
229
|
+
if (node.Repl !== null) {
|
|
230
|
+
optional(node.Repl.Orig, callback);
|
|
231
|
+
optional(dereference(node.Repl).With, callback);
|
|
232
|
+
}
|
|
233
|
+
if (node.Exp !== null) {
|
|
234
|
+
optional(node.Exp.Word, callback);
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
case 'ArithmExp':
|
|
238
|
+
case 'ArithmCmd':
|
|
239
|
+
case 'UnaryArithm':
|
|
240
|
+
case 'UnaryTest':
|
|
241
|
+
case 'ParenArithm':
|
|
242
|
+
case 'ParenTest':
|
|
243
|
+
case 'TestClause':
|
|
244
|
+
visit(node.X, callback);
|
|
245
|
+
break;
|
|
246
|
+
case 'BinaryArithm':
|
|
247
|
+
case 'BinaryTest':
|
|
248
|
+
visit(node.X, callback);
|
|
249
|
+
visit(node.Y, callback);
|
|
250
|
+
break;
|
|
251
|
+
case 'FlagsArithm':
|
|
252
|
+
pointer(node.Flags, 'Lit', callback);
|
|
253
|
+
optional(node.X, callback);
|
|
254
|
+
break;
|
|
255
|
+
case 'CaseClause':
|
|
256
|
+
pointer(node.Word, 'Word', callback);
|
|
257
|
+
list(node.Items, 'CaseItem', callback);
|
|
258
|
+
comments(node.Last, callback);
|
|
259
|
+
break;
|
|
260
|
+
case 'CaseItem':
|
|
261
|
+
case 'ArrayElem': {
|
|
262
|
+
const values = node.Comments;
|
|
263
|
+
const length = values?.length ?? 0;
|
|
264
|
+
for (let index = 0; values !== null && index < length; index++) {
|
|
265
|
+
const value = copyComment(values[index]);
|
|
266
|
+
if (afterItemStart(node, value.Hash)) {
|
|
267
|
+
deferred = value;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
visit(value, callback);
|
|
271
|
+
}
|
|
272
|
+
if (node.Type === 'CaseItem') {
|
|
273
|
+
list(node.Patterns, 'Word', callback);
|
|
274
|
+
list(node.Stmts, 'Stmt', callback);
|
|
275
|
+
comments(node.Last, callback);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
optional(node.Index, callback);
|
|
279
|
+
optional(node.Value, callback);
|
|
280
|
+
}
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'DeclClause':
|
|
284
|
+
list(node.Args, 'Assign', callback);
|
|
285
|
+
break;
|
|
286
|
+
case 'ArrayExpr':
|
|
287
|
+
list(node.Elems, 'ArrayElem', callback);
|
|
288
|
+
comments(node.Last, callback);
|
|
289
|
+
break;
|
|
290
|
+
case 'ExtGlob':
|
|
291
|
+
pointer(node.Pattern, 'Lit', callback);
|
|
292
|
+
break;
|
|
293
|
+
case 'TimeClause':
|
|
294
|
+
optional(node.Stmt, callback);
|
|
295
|
+
break;
|
|
296
|
+
case 'CoprocClause':
|
|
297
|
+
optional(node.Name, callback);
|
|
298
|
+
pointer(node.Stmt, 'Stmt', callback);
|
|
299
|
+
break;
|
|
300
|
+
case 'LetClause':
|
|
301
|
+
list(node.Exprs, null, callback);
|
|
302
|
+
break;
|
|
303
|
+
case 'TestDecl':
|
|
304
|
+
pointer(node.Description, 'Word', callback);
|
|
305
|
+
pointer(node.Body, 'Stmt', callback);
|
|
306
|
+
break;
|
|
307
|
+
case 'BraceExp':
|
|
308
|
+
throw new WalkPanicError('syntax.Walk: unexpected node type *syntax.BraceExp');
|
|
309
|
+
default: {
|
|
310
|
+
const exhaustive = node;
|
|
311
|
+
throw new WalkPanicError(`syntax.Walk: unexpected node type ${String(exhaustive)}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
invokeCallback(null, callback);
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
if (deferred !== undefined) {
|
|
318
|
+
visit(deferred, callback);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=syntax-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk.js","sourceRoot":"","sources":["../src/syntax-walk.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAOzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,IAAI,CAAC,IAAU,EAAE,QAAwC;IACvE,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,IAAiB,EAAE,QAAmB;IAC5D,MAAM,MAAM,GAAY,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,OAAO,MAAM,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,UAAU,CAAC,oDAAo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EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC5C,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBACrC,MAAM;YACR,KAAK,UAAU;gBACb,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;YACjF,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,UAAU,GAAU,IAAI,CAAC;gBAC/B,MAAM,IAAI,cAAc,CAAC,qCAAqC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACtF,CAAC;QACH,CAAC;QACD,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;YAAS,CAAC;QACT,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;AACH,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.Type === 'File';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awOperator } 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,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