wesl 0.6.49 → 0.7.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.
- package/dist/index.d.ts +269 -215
- package/dist/index.js +2911 -1539
- package/package.json +6 -8
- package/src/AbstractElems.ts +81 -81
- package/src/Assertions.ts +5 -5
- package/src/BindIdents.ts +192 -306
- package/src/ClickableError.ts +3 -2
- package/src/Conditions.ts +2 -2
- package/src/LinkedWesl.ts +1 -1
- package/src/Linker.ts +4 -3
- package/src/LinkerUtil.ts +1 -1
- package/src/Logging.ts +165 -0
- package/src/LowerAndEmit.ts +278 -110
- package/src/ModuleResolver.ts +15 -25
- package/src/ParseError.ts +9 -0
- package/src/ParseWESL.ts +30 -94
- package/src/RawEmit.ts +1 -4
- package/src/Reflection.ts +1 -1
- package/src/Scope.ts +3 -0
- package/src/Span.ts +2 -0
- package/src/SrcMap.ts +208 -0
- package/src/Stream.ts +30 -0
- package/src/TransformBindingStructs.ts +2 -2
- package/src/Util.ts +1 -1
- package/src/debug/ASTtoString.ts +84 -135
- package/src/discovery/FindUnboundIdents.ts +14 -5
- package/src/index.ts +4 -0
- package/src/parse/ContentsHelpers.ts +70 -0
- package/src/parse/ExpressionUtil.ts +121 -0
- package/src/parse/Keywords.ts +12 -12
- package/src/parse/OperatorBinding.ts +146 -0
- package/src/parse/ParseAttribute.ts +272 -0
- package/src/parse/ParseCall.ts +77 -0
- package/src/parse/ParseControlFlow.ts +129 -0
- package/src/parse/ParseDirective.ts +105 -0
- package/src/parse/ParseExpression.ts +288 -0
- package/src/parse/ParseFn.ts +151 -0
- package/src/parse/ParseGlobalVar.ts +131 -0
- package/src/parse/ParseIdent.ts +77 -0
- package/src/parse/ParseImport.ts +160 -0
- package/src/parse/ParseLocalVar.ts +69 -0
- package/src/parse/ParseLoop.ts +112 -0
- package/src/parse/ParseModule.ts +116 -0
- package/src/parse/ParseSimpleStatement.ts +162 -0
- package/src/parse/ParseStatement.ts +215 -0
- package/src/parse/ParseStruct.ts +89 -0
- package/src/parse/ParseType.ts +71 -0
- package/src/parse/ParseUtil.ts +174 -0
- package/src/parse/ParseValueDeclaration.ts +130 -0
- package/src/parse/ParseWesl.ts +51 -0
- package/src/parse/ParsingContext.ts +93 -0
- package/src/parse/WeslStream.ts +63 -20
- package/src/parse/stream/CachingStream.ts +48 -0
- package/src/parse/stream/MatchersStream.ts +85 -0
- package/src/parse/stream/RegexHelpers.ts +38 -0
- package/src/test/BevyLink.test.ts +100 -0
- package/src/test/BindStdTypes.test.ts +110 -0
- package/src/test/{BindWESL.test.ts → BindWESLV2.test.ts} +21 -22
- package/src/test/BulkTests.test.ts +11 -12
- package/src/test/ConditionLinking.test.ts +107 -0
- package/src/test/ConditionalElif.test.ts +1 -13
- package/src/test/ConditionalTranslationCases.test.ts +5 -0
- package/src/test/ErrorLogging.test.ts +2 -2
- package/src/test/ImportCasesV2.test.ts +63 -0
- package/src/test/LinkFails.test.ts +69 -0
- package/src/test/LinkPackage.test.ts +1 -1
- package/src/test/Linker.test.ts +75 -2
- package/src/test/LogCatcher.ts +53 -0
- package/src/test/Mangling.test.ts +1 -1
- package/src/test/ParseComments.test.ts +1 -2
- package/src/test/{ParseConditions.test.ts → ParseConditionsV2.test.ts} +57 -49
- package/src/test/ParseErrorV2.test.ts +73 -0
- package/src/test/{ParseWESL.test.ts → ParseWeslV2.test.ts} +288 -370
- package/src/test/{ScopeWESL.test.ts → ScopeWESLV2.test.ts} +205 -176
- package/src/test/TestLink.ts +51 -51
- package/src/test/TestSetup.ts +9 -3
- package/src/test/TestUtil.ts +47 -77
- package/src/test/TrimmedMatch.ts +40 -0
- package/src/test/VirtualModules.test.ts +33 -2
- package/src/test/WeslDevice.test.ts +9 -2
- package/src/test/__snapshots__/ParseWeslV2.test.ts.snap +67 -0
- package/src/test-util.ts +7 -0
- package/src/WESLCollect.ts +0 -656
- package/src/parse/AttributeGrammar.ts +0 -232
- package/src/parse/ImportGrammar.ts +0 -195
- package/src/parse/WeslBaseGrammar.ts +0 -11
- package/src/parse/WeslExpression.ts +0 -231
- package/src/parse/WeslGrammar.ts +0 -739
- package/src/test/Expression.test.ts +0 -22
- package/src/test/ImportSyntaxCases.test.ts +0 -24
- package/src/test/ParseError.test.ts +0 -45
- package/src/test/Reflection.test.ts +0 -176
- package/src/test/TransformBindingStructs.test.ts +0 -238
- /package/src/test/{ParseElif.test.ts → ParseElifV2.test.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AppState, ParseError, Span, SrcMap, Stream, TypedToken } from "mini-parse";
|
|
2
|
-
|
|
3
1
|
//#region src/LiveDeclarations.d.ts
|
|
4
2
|
/** decls currently visible in this scope */
|
|
5
3
|
interface LiveDecls {
|
|
@@ -19,50 +17,57 @@ interface FlatImport {
|
|
|
19
17
|
modulePath: string[];
|
|
20
18
|
}
|
|
21
19
|
//#endregion
|
|
22
|
-
//#region src/
|
|
23
|
-
|
|
20
|
+
//#region src/Span.d.ts
|
|
21
|
+
/** A range, from start (inclusive) to end (exclusive). */
|
|
22
|
+
type Span = readonly [number, number];
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/ParseError.d.ts
|
|
25
|
+
declare class ParseError extends Error {
|
|
26
|
+
span: Span;
|
|
27
|
+
constructor(msg: string, span: Span);
|
|
28
|
+
}
|
|
24
29
|
//#endregion
|
|
25
30
|
//#region src/ParseWESL.d.ts
|
|
26
|
-
/**
|
|
31
|
+
/** Partial element being constructed during parsing. */
|
|
32
|
+
type OpenElem<T extends ContainerElem = ContainerElem> = Pick<T, "kind" | "contents">;
|
|
33
|
+
/**
|
|
34
|
+
* Result of parsing one WESL module (e.g., one .wesl file).
|
|
27
35
|
*
|
|
28
|
-
* The
|
|
29
|
-
* for convenient access by the binding stage.
|
|
36
|
+
* The AST is constructed into three sections for the binding stage:
|
|
30
37
|
* - import statements
|
|
31
38
|
* - language elements (fn, struct, etc)
|
|
32
39
|
* - scopes
|
|
33
|
-
*
|
|
34
40
|
*/
|
|
35
41
|
interface WeslAST {
|
|
36
|
-
/**
|
|
42
|
+
/** Source text for this module. */
|
|
37
43
|
srcModule: SrcModule;
|
|
38
|
-
/**
|
|
44
|
+
/** Root module element. */
|
|
39
45
|
moduleElem: ModuleElem;
|
|
40
|
-
/**
|
|
46
|
+
/** Root scope for this module. */
|
|
41
47
|
rootScope: Scope;
|
|
42
|
-
/**
|
|
48
|
+
/** Imports found in this module. */
|
|
43
49
|
imports: ImportStatement[];
|
|
44
|
-
/**
|
|
50
|
+
/** Module level const_assert statements. */
|
|
45
51
|
moduleAsserts?: ConstAssertElem[];
|
|
46
52
|
}
|
|
47
|
-
/**
|
|
53
|
+
/** Extended AST with cached flattened imports. */
|
|
48
54
|
interface BindingAST extends WeslAST {
|
|
55
|
+
/** Flattened import statements (cached on demand). */
|
|
49
56
|
_flatImports?: FlatImport[];
|
|
50
57
|
}
|
|
51
|
-
/**
|
|
52
|
-
interface WeslParseState
|
|
58
|
+
/** Stable and unstable state used during parsing. */
|
|
59
|
+
interface WeslParseState {
|
|
53
60
|
context: WeslParseContext;
|
|
54
61
|
stable: StableState;
|
|
55
62
|
}
|
|
56
|
-
/**
|
|
63
|
+
/** Stable values used or accumulated during parsing. */
|
|
57
64
|
type StableState = WeslAST;
|
|
58
|
-
/**
|
|
65
|
+
/** Unstable values used during parse collection. */
|
|
59
66
|
interface WeslParseContext {
|
|
60
67
|
scope: Scope;
|
|
61
68
|
openElems: OpenElem[];
|
|
62
69
|
}
|
|
63
|
-
/**
|
|
64
|
-
* An error when parsing WESL fails. Designed to be human-readable.
|
|
65
|
-
*/
|
|
70
|
+
/** Human-readable error when parsing WESL fails. */
|
|
66
71
|
declare class WeslParseError extends Error {
|
|
67
72
|
span: Span;
|
|
68
73
|
src: SrcModule;
|
|
@@ -71,11 +76,9 @@ declare class WeslParseError extends Error {
|
|
|
71
76
|
src: SrcModule;
|
|
72
77
|
});
|
|
73
78
|
}
|
|
74
|
-
/** Parse a WESL file.
|
|
79
|
+
/** Parse a WESL file. */
|
|
75
80
|
declare function parseSrcModule(srcModule: SrcModule): WeslAST;
|
|
76
|
-
|
|
77
|
-
declare function syntheticWeslParseState(): WeslParseState;
|
|
78
|
-
/** @return a flattened form of the import tree for convenience in binding idents. */
|
|
81
|
+
/** @return flattened form of import tree for binding idents. */
|
|
79
82
|
declare function flatImports(ast: BindingAST, conditions?: Conditions): FlatImport[];
|
|
80
83
|
//#endregion
|
|
81
84
|
//#region src/Scope.d.ts
|
|
@@ -99,6 +102,8 @@ interface RefIdent extends IdentBase {
|
|
|
99
102
|
kind: "ref";
|
|
100
103
|
refersTo?: Ident;
|
|
101
104
|
std?: true;
|
|
105
|
+
/** True for identifiers in @if/@elif conditions. Binding skips these (for now). */
|
|
106
|
+
conditionRef?: true;
|
|
102
107
|
ast: WeslAST;
|
|
103
108
|
refIdentElem: RefIdentElem;
|
|
104
109
|
}
|
|
@@ -167,23 +172,36 @@ declare function childIdent(child: Scope | Ident): child is Ident;
|
|
|
167
172
|
//#endregion
|
|
168
173
|
//#region src/AbstractElems.d.ts
|
|
169
174
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* The parts of the source that need to analyze further in the linker
|
|
173
|
-
* are pulled out into these structures.
|
|
175
|
+
* AST structures describing 'interesting' parts of WESL source.
|
|
174
176
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* along with their containing element.
|
|
177
|
+
* Parts needing further analysis are pulled into these structures.
|
|
178
|
+
* Uninteresting parts are 'TextElem' nodes, copied to output WGSL.
|
|
178
179
|
*/
|
|
179
|
-
type AbstractElem = GrammarElem | SyntheticElem;
|
|
180
|
+
type AbstractElem = GrammarElem | SyntheticElem | ExpressionElem;
|
|
180
181
|
type GrammarElem = ContainerElem | TerminalElem;
|
|
181
|
-
type ContainerElem = AttributeElem | AliasElem | ConstAssertElem | ConstElem | UnknownExpressionElem | SimpleMemberRef | FnElem | TypedDeclElem | GlobalVarElem | LetElem | ModuleElem | OverrideElem | FnParamElem | StructElem | StructMemberElem | StuffElem | TypeRefElem | VarElem | StatementElem | SwitchClauseElem;
|
|
182
|
+
type ContainerElem = AttributeElem | AliasElem | ConstAssertElem | ConstElem | ContinuingElem | UnknownExpressionElem | SimpleMemberRef | FnElem | TypedDeclElem | GlobalVarElem | LetElem | ModuleElem | OverrideElem | FnParamElem | StructElem | StructMemberElem | StuffElem | TypeRefElem | VarElem | StatementElem | SwitchClauseElem;
|
|
183
|
+
/** Map from element kind string to element type, for type-safe element construction. */
|
|
184
|
+
type ElemKindMap = {
|
|
185
|
+
alias: AliasElem;
|
|
186
|
+
assert: ConstAssertElem;
|
|
187
|
+
const: ConstElem;
|
|
188
|
+
continuing: ContinuingElem;
|
|
189
|
+
gvar: GlobalVarElem;
|
|
190
|
+
let: LetElem;
|
|
191
|
+
member: StructMemberElem;
|
|
192
|
+
override: OverrideElem;
|
|
193
|
+
param: FnParamElem;
|
|
194
|
+
statement: StatementElem;
|
|
195
|
+
struct: StructElem;
|
|
196
|
+
"switch-clause": SwitchClauseElem;
|
|
197
|
+
type: TypeRefElem;
|
|
198
|
+
var: VarElem;
|
|
199
|
+
};
|
|
182
200
|
/** Inspired by https://github.com/wgsl-tooling-wg/wesl-rs/blob/3b2434eac1b2ebda9eb8bfb25f43d8600d819872/crates/wgsl-parse/src/syntax.rs#L364 */
|
|
183
|
-
type ExpressionElem = Literal |
|
|
201
|
+
type ExpressionElem = Literal | RefIdentElem | TypeRefElem | ParenthesizedExpression | ComponentExpression | ComponentMemberExpression | UnaryExpression | BinaryExpression | FunctionCallExpression;
|
|
184
202
|
type TerminalElem = DirectiveElem | DeclIdentElem | NameElem | RefIdentElem | TextElem | ImportElem;
|
|
185
203
|
type GlobalDeclarationElem = AliasElem | ConstElem | FnElem | GlobalVarElem | OverrideElem | StructElem;
|
|
186
|
-
type DeclarationElem = GlobalDeclarationElem | FnParamElem | VarElem;
|
|
204
|
+
type DeclarationElem = GlobalDeclarationElem | FnParamElem | VarElem | LetElem;
|
|
187
205
|
type ElemWithAttributes = Extract<AbstractElem, HasAttributes>;
|
|
188
206
|
interface AbstractElemBase {
|
|
189
207
|
kind: AbstractElem["kind"];
|
|
@@ -196,22 +214,12 @@ interface ElemWithContentsBase extends AbstractElemBase {
|
|
|
196
214
|
interface HasAttributes {
|
|
197
215
|
attributes?: AttributeElem[];
|
|
198
216
|
}
|
|
199
|
-
/**
|
|
200
|
-
* a raw bit of text in WESL source that's typically copied to the linked WGSL.
|
|
201
|
-
* e.g. a keyword like 'var'
|
|
202
|
-
* or a phrase we needn't analyze further like '@diagnostic(off,derivative_uniformity)'
|
|
203
|
-
*/
|
|
217
|
+
/** Raw text copied to linked WGSL (e.g., 'var' or '@diagnostic(off,derivative_uniformity)'). */
|
|
204
218
|
interface TextElem extends AbstractElemBase {
|
|
205
219
|
kind: "text";
|
|
206
220
|
srcModule: SrcModule;
|
|
207
221
|
}
|
|
208
|
-
/**
|
|
209
|
-
* e.g.
|
|
210
|
-
* - a struct member name
|
|
211
|
-
* - a diagnostic rule name
|
|
212
|
-
* - an enable-extension name
|
|
213
|
-
* - an interpolation sampling name
|
|
214
|
-
*/
|
|
222
|
+
/** A name that doesn't need to be an Ident (e.g., struct member, diagnostic rule). */
|
|
215
223
|
interface NameElem extends AbstractElemBase {
|
|
216
224
|
kind: "name";
|
|
217
225
|
name: string;
|
|
@@ -233,59 +241,47 @@ interface ImportElem extends AbstractElemBase, HasAttributes {
|
|
|
233
241
|
kind: "import";
|
|
234
242
|
imports: ImportStatement;
|
|
235
243
|
}
|
|
236
|
-
/**
|
|
237
|
-
* An import statement, which is tree shaped.
|
|
238
|
-
* `import foo::bar::{baz, cat as neko};
|
|
239
|
-
*/
|
|
244
|
+
/** Tree-shaped import statement: `import foo::bar::{baz, cat as neko};` */
|
|
240
245
|
interface ImportStatement {
|
|
241
246
|
kind: "import-statement";
|
|
242
247
|
segments: ImportSegment[];
|
|
243
248
|
finalSegment: ImportCollection | ImportItem;
|
|
244
249
|
}
|
|
245
|
-
/**
|
|
246
|
-
* A collection of import trees.
|
|
247
|
-
* `{baz, cat as neko}`
|
|
248
|
-
*/
|
|
250
|
+
/** A segment in an import path: `foo` in `foo::bar`. */
|
|
249
251
|
interface ImportSegment {
|
|
250
252
|
kind: "import-segment";
|
|
251
253
|
name: string;
|
|
252
254
|
}
|
|
253
|
-
/**
|
|
254
|
-
* A primitive segment in an import statement.
|
|
255
|
-
* `foo`
|
|
256
|
-
*/
|
|
255
|
+
/** A collection of import trees: `{baz, cat as neko}`. */
|
|
257
256
|
interface ImportCollection {
|
|
258
257
|
kind: "import-collection";
|
|
259
258
|
subtrees: ImportStatement[];
|
|
260
259
|
}
|
|
261
|
-
/**
|
|
262
|
-
* A renamed item at the end of an import statement.
|
|
263
|
-
* `cat as neko`
|
|
264
|
-
*/
|
|
260
|
+
/** A renamed item at the end of an import statement: `cat as neko`. */
|
|
265
261
|
interface ImportItem {
|
|
266
262
|
kind: "import-item";
|
|
267
263
|
name: string;
|
|
268
264
|
as?: string;
|
|
269
265
|
}
|
|
270
|
-
/**
|
|
266
|
+
/** Generated element produced after parsing and binding. */
|
|
271
267
|
interface SyntheticElem {
|
|
272
268
|
kind: "synthetic";
|
|
273
269
|
text: string;
|
|
274
270
|
}
|
|
275
|
-
/**
|
|
271
|
+
/** A declaration identifier with an optional type. */
|
|
276
272
|
interface TypedDeclElem extends ElemWithContentsBase {
|
|
277
273
|
kind: "typeDecl";
|
|
278
274
|
decl: DeclIdentElem;
|
|
279
275
|
typeRef?: TypeRefElem;
|
|
280
276
|
typeScope?: Scope;
|
|
281
277
|
}
|
|
282
|
-
/**
|
|
278
|
+
/** An alias statement. */
|
|
283
279
|
interface AliasElem extends ElemWithContentsBase, HasAttributes {
|
|
284
280
|
kind: "alias";
|
|
285
281
|
name: DeclIdentElem;
|
|
286
282
|
typeRef: TypeRefElem;
|
|
287
283
|
}
|
|
288
|
-
/**
|
|
284
|
+
/** An attribute like '@compute' or '@binding(0)'. */
|
|
289
285
|
interface AttributeElem extends ElemWithContentsBase {
|
|
290
286
|
kind: "attribute";
|
|
291
287
|
attribute: Attribute;
|
|
@@ -304,10 +300,11 @@ interface BuiltinAttribute {
|
|
|
304
300
|
kind: "@builtin";
|
|
305
301
|
param: NameElem;
|
|
306
302
|
}
|
|
303
|
+
type DiagnosticRule = [NameElem, NameElem | null];
|
|
307
304
|
interface DiagnosticAttribute {
|
|
308
305
|
kind: "@diagnostic";
|
|
309
306
|
severity: NameElem;
|
|
310
|
-
rule:
|
|
307
|
+
rule: DiagnosticRule;
|
|
311
308
|
}
|
|
312
309
|
interface IfAttribute {
|
|
313
310
|
kind: "@if";
|
|
@@ -320,71 +317,66 @@ interface ElifAttribute {
|
|
|
320
317
|
interface ElseAttribute {
|
|
321
318
|
kind: "@else";
|
|
322
319
|
}
|
|
323
|
-
|
|
320
|
+
type ConditionalAttribute = IfAttribute | ElifAttribute | ElseAttribute;
|
|
321
|
+
/** A const_assert statement. */
|
|
324
322
|
interface ConstAssertElem extends ElemWithContentsBase, HasAttributes {
|
|
325
323
|
kind: "assert";
|
|
326
324
|
}
|
|
327
|
-
/**
|
|
325
|
+
/** A const declaration. */
|
|
328
326
|
interface ConstElem extends ElemWithContentsBase, HasAttributes {
|
|
329
327
|
kind: "const";
|
|
330
328
|
name: TypedDeclElem;
|
|
331
329
|
}
|
|
332
|
-
/**
|
|
330
|
+
/** An expression without special handling, used in attribute parameters. */
|
|
333
331
|
interface UnknownExpressionElem extends ElemWithContentsBase {
|
|
334
332
|
kind: "expression";
|
|
335
333
|
}
|
|
336
|
-
/**
|
|
334
|
+
/** An expression that can be safely evaluated at compile time. */
|
|
337
335
|
interface TranslateTimeExpressionElem {
|
|
338
336
|
kind: "translate-time-expression";
|
|
339
337
|
expression: ExpressionElem;
|
|
340
338
|
span: Span;
|
|
341
339
|
}
|
|
342
|
-
/** A literal value in WESL source.
|
|
343
|
-
interface Literal {
|
|
340
|
+
/** A literal value (boolean or number) in WESL source. */
|
|
341
|
+
interface Literal extends AbstractElemBase {
|
|
344
342
|
kind: "literal";
|
|
345
343
|
value: string;
|
|
346
|
-
span: Span;
|
|
347
|
-
}
|
|
348
|
-
/** `words`s inside `@if` */
|
|
349
|
-
interface TranslateTimeFeature {
|
|
350
|
-
kind: "translate-time-feature";
|
|
351
|
-
name: string;
|
|
352
|
-
span: Span;
|
|
353
344
|
}
|
|
354
345
|
/** (expr) */
|
|
355
|
-
interface ParenthesizedExpression {
|
|
346
|
+
interface ParenthesizedExpression extends AbstractElemBase {
|
|
356
347
|
kind: "parenthesized-expression";
|
|
357
348
|
expression: ExpressionElem;
|
|
358
349
|
}
|
|
359
350
|
/** `foo[expr]` */
|
|
360
|
-
interface ComponentExpression {
|
|
351
|
+
interface ComponentExpression extends AbstractElemBase {
|
|
361
352
|
kind: "component-expression";
|
|
362
353
|
base: ExpressionElem;
|
|
363
354
|
access: ExpressionElem;
|
|
364
355
|
}
|
|
365
356
|
/** `foo.member` */
|
|
366
|
-
interface ComponentMemberExpression {
|
|
357
|
+
interface ComponentMemberExpression extends AbstractElemBase {
|
|
367
358
|
kind: "component-member-expression";
|
|
368
359
|
base: ExpressionElem;
|
|
369
360
|
access: NameElem;
|
|
370
361
|
}
|
|
371
362
|
/** `+foo` */
|
|
372
|
-
interface UnaryExpression {
|
|
363
|
+
interface UnaryExpression extends AbstractElemBase {
|
|
373
364
|
kind: "unary-expression";
|
|
374
365
|
operator: UnaryOperator;
|
|
375
366
|
expression: ExpressionElem;
|
|
376
367
|
}
|
|
377
368
|
/** `foo + bar` */
|
|
378
|
-
interface BinaryExpression {
|
|
369
|
+
interface BinaryExpression extends AbstractElemBase {
|
|
379
370
|
kind: "binary-expression";
|
|
380
371
|
operator: BinaryOperator;
|
|
381
372
|
left: ExpressionElem;
|
|
382
373
|
right: ExpressionElem;
|
|
383
374
|
}
|
|
384
|
-
/** `foo(arg, arg)` */
|
|
385
|
-
interface FunctionCallExpression {
|
|
375
|
+
/** `foo<T>(arg, arg)` */
|
|
376
|
+
interface FunctionCallExpression extends AbstractElemBase {
|
|
386
377
|
kind: "call-expression";
|
|
387
|
-
function: RefIdentElem;
|
|
378
|
+
function: RefIdentElem | TypeRefElem;
|
|
379
|
+
templateArgs?: TypeTemplateParameter[];
|
|
388
380
|
arguments: ExpressionElem[];
|
|
389
381
|
}
|
|
390
382
|
interface UnaryOperator {
|
|
@@ -413,7 +405,7 @@ interface RequiresDirective {
|
|
|
413
405
|
kind: "requires";
|
|
414
406
|
extensions: NameElem[];
|
|
415
407
|
}
|
|
416
|
-
/**
|
|
408
|
+
/** A function declaration. */
|
|
417
409
|
interface FnElem extends ElemWithContentsBase, HasAttributes {
|
|
418
410
|
kind: "fn";
|
|
419
411
|
name: DeclIdentElem;
|
|
@@ -422,64 +414,63 @@ interface FnElem extends ElemWithContentsBase, HasAttributes {
|
|
|
422
414
|
returnAttributes?: AttributeElem[];
|
|
423
415
|
returnType?: TypeRefElem;
|
|
424
416
|
}
|
|
425
|
-
/**
|
|
417
|
+
/** A global variable declaration (at the root level). */
|
|
426
418
|
interface GlobalVarElem extends ElemWithContentsBase, HasAttributes {
|
|
427
419
|
kind: "gvar";
|
|
428
420
|
name: TypedDeclElem;
|
|
429
421
|
}
|
|
430
|
-
/**
|
|
422
|
+
/** An entire file. */
|
|
431
423
|
interface ModuleElem extends ElemWithContentsBase {
|
|
432
424
|
kind: "module";
|
|
433
425
|
}
|
|
434
|
-
/**
|
|
426
|
+
/** An override declaration. */
|
|
435
427
|
interface OverrideElem extends ElemWithContentsBase, HasAttributes {
|
|
436
428
|
kind: "override";
|
|
437
429
|
name: TypedDeclElem;
|
|
438
430
|
}
|
|
439
|
-
/**
|
|
431
|
+
/** A parameter in a function declaration. */
|
|
440
432
|
interface FnParamElem extends ElemWithContentsBase, HasAttributes {
|
|
441
433
|
kind: "param";
|
|
442
434
|
name: TypedDeclElem;
|
|
443
435
|
}
|
|
444
|
-
/**
|
|
445
|
-
* (used for transforming refs to binding structs) */
|
|
436
|
+
/** Simple struct references like `myStruct.bar` (for binding struct transforms). */
|
|
446
437
|
interface SimpleMemberRef extends ElemWithContentsBase {
|
|
447
438
|
kind: "memberRef";
|
|
448
439
|
name: RefIdentElem;
|
|
449
440
|
member: NameElem;
|
|
450
441
|
extraComponents?: StuffElem;
|
|
451
442
|
}
|
|
452
|
-
/**
|
|
443
|
+
/** A struct declaration. */
|
|
453
444
|
interface StructElem extends ElemWithContentsBase, HasAttributes {
|
|
454
445
|
kind: "struct";
|
|
455
446
|
name: DeclIdentElem;
|
|
456
447
|
members: StructMemberElem[];
|
|
457
448
|
bindingStruct?: true;
|
|
458
449
|
}
|
|
459
|
-
/**
|
|
450
|
+
/** Generic container of other elements. */
|
|
460
451
|
interface StuffElem extends ElemWithContentsBase {
|
|
461
452
|
kind: "stuff";
|
|
462
453
|
}
|
|
463
|
-
/**
|
|
454
|
+
/** A struct declaration marked as a binding struct. */
|
|
464
455
|
interface BindingStructElem extends StructElem {
|
|
465
456
|
bindingStruct: true;
|
|
466
457
|
entryFn?: FnElem;
|
|
467
458
|
}
|
|
468
|
-
/**
|
|
459
|
+
/** A member of a struct declaration. */
|
|
469
460
|
interface StructMemberElem extends ElemWithContentsBase, HasAttributes {
|
|
470
461
|
kind: "member";
|
|
471
462
|
name: NameElem;
|
|
472
463
|
typeRef: TypeRefElem;
|
|
473
464
|
mangledVarName?: string;
|
|
474
465
|
}
|
|
475
|
-
type TypeTemplateParameter =
|
|
476
|
-
/**
|
|
466
|
+
type TypeTemplateParameter = ExpressionElem;
|
|
467
|
+
/** A type reference like 'f32', 'MyStruct', or 'ptr<storage, array<f32>, read_only>'. */
|
|
477
468
|
interface TypeRefElem extends ElemWithContentsBase {
|
|
478
469
|
kind: "type";
|
|
479
470
|
name: RefIdent;
|
|
480
471
|
templateParams?: TypeTemplateParameter[];
|
|
481
472
|
}
|
|
482
|
-
/**
|
|
473
|
+
/** A variable declaration. */
|
|
483
474
|
interface VarElem extends ElemWithContentsBase, HasAttributes {
|
|
484
475
|
kind: "var";
|
|
485
476
|
name: TypedDeclElem;
|
|
@@ -491,10 +482,76 @@ interface LetElem extends ElemWithContentsBase, HasAttributes {
|
|
|
491
482
|
interface StatementElem extends ElemWithContentsBase, HasAttributes {
|
|
492
483
|
kind: "statement";
|
|
493
484
|
}
|
|
485
|
+
interface ContinuingElem extends ElemWithContentsBase, HasAttributes {
|
|
486
|
+
kind: "continuing";
|
|
487
|
+
}
|
|
488
|
+
/** Statement or continuing - used in loop body parsing. */
|
|
489
|
+
type BlockStatement = StatementElem | ContinuingElem;
|
|
494
490
|
interface SwitchClauseElem extends ElemWithContentsBase, HasAttributes {
|
|
495
491
|
kind: "switch-clause";
|
|
496
492
|
}
|
|
497
493
|
//#endregion
|
|
494
|
+
//#region src/SrcMap.d.ts
|
|
495
|
+
/** A source map file, and a path for debug purposes. */
|
|
496
|
+
interface SrcWithPath {
|
|
497
|
+
/** User friendly path */
|
|
498
|
+
path?: string;
|
|
499
|
+
text: string;
|
|
500
|
+
}
|
|
501
|
+
interface SrcMapEntry {
|
|
502
|
+
src: SrcWithPath;
|
|
503
|
+
srcStart: number;
|
|
504
|
+
srcEnd: number;
|
|
505
|
+
destStart: number;
|
|
506
|
+
destEnd: number;
|
|
507
|
+
}
|
|
508
|
+
interface SrcPosition {
|
|
509
|
+
src: SrcWithPath;
|
|
510
|
+
position: number;
|
|
511
|
+
}
|
|
512
|
+
/** map text ranges in multiple src texts to a single dest text */
|
|
513
|
+
declare class SrcMap {
|
|
514
|
+
entries: SrcMapEntry[];
|
|
515
|
+
dest: SrcWithPath;
|
|
516
|
+
constructor(dest: SrcWithPath, entries?: SrcMapEntry[]);
|
|
517
|
+
/** add a new mapping from src to dest ranges (must be non-overlapping in destination) */
|
|
518
|
+
addEntries(newEntries: SrcMapEntry[]): void;
|
|
519
|
+
/** given positions in the dest string, return corresponding positions in the src strings */
|
|
520
|
+
mapPositions(...positions: number[]): SrcPosition[];
|
|
521
|
+
/** internally compress adjacent entries where possible */
|
|
522
|
+
compact(): void;
|
|
523
|
+
/** sort in destination order */
|
|
524
|
+
sort(): void;
|
|
525
|
+
/**
|
|
526
|
+
* This SrcMap's destination is a src for the other srcmap,
|
|
527
|
+
* so combine the two and return the result.
|
|
528
|
+
*/
|
|
529
|
+
merge(other: SrcMap): SrcMap;
|
|
530
|
+
/** @return the source position corresponding to a provided destination position */
|
|
531
|
+
destToSrc(destPos: number): SrcPosition;
|
|
532
|
+
}
|
|
533
|
+
/** Incrementally append to a string, tracking source references */
|
|
534
|
+
declare class SrcMapBuilder {
|
|
535
|
+
#private;
|
|
536
|
+
source: SrcWithPath;
|
|
537
|
+
constructor(source: SrcWithPath);
|
|
538
|
+
/** append a string fragment to the destination string */
|
|
539
|
+
add(fragment: string, srcStart: number, srcEnd: number): void;
|
|
540
|
+
/**
|
|
541
|
+
* Append a fragment to the destination string,
|
|
542
|
+
* mapping source to the previous,
|
|
543
|
+
* and guessing that the source fragment is just as long as the dest fragment.
|
|
544
|
+
*/
|
|
545
|
+
appendNext(fragment: string): void;
|
|
546
|
+
addSynthetic(fragment: string, syntheticSource: string, srcStart: number, srcEnd: number): void;
|
|
547
|
+
/** append a synthetic newline, mapped to previous source location */
|
|
548
|
+
addNl(): void;
|
|
549
|
+
/** copy a string fragment from the src to the destination string */
|
|
550
|
+
addCopy(srcStart: number, srcEnd: number): void;
|
|
551
|
+
/** return a SrcMap */
|
|
552
|
+
static build(builders: SrcMapBuilder[]): SrcMap;
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
498
555
|
//#region src/WeslDevice.d.ts
|
|
499
556
|
/**
|
|
500
557
|
* A {@link GPUDevice} with extensions for WESL. Created with {@link makeWeslDevice}.
|
|
@@ -629,26 +686,14 @@ interface WeslBundle {
|
|
|
629
686
|
}
|
|
630
687
|
//#endregion
|
|
631
688
|
//#region src/ModuleResolver.d.ts
|
|
632
|
-
/**
|
|
633
|
-
* Resolves module paths to parsed ASTs.
|
|
634
|
-
*
|
|
635
|
-
* Implementations may cache ASTs or load them lazily.
|
|
636
|
-
*/
|
|
689
|
+
/** Resolves module paths to parsed ASTs. Implementations may cache or load lazily. */
|
|
637
690
|
interface ModuleResolver {
|
|
638
|
-
/**
|
|
639
|
-
* Resolve a module path to its parsed AST.
|
|
640
|
-
*
|
|
641
|
-
* @param modulePath - Module path in :: format (e.g., "package::foo::bar")
|
|
642
|
-
* @returns Parsed AST or undefined if module not found
|
|
643
|
-
*/
|
|
691
|
+
/** Resolve module path (e.g., "package::foo::bar") to AST, or undefined if not found. */
|
|
644
692
|
resolveModule(modulePath: string): WeslAST | undefined;
|
|
645
693
|
}
|
|
646
694
|
/** Module resolver that supports batch enumeration of all modules. */
|
|
647
695
|
interface BatchModuleResolver extends ModuleResolver {
|
|
648
|
-
/**
|
|
649
|
-
* Return all modules, parsing them on-demand if needed.
|
|
650
|
-
* Implementations should ensure all sources are parsed before returning.
|
|
651
|
-
*/
|
|
696
|
+
/** Return all modules, parsing them on-demand if needed. */
|
|
652
697
|
allModules(): Iterable<[string, WeslAST]>;
|
|
653
698
|
}
|
|
654
699
|
interface RecordResolverOptions {
|
|
@@ -666,9 +711,10 @@ declare class RecordResolver implements BatchModuleResolver {
|
|
|
666
711
|
constructor(sources: Record<string, string>, options?: RecordResolverOptions);
|
|
667
712
|
resolveModule(modulePath: string): WeslAST | undefined;
|
|
668
713
|
private findSource;
|
|
714
|
+
/** Convert module path to file path, or undefined if not local. */
|
|
669
715
|
private moduleToFilePath;
|
|
670
716
|
private modulePathToDebugPath;
|
|
671
|
-
/**
|
|
717
|
+
/** Parse all modules and return entries. */
|
|
672
718
|
allModules(): Iterable<[string, WeslAST]>;
|
|
673
719
|
}
|
|
674
720
|
/** Composite resolver that tries each resolver in order until one succeeds. */
|
|
@@ -689,7 +735,7 @@ declare class BundleResolver implements ModuleResolver {
|
|
|
689
735
|
private moduleToFilePath;
|
|
690
736
|
private modulePathToDebugPath;
|
|
691
737
|
}
|
|
692
|
-
/** Convert file path to module path (e.g., "foo/bar.wesl"
|
|
738
|
+
/** Convert file path to module path (e.g., "foo/bar.wesl" to "package::foo::bar"). */
|
|
693
739
|
declare function fileToModulePath(filePath: string, packageName: string, treatLibAsRoot: boolean): string;
|
|
694
740
|
//#endregion
|
|
695
741
|
//#region src/Linker.d.ts
|
|
@@ -786,132 +832,87 @@ declare function normalizeModuleName(name: string): string;
|
|
|
786
832
|
//#endregion
|
|
787
833
|
//#region src/BindIdents.d.ts
|
|
788
834
|
/**
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
processed ident, along with a link to parent liveDecls for their current decl visibility.
|
|
809
|
-
|
|
810
|
-
@if/@else Handling:
|
|
811
|
-
The binding phase respects conditional compilation by tracking @else validity state as it
|
|
812
|
-
processes sibling scopes. This prevents references from within filtered @else blocks from
|
|
813
|
-
pulling in declarations that won't be emitted. The algorithm mirrors the emission phase's
|
|
814
|
-
filterValidElements approach but operates on scopes rather than elements.
|
|
815
|
-
*/
|
|
816
|
-
/** results returned from binding pass */
|
|
835
|
+
* BindIdents pass: link reference identifiers to declarations.
|
|
836
|
+
*
|
|
837
|
+
* Goals:
|
|
838
|
+
* - Link reference idents to declaration idents
|
|
839
|
+
* - Collect used declarations (to emit in link)
|
|
840
|
+
* - Create mangled names for globals to avoid conflicts
|
|
841
|
+
*
|
|
842
|
+
* Algorithm:
|
|
843
|
+
* - Recursive depth-first walk of scope tree (not syntax tree)
|
|
844
|
+
* - For each ref: search current scope, then up to parent scopes
|
|
845
|
+
* - If no local match: check import statements for external matches
|
|
846
|
+
* - For found global decls: mangle name to be unique, collect for emission
|
|
847
|
+
*
|
|
848
|
+
* LiveDecls: tracks visible declarations at the current position, with parent links.
|
|
849
|
+
*
|
|
850
|
+
* @if/@else: respects conditional compilation by tracking @else validity state,
|
|
851
|
+
* mirroring the emission phase's filterValidElements but on scopes.
|
|
852
|
+
*/
|
|
853
|
+
/** Results returned from binding pass. */
|
|
817
854
|
interface BindResults {
|
|
818
|
-
/**
|
|
855
|
+
/** Root level names (including mangled names from conflicts). */
|
|
819
856
|
globalNames: Set<string>;
|
|
820
|
-
/**
|
|
857
|
+
/** Global declarations referenced (to emit in link). */
|
|
821
858
|
decls: DeclIdent[];
|
|
822
|
-
/**
|
|
823
|
-
* (e.g. for adding module level const_assert statements) */
|
|
859
|
+
/** Additional global statements to emit (e.g., const_assert). */
|
|
824
860
|
newStatements: EmittableElem[];
|
|
825
|
-
/** if accumulateUnbound is true
|
|
861
|
+
/** Unbound module paths (only if accumulateUnbound is true). */
|
|
826
862
|
unbound?: string[][];
|
|
827
863
|
}
|
|
828
|
-
/**
|
|
864
|
+
/** An element that can be directly emitted into the linked result. */
|
|
829
865
|
interface EmittableElem {
|
|
830
866
|
srcModule: SrcModule;
|
|
831
867
|
elem: AbstractElem;
|
|
832
868
|
}
|
|
833
|
-
/**
|
|
869
|
+
/** Virtual package generated by code generation function. */
|
|
834
870
|
interface VirtualLibrary {
|
|
835
|
-
/**
|
|
871
|
+
/** Function to generate the module. */
|
|
836
872
|
fn: VirtualLibraryFn;
|
|
837
|
-
/**
|
|
873
|
+
/** Parsed AST for the module (constructed lazily). */
|
|
838
874
|
ast?: WeslAST;
|
|
839
875
|
}
|
|
840
|
-
/**
|
|
876
|
+
/** Key is virtual module name. */
|
|
841
877
|
type VirtualLibrarySet = Record<string, VirtualLibrary>;
|
|
842
878
|
interface BindIdentsParams extends Pick<LinkRegistryParams, "resolver" | "conditions" | "mangler"> {
|
|
843
879
|
rootAst: WeslAST;
|
|
844
880
|
virtuals?: VirtualLibrarySet;
|
|
845
|
-
/**
|
|
846
|
-
* a BindResults.unbound. */
|
|
881
|
+
/** If true, accumulate unbound identifiers into BindResults.unbound instead of throwing. */
|
|
847
882
|
accumulateUnbound?: true;
|
|
848
883
|
}
|
|
849
|
-
/**
|
|
850
|
-
* Bind active reference idents to declaration Idents by mutating the refersTo: field
|
|
851
|
-
* Also in this pass, set the mangledName: field for all active global declaration idents.
|
|
852
|
-
*
|
|
853
|
-
* @param parsed
|
|
854
|
-
* @param conditions only bind to/from idents that are valid with the current condition set
|
|
855
|
-
* @return any new declaration elements found (they will need to be emitted)
|
|
856
|
-
*/
|
|
884
|
+
/** Bind ref idents to declarations and mangle global declaration names. */
|
|
857
885
|
declare function bindIdents(params: BindIdentsParams): BindResults;
|
|
858
|
-
/**
|
|
859
|
-
* Find all conditionally valid declarations at the root level.
|
|
860
|
-
* Declarations are either directly in the root scope or in conditionally valid partial scopes.
|
|
861
|
-
*
|
|
862
|
-
* This function tracks @else state to ensure that declarations in @else blocks are only
|
|
863
|
-
* included when the corresponding @if block is invalid. This is essential for preventing
|
|
864
|
-
* unused declarations from being included in the output.
|
|
865
|
-
*
|
|
866
|
-
* Results are cached on the root scope's _validRootDecls field.
|
|
867
|
-
* Used both for binding and for publicDecl() lookups.
|
|
868
|
-
*
|
|
869
|
-
* @param rootScope The root scope to search
|
|
870
|
-
* @param conditions Current conditional compilation settings
|
|
871
|
-
* @return Array of valid declaration identifiers
|
|
872
|
-
*/
|
|
886
|
+
/** Find all conditionally valid declarations at the root level. */
|
|
873
887
|
declare function findValidRootDecls(rootScope: Scope, conditions: Conditions): DeclIdent[];
|
|
874
|
-
/** Find a public declaration with the given original name */
|
|
888
|
+
/** Find a public declaration with the given original name. */
|
|
875
889
|
declare function publicDecl(scope: Scope, name: string, conditions: Conditions): DeclIdent | undefined;
|
|
876
|
-
/**
|
|
877
|
-
declare function isGlobal(declIdent: DeclIdent): boolean;
|
|
878
|
-
/** state used during the recursive scope tree walk to bind references to declarations */
|
|
890
|
+
/** State used during the recursive scope tree walk to bind references to declarations. */
|
|
879
891
|
interface BindContext {
|
|
880
892
|
resolver: ModuleResolver;
|
|
881
|
-
conditions:
|
|
882
|
-
/**
|
|
893
|
+
conditions: Conditions;
|
|
894
|
+
/** Decl idents discovered so far (to avoid re-traversing). */
|
|
883
895
|
knownDecls: Set<DeclIdent>;
|
|
884
|
-
/**
|
|
896
|
+
/** Scopes already processed (avoid duplicate work). */
|
|
885
897
|
foundScopes: Set<Scope>;
|
|
886
|
-
/**
|
|
898
|
+
/** Root level names used so far (enables manglers to pick unique names). */
|
|
887
899
|
globalNames: Set<string>;
|
|
888
|
-
/**
|
|
900
|
+
/** Additional global statements to emit (indexed by elem for uniqueness). */
|
|
889
901
|
globalStatements: Map<AbstractElem, EmittableElem>;
|
|
890
|
-
/**
|
|
902
|
+
/** Construct unique identifier names for global declarations. */
|
|
891
903
|
mangler: ManglerFn;
|
|
892
904
|
virtuals?: VirtualLibrarySet;
|
|
893
|
-
/**
|
|
905
|
+
/** Unbound identifiers if accumulateUnbound is true. */
|
|
894
906
|
unbound?: string[][];
|
|
895
|
-
/**
|
|
907
|
+
/** Don't follow references from declarations (for library dependency detection). */
|
|
896
908
|
dontFollowDecls?: boolean;
|
|
897
909
|
}
|
|
898
910
|
/**
|
|
899
|
-
* Recursively bind references to declarations in this scope and
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
* IMPORTANT: This function tracks @else state while traversing sibling scopes.
|
|
904
|
-
* When an @if scope is processed, its validity determines whether the following
|
|
905
|
-
* @else scope should be considered valid. This ensures that references from
|
|
906
|
-
* filtered @else blocks don't pull in unused declarations.
|
|
907
|
-
*
|
|
908
|
-
* @return any new declarations found
|
|
909
|
-
* @param liveDecls current set of live declaration in this scope
|
|
910
|
-
* (empty when traversing to a new scope, possibly non-empty for a partial scope)
|
|
911
|
-
* @param isRoot liveDecls refers to a prepopulated root scope
|
|
912
|
-
* (root scope declarations may appear in any order)
|
|
911
|
+
* Recursively bind references to declarations in this scope and child scopes.
|
|
912
|
+
* Tracks @else state to ensure filtered @else blocks don't pull in unused declarations.
|
|
913
|
+
* @return new declarations found
|
|
913
914
|
*/
|
|
914
|
-
declare function bindIdentsRecursive(scope: Scope, bindContext: BindContext, liveDecls: LiveDecls
|
|
915
|
+
declare function bindIdentsRecursive(scope: Scope, bindContext: BindContext, liveDecls: LiveDecls): DeclIdent[];
|
|
915
916
|
//#endregion
|
|
916
917
|
//#region src/debug/ASTtoString.d.ts
|
|
917
918
|
declare function astToString(elem: AbstractElem, indent?: number): string;
|
|
@@ -982,6 +983,22 @@ declare function sanitizePackageName(npmName: string): string;
|
|
|
982
983
|
*/
|
|
983
984
|
declare function npmNameVariations(sanitizedPath: string): Generator<string>;
|
|
984
985
|
//#endregion
|
|
986
|
+
//#region src/Logging.d.ts
|
|
987
|
+
/** base logger (can be overridden to a capturing logger for tests) */
|
|
988
|
+
declare let log: (...data: any[]) => void;
|
|
989
|
+
/** enable debug assertions and verbose error messages (set false via bundler for smaller builds) */
|
|
990
|
+
declare const debug = true;
|
|
991
|
+
/** enable user-facing validation like operator binding rules (set false via bundler for smaller builds) */
|
|
992
|
+
declare const validation = true;
|
|
993
|
+
/** use temporary logger for async tests */
|
|
994
|
+
declare function withLoggerAsync<T>(logFn: typeof console.log, fn: () => Promise<T>): Promise<T>;
|
|
995
|
+
/**
|
|
996
|
+
* Log a message along with the source line and a caret indicating the error position.
|
|
997
|
+
* @param pos is the position in the source string, or if src is a SrcMap,
|
|
998
|
+
* then pos is the position in the dest (e.g. preprocessed) text
|
|
999
|
+
*/
|
|
1000
|
+
declare function srcLog(src: string | SrcMap, pos: number | [number, number], ...msgs: any[]): void;
|
|
1001
|
+
//#endregion
|
|
985
1002
|
//#region src/ModulePathUtil.d.ts
|
|
986
1003
|
/** WESL module path utilities for converting between :: and / separators. */
|
|
987
1004
|
/**
|
|
@@ -1015,6 +1032,34 @@ declare function normalize(path: string): string;
|
|
|
1015
1032
|
* e.g. /foo/bar.wgsl => /foo/bar */
|
|
1016
1033
|
declare function noSuffix(path: string): string;
|
|
1017
1034
|
//#endregion
|
|
1035
|
+
//#region src/Stream.d.ts
|
|
1036
|
+
/**
|
|
1037
|
+
* Interface for a tokenizer. Returns a "next token", and can be reset to
|
|
1038
|
+
* previously saved positions (checkpoints).
|
|
1039
|
+
*/
|
|
1040
|
+
interface Stream<T extends Token> {
|
|
1041
|
+
/** Returns the current position */
|
|
1042
|
+
checkpoint(): number;
|
|
1043
|
+
/** Restores a position */
|
|
1044
|
+
reset(position: number): void;
|
|
1045
|
+
/**
|
|
1046
|
+
* Returns the next token, or `null` if the end of the stream has been reached.
|
|
1047
|
+
* Always leaves `checkpoint` right after the token.
|
|
1048
|
+
*/
|
|
1049
|
+
nextToken(): T | null;
|
|
1050
|
+
/** src text */
|
|
1051
|
+
src: string;
|
|
1052
|
+
}
|
|
1053
|
+
/** A text token */
|
|
1054
|
+
interface Token {
|
|
1055
|
+
kind: string;
|
|
1056
|
+
text: string;
|
|
1057
|
+
span: Span;
|
|
1058
|
+
}
|
|
1059
|
+
interface TypedToken<Kind extends string> extends Token {
|
|
1060
|
+
kind: Kind;
|
|
1061
|
+
}
|
|
1062
|
+
//#endregion
|
|
1018
1063
|
//#region src/parse/WeslStream.d.ts
|
|
1019
1064
|
type WeslTokenKind = "word" | "keyword" | "number" | "symbol";
|
|
1020
1065
|
type WeslToken<Kind extends WeslTokenKind = WeslTokenKind> = TypedToken<Kind>;
|
|
@@ -1023,13 +1068,22 @@ declare class WeslStream implements Stream<WeslToken> {
|
|
|
1023
1068
|
private stream;
|
|
1024
1069
|
/** New line */
|
|
1025
1070
|
private eolPattern;
|
|
1026
|
-
/** Block comments */
|
|
1027
1071
|
private blockCommentPattern;
|
|
1028
1072
|
src: string;
|
|
1029
1073
|
constructor(src: string);
|
|
1030
1074
|
checkpoint(): number;
|
|
1031
1075
|
reset(position: number): void;
|
|
1032
1076
|
nextToken(): WeslToken | null;
|
|
1077
|
+
/** Peek at the next token without consuming it */
|
|
1078
|
+
peek(): WeslToken | null;
|
|
1079
|
+
/** Consume token if text matches, otherwise leave position unchanged */
|
|
1080
|
+
matchText(text: string): WeslToken | null;
|
|
1081
|
+
/** Consume token if kind matches (and optionally text), otherwise leave position unchanged */
|
|
1082
|
+
matchKind<K extends WeslTokenKind>(kind: K, text?: string): WeslToken<K> | null;
|
|
1083
|
+
/** Consume token if predicate matches, otherwise leave position unchanged */
|
|
1084
|
+
nextIf(predicate: (token: WeslToken) => boolean): WeslToken | null;
|
|
1085
|
+
/** Match a sequence of tokens by text. Resets and returns null if any fails. */
|
|
1086
|
+
matchSequence(...texts: string[]): WeslToken[] | null;
|
|
1033
1087
|
private skipToEol;
|
|
1034
1088
|
private skipBlockComment;
|
|
1035
1089
|
/**
|
|
@@ -1043,12 +1097,12 @@ declare class WeslStream implements Stream<WeslToken> {
|
|
|
1043
1097
|
nextTemplateEndToken(): (WeslToken & {
|
|
1044
1098
|
kind: "symbol";
|
|
1045
1099
|
}) | null;
|
|
1046
|
-
isTemplateStart
|
|
1100
|
+
private isTemplateStart;
|
|
1047
1101
|
/**
|
|
1048
1102
|
* Call this after consuming an opening bracket.
|
|
1049
1103
|
* Skips until a closing bracket. This also consumes the closing bracket.
|
|
1050
1104
|
*/
|
|
1051
|
-
skipBracketsTo
|
|
1105
|
+
private skipBracketsTo;
|
|
1052
1106
|
}
|
|
1053
1107
|
//#endregion
|
|
1054
1108
|
//#region src/TransformBindingStructs.d.ts
|
|
@@ -1146,4 +1200,4 @@ declare function offsetToLineNumber(offset: number, text: string): [lineNum: num
|
|
|
1146
1200
|
*/
|
|
1147
1201
|
declare function errorHighlight(source: string, span: Span): [string, string];
|
|
1148
1202
|
//#endregion
|
|
1149
|
-
export { AbstractElem, AbstractElemBase, AliasElem, Attribute, AttributeElem, BatchModuleResolver, BinaryExpression, BinaryOperator, BindIdentsParams, BindResults, BindingAST, BindingStructElem, BoundAndTransformed, BuiltinAttribute, BundleResolver, ComponentExpression, ComponentMemberExpression, CompositeResolver, Conditions, ConstAssertElem, ConstElem, ContainerElem, DeclIdent, DeclIdentElem, DeclarationElem, DiagnosticAttribute, DiagnosticDirective, DirectiveElem, DirectiveVariant, ElemWithAttributes, ElemWithContentsBase, ElifAttribute, ElseAttribute, EmittableElem, EnableDirective, ExpressionElem, ExtendedGPUValidationError, FnElem, FnParamElem, FunctionCallExpression, GlobalDeclarationElem, GlobalVarElem, GrammarElem, HasAttributes, Ident, IfAttribute, ImportCollection, ImportElem, ImportItem, ImportSegment, ImportStatement, InterpolateAttribute, LetElem, LexicalScope, LinkConfig, LinkParams, LinkRegistryParams, LinkedWesl, LinkerTransform, Literal, LiveDecls, ManglerFn, ModuleElem, ModuleResolver, NameElem, OverrideElem, ParenthesizedExpression, PartialScope, RecordResolver, RecordResolverOptions, RefIdent, RefIdentElem, RequiresDirective, Scope, SimpleMemberRef, SrcModule, StableState, StandardAttribute, StatementElem, StructElem, StructMemberElem, StuffElem, SwitchClauseElem, SyntheticElem, TerminalElem, TextElem, TransformedAST, TranslateTimeExpressionElem,
|
|
1203
|
+
export { AbstractElem, AbstractElemBase, AliasElem, Attribute, AttributeElem, BatchModuleResolver, BinaryExpression, BinaryOperator, BindIdentsParams, BindResults, BindingAST, BindingStructElem, BlockStatement, BoundAndTransformed, BuiltinAttribute, BundleResolver, ComponentExpression, ComponentMemberExpression, CompositeResolver, ConditionalAttribute, Conditions, ConstAssertElem, ConstElem, ContainerElem, ContinuingElem, DeclIdent, DeclIdentElem, DeclarationElem, DiagnosticAttribute, DiagnosticDirective, DiagnosticRule, DirectiveElem, DirectiveVariant, ElemKindMap, ElemWithAttributes, ElemWithContentsBase, ElifAttribute, ElseAttribute, EmittableElem, EnableDirective, ExpressionElem, ExtendedGPUValidationError, FnElem, FnParamElem, FunctionCallExpression, GlobalDeclarationElem, GlobalVarElem, GrammarElem, HasAttributes, Ident, IfAttribute, ImportCollection, ImportElem, ImportItem, ImportSegment, ImportStatement, InterpolateAttribute, LetElem, LexicalScope, LinkConfig, LinkParams, LinkRegistryParams, LinkedWesl, LinkerTransform, Literal, LiveDecls, ManglerFn, ModuleElem, ModuleResolver, NameElem, OpenElem, OverrideElem, ParenthesizedExpression, ParseError, PartialScope, RecordResolver, RecordResolverOptions, RefIdent, RefIdentElem, RequiresDirective, Scope, SimpleMemberRef, Span, SrcMap, SrcMapBuilder, SrcMapEntry, SrcModule, SrcPosition, SrcWithPath, StableState, StandardAttribute, StatementElem, StructElem, StructMemberElem, StuffElem, SwitchClauseElem, SyntheticElem, TerminalElem, TextElem, TransformedAST, TranslateTimeExpressionElem, TypeRefElem, TypeTemplateParameter, TypedDeclElem, UnaryExpression, UnaryOperator, UnknownExpressionElem, VarElem, VirtualLibrary, VirtualLibraryFn, VirtualLibrarySet, WeslAST, WeslBundle, WeslDevice, WeslGPUCompilationInfo, WeslGPUCompilationMessage, WeslJsPlugin, WeslParseContext, WeslParseError, WeslParseState, WeslStream, _linkSync, astToString, attributeToString, bindAndTransform, bindIdents, bindIdentsRecursive, bindingStructsPlugin, childIdent, childScope, containsScope, debug, debugContentsToString, emptyScope, errorHighlight, fileToModulePath, filterMap, findMap, findRefsToBindingStructs, findUnboundIdents, findValidRootDecls, flatImports, groupBy, grouped, identToString, last, lengthPrefixMangle, link, linkRegistry, liveDeclsToString, log, lowerBindingStructs, makeLiveDecls, makeWeslDevice, mapForward, mapValues, markBindingStructs, markEntryTypes, mergeScope, minimalMangle, minimallyMangledName, modulePartsToRelativePath, moduleToRelativePath, multiKeySet, nextIdentId, noSuffix, normalize, normalizeDebugRoot, normalizeModuleName, npmNameVariations, offsetToLineNumber, overlapTail, parseSrcModule, partition, publicDecl, replaceWords, requestWeslDevice, resetScopeIds, resolveSuper, sanitizePackageName, scan, scopeToString, scopeToStringLong, srcLog, transformBindingReference, transformBindingStruct, underscoreMangle, validation, withLoggerAsync };
|