wesl 0.6.0-pre2
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.cjs +2617 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2617 -0
- package/dist/index.js.map +1 -0
- package/dist/linker/packages/linker/src/AbstractElems.d.ts +104 -0
- package/dist/linker/packages/linker/src/BindIdents.d.ts +16 -0
- package/dist/linker/packages/linker/src/CommentsGrammar.d.ts +6 -0
- package/dist/linker/packages/linker/src/FlattenTreeImport.d.ts +11 -0
- package/dist/linker/packages/linker/src/ImportGrammar.d.ts +13 -0
- package/dist/linker/packages/linker/src/ImportTree.d.ts +17 -0
- package/dist/linker/packages/linker/src/Linker.d.ts +26 -0
- package/dist/linker/packages/linker/src/LowerAndEmit.d.ts +25 -0
- package/dist/linker/packages/linker/src/ParseWESL.d.ts +36 -0
- package/dist/linker/packages/linker/src/ParsedRegistry.d.ts +26 -0
- package/dist/linker/packages/linker/src/PathUtil.d.ts +9 -0
- package/dist/linker/packages/linker/src/Scope.d.ts +55 -0
- package/dist/linker/packages/linker/src/Slicer.d.ts +26 -0
- package/dist/linker/packages/linker/src/StandardTypes.d.ts +6 -0
- package/dist/linker/packages/linker/src/Util.d.ts +26 -0
- package/dist/linker/packages/linker/src/WESLCollect.d.ts +29 -0
- package/dist/linker/packages/linker/src/WESLGrammar.d.ts +23 -0
- package/dist/linker/packages/linker/src/WESLTokens.d.ts +42 -0
- package/dist/linker/packages/linker/src/WgslBundle.d.ts +13 -0
- package/dist/linker/packages/linker/src/debug/ASTtoString.d.ts +3 -0
- package/dist/linker/packages/linker/src/debug/ImportToString.d.ts +2 -0
- package/dist/linker/packages/linker/src/debug/LineWrapper.d.ts +21 -0
- package/dist/linker/packages/linker/src/debug/ScopeToString.d.ts +4 -0
- package/dist/linker/packages/linker/src/index.d.ts +7 -0
- package/dist/linker/packages/linker/src/test/ErrorLogging.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/Expression.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/FlattenTreeImport.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/ImportCases.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/ImportSyntaxCases.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/LinkGlob.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/LinkPackage.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/Linker.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/MatchWgslD.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/ParseComments.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/ParseWESL.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/PathUtil.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/PrettyGrammar.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/ScopeWESL.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/Slicer.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/TestSetup.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/TestUtil.d.ts +15 -0
- package/dist/linker/packages/linker/src/test/Util.test.d.ts +1 -0
- package/dist/linker/packages/linker/src/test/WgslTests.d.ts +0 -0
- package/dist/linker/packages/linker/src/test/shared/StringUtil.d.ts +8 -0
- package/dist/linker/packages/linker/src/test/shared/test/StringUtil.test.d.ts +1 -0
- package/dist/minified.cjs +2 -0
- package/dist/minified.cjs.map +1 -0
- package/dist/minified.js +2617 -0
- package/dist/minified.js.map +1 -0
- package/dist/wesl-testsuite/src/test-cases/BulkTests.d.ts +4 -0
- package/dist/wesl-testsuite/src/test-cases/ImportCases.d.ts +3 -0
- package/dist/wesl-testsuite/src/test-cases/ImportSyntaxCases.d.ts +3 -0
- package/package.json +45 -0
- package/src/AbstractElems.ts +148 -0
- package/src/BindIdents.ts +277 -0
- package/src/CommentsGrammar.ts +44 -0
- package/src/FlattenTreeImport.ts +59 -0
- package/src/ImportGrammar.ts +142 -0
- package/src/ImportTree.ts +19 -0
- package/src/Linker.ts +151 -0
- package/src/LowerAndEmit.ts +143 -0
- package/src/ParseWESL.ts +106 -0
- package/src/ParsedRegistry.ts +97 -0
- package/src/PathUtil.ts +52 -0
- package/src/Scope.ts +100 -0
- package/src/Slicer.ts +127 -0
- package/src/StandardTypes.ts +66 -0
- package/src/Util.ts +112 -0
- package/src/WESLCollect.ts +336 -0
- package/src/WESLGrammar.ts +538 -0
- package/src/WESLTokens.ts +97 -0
- package/src/WgslBundle.ts +16 -0
- package/src/debug/ASTtoString.ts +149 -0
- package/src/debug/ImportToString.ts +21 -0
- package/src/debug/LineWrapper.ts +65 -0
- package/src/debug/ScopeToString.ts +51 -0
- package/src/index.ts +7 -0
- package/src/test/ErrorLogging.test.ts +14 -0
- package/src/test/Expression.test.ts +22 -0
- package/src/test/FlattenTreeImport.test.ts +56 -0
- package/src/test/ImportCases.test.ts +440 -0
- package/src/test/ImportSyntaxCases.test.ts +22 -0
- package/src/test/LinkGlob.test.ts +25 -0
- package/src/test/LinkPackage.test.ts +26 -0
- package/src/test/Linker.test.ts +120 -0
- package/src/test/MatchWgslD.test.ts +16 -0
- package/src/test/ParseComments.test.ts +74 -0
- package/src/test/ParseWESL.test.ts +902 -0
- package/src/test/PathUtil.test.ts +34 -0
- package/src/test/PrettyGrammar.test.ts +21 -0
- package/src/test/ScopeWESL.test.ts +272 -0
- package/src/test/Slicer.test.ts +103 -0
- package/src/test/TestSetup.ts +4 -0
- package/src/test/TestUtil.ts +52 -0
- package/src/test/Util.test.ts +22 -0
- package/src/test/WgslTests.ts +0 -0
- package/src/test/__snapshots__/ParseDirectives.test.ts.snap +25 -0
- package/src/test/__snapshots__/ParseWESL.test.ts.snap +119 -0
- package/src/test/__snapshots__/ParseWESL2.test.ts.snap +67 -0
- package/src/test/__snapshots__/RustDirective.test.ts.snap +359 -0
- package/src/test/shared/StringUtil.ts +59 -0
- package/src/test/shared/test/StringUtil.test.ts +32 -0
- package/src/test/wgsl_1/main.wgsl +3 -0
- package/src/test/wgsl_1/util.wgsl +1 -0
- package/src/test/wgsl_2/main2.wgsl +3 -0
- package/src/test/wgsl_2/util2.wgsl +1 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Parser } from '../../mini-parse/src';
|
|
2
|
+
/** currently unused */
|
|
3
|
+
export declare const unknown: Parser<void, import('../../mini-parse/src').NoTags>;
|
|
4
|
+
export declare const blockComment: Parser<any>;
|
|
5
|
+
export declare const lineComment: import('../../mini-parse/src/CombinatorTypes.ts').SeqParser<[import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<"//">, import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<Parser<[...any[], any], import('../../mini-parse/src').NoTags>>]>;
|
|
6
|
+
export declare const comment: Parser<any, import('../../mini-parse/src').NoTags>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ImportTree } from './ImportTree.js';
|
|
2
|
+
export interface FlatImport {
|
|
3
|
+
importPath: string[];
|
|
4
|
+
modulePath: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Simplify importTree into a flattened map from import paths to module paths.
|
|
8
|
+
*
|
|
9
|
+
* @return map from import path (with 'as' renaming) to module Path
|
|
10
|
+
*/
|
|
11
|
+
export declare function flattenTreeImport(imp: ImportTree): FlatImport[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NoTags, Parser } from '../../mini-parse/src';
|
|
2
|
+
export declare const importTokens: import('../../mini-parse/src').FullTokenMatcher<{
|
|
3
|
+
ws: RegExp;
|
|
4
|
+
importSymbol: RegExp;
|
|
5
|
+
ident: RegExp;
|
|
6
|
+
digits: RegExp;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const eolTokens: import('../../mini-parse/src').FullTokenMatcher<{
|
|
9
|
+
ws: RegExp;
|
|
10
|
+
eol: RegExp;
|
|
11
|
+
}>;
|
|
12
|
+
/** parse a WESL style wgsl import statement. */
|
|
13
|
+
export declare const weslImport: Parser<[string, [string, any], string | undefined, any], NoTags>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class ImportTree {
|
|
2
|
+
segments: PathSegment[];
|
|
3
|
+
/** segments in path order */
|
|
4
|
+
constructor(segments: PathSegment[]);
|
|
5
|
+
}
|
|
6
|
+
export type PathSegment = SimpleSegment | ImportTree | SegmentList;
|
|
7
|
+
export declare class SimpleSegment {
|
|
8
|
+
name: string;
|
|
9
|
+
as?: string | undefined;
|
|
10
|
+
args?: string[] | undefined;
|
|
11
|
+
constructor(name: string, as?: string | undefined, args?: string[] | undefined);
|
|
12
|
+
}
|
|
13
|
+
/** or choices for this path segment */
|
|
14
|
+
export declare class SegmentList {
|
|
15
|
+
list: PathSegment[];
|
|
16
|
+
constructor(list: PathSegment[]);
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SrcMap } from '../../mini-parse/src';
|
|
2
|
+
import { ParsedRegistry } from './ParsedRegistry.ts';
|
|
3
|
+
import { Conditions } from './Scope.ts';
|
|
4
|
+
import { WgslBundle } from './WgslBundle.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Link a set of WESL source modules (typically the text from .wesl files) into a single WGSL string.
|
|
7
|
+
* Linking starts with a specified 'root' source module, and recursively incorporates code
|
|
8
|
+
* referenced from other modules (in local files or libraries).
|
|
9
|
+
*
|
|
10
|
+
* Unreferenced (dead) code outside the root module is not included in the output WGSL.
|
|
11
|
+
* Additionally the caller can specify conditions for to control conditional compilation.
|
|
12
|
+
* Only code that is valid with the current conditions is included in the output.
|
|
13
|
+
*
|
|
14
|
+
* @param weslSrc map of wesl source strings (aka modules) by scoped path
|
|
15
|
+
* key is module path or file path
|
|
16
|
+
* `package::foo::bar`, or './foo/bar.wesl', or './foo/bar'
|
|
17
|
+
* value is wesl src
|
|
18
|
+
* (inludes both library and local WESL modules)
|
|
19
|
+
* @param rootModuleName name or module path of the root module
|
|
20
|
+
* @param conditions runtime conditions for conditional compilation
|
|
21
|
+
*/
|
|
22
|
+
export declare function linkWesl(weslSrc: Record<string, string>, rootModuleName?: string, conditions?: Conditions): SrcMap;
|
|
23
|
+
export declare function linkWeslFiles(weslSrc: Record<string, string>, rootModuleName?: string, conditions?: Conditions,
|
|
24
|
+
/** record of file names and wgsl text for modules */
|
|
25
|
+
libs?: WgslBundle[], maxParseCount?: number): SrcMap;
|
|
26
|
+
export declare function linkRegistry(parsed: ParsedRegistry, rootModuleName?: string, conditions?: Conditions): SrcMap;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SrcMapBuilder } from '../../mini-parse/src';
|
|
2
|
+
import { AbstractElem, DeclIdentElem, RefIdentElem, NameElem, TextElem } from './AbstractElems.ts';
|
|
3
|
+
import { Conditions, DeclIdent, Ident } from './Scope.ts';
|
|
4
|
+
/** passed to the emitters */
|
|
5
|
+
interface EmitContext {
|
|
6
|
+
srcBuilder: SrcMapBuilder;
|
|
7
|
+
conditions: Conditions;
|
|
8
|
+
extracting: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** traverse the AST, starting from root elements, emitting wgsl for each */
|
|
11
|
+
export declare function lowerAndEmit(srcBuilder: SrcMapBuilder, rootElems: AbstractElem[], conditions: Conditions, extracting?: boolean): void;
|
|
12
|
+
export declare function lowerAndEmitElem(e: AbstractElem, ctx: EmitContext): void;
|
|
13
|
+
export declare function emitText(e: TextElem, ctx: EmitContext): void;
|
|
14
|
+
export declare function emitName(e: NameElem, ctx: EmitContext): void;
|
|
15
|
+
export declare function emitContents(elem: AbstractElem & {
|
|
16
|
+
contents: AbstractElem[];
|
|
17
|
+
}, ctx: EmitContext): void;
|
|
18
|
+
export declare function emitIdent(e: RefIdentElem | DeclIdentElem, ctx: EmitContext): void;
|
|
19
|
+
/** trace through refersTo links in reference Idents until we find the declaration
|
|
20
|
+
* expects that bindIdents has filled in all refersTo: links
|
|
21
|
+
*/
|
|
22
|
+
export declare function findDecl(ident: Ident): DeclIdent;
|
|
23
|
+
/** check if the element is visible with the current current conditional compilation settings */
|
|
24
|
+
export declare function conditionsValid(elem: AbstractElem, conditions: Conditions): boolean;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AppState, SrcMap } from '../../mini-parse/src';
|
|
2
|
+
import { ModuleElem } from './AbstractElems.ts';
|
|
3
|
+
import { ImportTree } from './ImportTree.ts';
|
|
4
|
+
import { Scope, SrcModule } from './Scope.ts';
|
|
5
|
+
import { OpenElem } from './WESLCollect.ts';
|
|
6
|
+
import { FlatImport } from './FlattenTreeImport.ts';
|
|
7
|
+
/** result of a parse */
|
|
8
|
+
export interface WeslAST {
|
|
9
|
+
/** source text for this module */
|
|
10
|
+
srcModule: SrcModule;
|
|
11
|
+
/** root module element */
|
|
12
|
+
moduleElem: ModuleElem;
|
|
13
|
+
/** root scope for this module */
|
|
14
|
+
rootScope: Scope;
|
|
15
|
+
/** imports found in this module */
|
|
16
|
+
imports: ImportTree[];
|
|
17
|
+
_flatImports?: FlatImport[];
|
|
18
|
+
}
|
|
19
|
+
/** stable and unstable state used during parsing */
|
|
20
|
+
export interface WeslParseState extends AppState<WeslParseContext, StableState> {
|
|
21
|
+
context: WeslParseContext;
|
|
22
|
+
stable: StableState;
|
|
23
|
+
}
|
|
24
|
+
/** stable values used or accumulated during parsing */
|
|
25
|
+
export type StableState = WeslAST;
|
|
26
|
+
/** unstable values used during parse collection */
|
|
27
|
+
export interface WeslParseContext {
|
|
28
|
+
scope: Scope;
|
|
29
|
+
openElems: OpenElem[];
|
|
30
|
+
}
|
|
31
|
+
export declare function parseSrcModule(srcModule: SrcModule, srcMap?: SrcMap, maxParseCount?: number | undefined): WeslAST;
|
|
32
|
+
export declare function parseWESL(src: string, srcMap?: SrcMap, maxParseCount?: number | undefined): WeslAST;
|
|
33
|
+
export declare function blankWeslParseState(srcModule: SrcModule): WeslParseState;
|
|
34
|
+
export declare function syntheticWeslParseState(): WeslParseState;
|
|
35
|
+
/** @return a flattened form of the import tree for convenience in binding idents. */
|
|
36
|
+
export declare function flatImports(ast: WeslAST): FlatImport[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WgslBundle } from 'random_wgsl';
|
|
2
|
+
import { WeslAST } from './ParseWESL.ts';
|
|
3
|
+
export interface ParsedRegistry {
|
|
4
|
+
modules: Record<string, WeslAST>;
|
|
5
|
+
}
|
|
6
|
+
export declare function parsedRegistry(): ParsedRegistry;
|
|
7
|
+
/**
|
|
8
|
+
* Parse WESL each src module (file) into AST elements and a Scope tree.
|
|
9
|
+
* @param src keys are module paths, values are wesl src strings
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseWeslSrc(src: Record<string, string>): ParsedRegistry;
|
|
12
|
+
/** Look up a module with a flexible selector.
|
|
13
|
+
* :: separated module path, package::util
|
|
14
|
+
* / separated file path ./util.wesl (or ./util)
|
|
15
|
+
* simpleName util
|
|
16
|
+
*/
|
|
17
|
+
export declare function selectModule(parsed: ParsedRegistry, selectPath: string, packageName?: string): WeslAST | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* @param srcFiles map of source strings by file path
|
|
20
|
+
* key is '/' separated relative path (relative to srcRoot, not absolute file path )
|
|
21
|
+
* value is wesl source string
|
|
22
|
+
* @param registry add parsed modules to this registry
|
|
23
|
+
* @param packageName name of package
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseIntoRegistry(srcFiles: Record<string, string>, registry: ParsedRegistry, packageName?: string, maxParseCount?: number): void;
|
|
26
|
+
export declare function parseLibsIntoRegistry(libs: WgslBundle[], registry: ParsedRegistry): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** simplistic path manipulation utilities */
|
|
2
|
+
export declare function relativePath(srcPath: string | undefined, reqPath: string): string;
|
|
3
|
+
export declare function dirname(path: string): string;
|
|
4
|
+
export declare function join(a: string, b: string): string;
|
|
5
|
+
/** return path with ./ and foo/.. elements removed */
|
|
6
|
+
export declare function normalize(path: string): string;
|
|
7
|
+
/** return path w/o a suffix.
|
|
8
|
+
* e.g. /foo/bar.wgsl => /foo/bar */
|
|
9
|
+
export declare function noSuffix(path: string): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DeclarationElem, RefIdentElem } from './AbstractElems.ts';
|
|
2
|
+
import { WeslAST } from './ParseWESL.ts';
|
|
3
|
+
export interface SrcModule {
|
|
4
|
+
/** module path "rand_pkg::sub::foo", or "package::main" */
|
|
5
|
+
modulePath: string;
|
|
6
|
+
/** file path to the module for user error reporting e.g "rand_pkg:sub/foo.wesl", or "./sub/foo.wesl" */
|
|
7
|
+
filePath: string;
|
|
8
|
+
/** original src for module */
|
|
9
|
+
src: string;
|
|
10
|
+
}
|
|
11
|
+
/** a src declaration or reference to an ident */
|
|
12
|
+
export type Ident = DeclIdent | RefIdent;
|
|
13
|
+
export type Conditions = Record<string, boolean>;
|
|
14
|
+
interface IdentBase {
|
|
15
|
+
originalName: string;
|
|
16
|
+
conditions?: Conditions;
|
|
17
|
+
id?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface RefIdent extends IdentBase {
|
|
20
|
+
kind: "ref";
|
|
21
|
+
refersTo?: Ident;
|
|
22
|
+
std?: true;
|
|
23
|
+
ast: WeslAST;
|
|
24
|
+
scope: Scope;
|
|
25
|
+
refIdentElem?: RefIdentElem;
|
|
26
|
+
}
|
|
27
|
+
export interface DeclIdent extends IdentBase {
|
|
28
|
+
kind: "decl";
|
|
29
|
+
mangledName?: string;
|
|
30
|
+
declElem?: DeclarationElem;
|
|
31
|
+
scope: Scope;
|
|
32
|
+
}
|
|
33
|
+
export type ScopeKind = "module-scope" | "body-scope";
|
|
34
|
+
/** tree of ident references, organized by lexical scope */
|
|
35
|
+
export interface Scope {
|
|
36
|
+
id?: number;
|
|
37
|
+
idents: Ident[];
|
|
38
|
+
parent: Scope | null;
|
|
39
|
+
children: Scope[];
|
|
40
|
+
kind: ScopeKind;
|
|
41
|
+
}
|
|
42
|
+
export declare function resetScopeIds(): void;
|
|
43
|
+
/** make a new Scope object */
|
|
44
|
+
export declare function makeScope(s: Omit<Scope, "id">): Scope;
|
|
45
|
+
export interface RootAndScope {
|
|
46
|
+
rootScope: Scope;
|
|
47
|
+
scope: Scope;
|
|
48
|
+
}
|
|
49
|
+
export declare function emptyScope(kind: ScopeKind): Scope;
|
|
50
|
+
export declare function emptyBodyScope(parent: Scope): Scope;
|
|
51
|
+
/** For debugging,
|
|
52
|
+
* @return true if a scope is in the rootScope tree somewhere */
|
|
53
|
+
export declare function containsScope(rootScope: Scope, scope: Scope): boolean;
|
|
54
|
+
export declare function exportDecl(scope: Scope, name: string): DeclIdent | undefined;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SrcMap } from '../../mini-parse/src';
|
|
2
|
+
/** specify a start,end portion of a string to be replaced */
|
|
3
|
+
export interface SliceReplace {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Rewrite a string by replacing segments them with provided texts.
|
|
10
|
+
*
|
|
11
|
+
* example:
|
|
12
|
+
* src:
|
|
13
|
+
* aaabbbbbc
|
|
14
|
+
* ^ ^
|
|
15
|
+
* St End Repl='XXX'
|
|
16
|
+
*
|
|
17
|
+
* returns a srcMap with the new text and mappings from the original text to the new text
|
|
18
|
+
* aaaXXXc
|
|
19
|
+
*/
|
|
20
|
+
export declare function sliceReplace(src: string, slices: SliceReplace[], start?: number, end?: number): SrcMap;
|
|
21
|
+
/** find strings in a text -
|
|
22
|
+
* found strings must be 'tokens', surrounded by spaces or punctuation
|
|
23
|
+
*
|
|
24
|
+
* @return SliceReplace elements
|
|
25
|
+
*/
|
|
26
|
+
export declare function sliceWords(text: string, replace: Record<string, string>): SliceReplace[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const stdFns: string[];
|
|
2
|
+
export declare const stdTypes: string[];
|
|
3
|
+
/** return true if the name is for a built in type (not a user struct) */
|
|
4
|
+
export declare function stdType(name: string): boolean;
|
|
5
|
+
/** return true if the name is for a built in fn (not a user function) */
|
|
6
|
+
export declare function stdFn(name: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare function multiKeySet<A, B, V>(m: Map<A, Map<B, V>>, a: A, b: B, v: V): void;
|
|
2
|
+
/** replace strings in a text according to a relacement map
|
|
3
|
+
* replaced strings must be 'tokens', surrounded by spaces or punctuation
|
|
4
|
+
*/
|
|
5
|
+
export declare function replaceWords(text: string, replace: Record<string, string>): string;
|
|
6
|
+
/** return an array partitioned into possibly overlapping groups */
|
|
7
|
+
export declare function grouped<T>(a: T[], size: number, stride?: number): T[][];
|
|
8
|
+
/** group an array into subarrays by a key function */
|
|
9
|
+
export declare function groupBy<T, K>(a: T[], key: (t: T) => K): Map<K, T[]>;
|
|
10
|
+
/** partition an array into two parts by a discriminator function */
|
|
11
|
+
export declare function partition<T>(a: T[], partFn: (t: T) => boolean): [T[], T[]];
|
|
12
|
+
/** run an carrying function over every element in an array,
|
|
13
|
+
* i.e. an inclusive prefix scan */
|
|
14
|
+
export declare function scan<T, U>(array: T[], fn: (a: T, b: U) => U, zero: U): U[];
|
|
15
|
+
/** return a new record by replacing values in 'a' with 'b' as a map.
|
|
16
|
+
* values in 'a' that are not in 'b' are unchanged.
|
|
17
|
+
* e.g. {a: "b", x: 9}, {b: 1} yields {a: 1, x: 9}
|
|
18
|
+
*/
|
|
19
|
+
export declare function mapForward(a: Record<string, string>, b: Record<string, any>): Record<string, any>;
|
|
20
|
+
/** return the last element of an array or undefined */
|
|
21
|
+
export declare function last<T>(a: T[]): T | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Overlap two arrays, returning the tail of b if a is a prefix of b.
|
|
24
|
+
* Otherwise, return undefined.
|
|
25
|
+
*/
|
|
26
|
+
export declare function overlapTail<T>(a: T[], b: T[]): T[] | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CollectContext, CollectPair } from '../../mini-parse/src';
|
|
2
|
+
import { AbstractElem, AliasElem, ConstElem, DeclIdentElem, ElemWithContents, FnElem, GlobalVarElem, ImportElem, ModuleElem, NameElem, OverrideElem, ParamElem, RefIdentElem, StructElem, StructMemberElem, VarElem } from './AbstractElems.ts';
|
|
3
|
+
import { ImportTree, SegmentList, SimpleSegment } from './ImportTree.ts';
|
|
4
|
+
/** create reference Ident and add to context */
|
|
5
|
+
export declare function refIdent(cc: CollectContext): RefIdentElem;
|
|
6
|
+
/** create declaration Ident and add to context */
|
|
7
|
+
export declare function declIdentElem(cc: CollectContext): DeclIdentElem;
|
|
8
|
+
export type OpenElem<T extends AbstractElem = AbstractElem> = Pick<T, "kind"> & {
|
|
9
|
+
contents: AbstractElem[];
|
|
10
|
+
};
|
|
11
|
+
export type PartElem<T extends AbstractElem = AbstractElem> = Pick<T, "kind" | "start" | "end"> & {
|
|
12
|
+
contents: AbstractElem[];
|
|
13
|
+
};
|
|
14
|
+
type VarLikeElem = GlobalVarElem | VarElem | ConstElem | OverrideElem | AliasElem;
|
|
15
|
+
export declare function collectVarLike<E extends VarLikeElem>(kind: E["kind"]): CollectPair<E>;
|
|
16
|
+
export declare function collectFn(): CollectPair<FnElem>;
|
|
17
|
+
export declare function collectFnParam(): CollectPair<ParamElem>;
|
|
18
|
+
export declare function collectStruct(): CollectPair<StructElem>;
|
|
19
|
+
export declare function collectStructMember(): CollectPair<StructMemberElem>;
|
|
20
|
+
export declare function collectNameElem(cc: CollectContext): NameElem;
|
|
21
|
+
export declare function collectModule(): CollectPair<ModuleElem>;
|
|
22
|
+
export declare function importList(cc: CollectContext): SegmentList;
|
|
23
|
+
export declare function importSegment(cc: CollectContext): SimpleSegment;
|
|
24
|
+
export declare function importTree(cc: CollectContext): ImportTree;
|
|
25
|
+
export declare function importElem(): CollectPair<ImportElem>;
|
|
26
|
+
/** collect a scope start starts before and ends after a parser */
|
|
27
|
+
export declare function scopeCollect(): CollectPair<void>;
|
|
28
|
+
export declare function collectSimpleElem<V extends AbstractElem & ElemWithContents>(kind: V["kind"]): CollectPair<V>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Parser } from '../../mini-parse/src';
|
|
2
|
+
/** parser that recognizes key parts of WGSL and also directives like #import */
|
|
3
|
+
export declare const word: import('../../mini-parse/src/CombinatorTypes.ts').OrParser<[Parser<string, import('../../mini-parse/src').NoTags>, Parser<string, import('../../mini-parse/src').NoTags>]>;
|
|
4
|
+
/** parse an identifier into a TypeNameElem */
|
|
5
|
+
export declare const typeNameDecl: import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<Parser<string, import('../../mini-parse/src').NoTags>>;
|
|
6
|
+
/** parse an identifier into a TypeNameElem */
|
|
7
|
+
export declare const fnNameDecl: import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<Parser<string, import('../../mini-parse/src').NoTags>>;
|
|
8
|
+
export declare const type_specifier: Parser<any>;
|
|
9
|
+
export declare const struct_member: Parser<[[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, any], import('../../mini-parse/src').NoTags>;
|
|
10
|
+
export declare const struct_decl: Parser<[string, string, [string, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, any][], string]], import('../../mini-parse/src').NoTags & {
|
|
11
|
+
members: [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, any][][];
|
|
12
|
+
}>;
|
|
13
|
+
/** Also covers func_call_statement.post.ident */
|
|
14
|
+
export declare const fn_call: import('../../mini-parse/src/CombinatorTypes.ts').SeqParser<[Parser<string, import('../../mini-parse/src').NoTags>, () => import('../../mini-parse/src').UndefinedParser | import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<import('../../mini-parse/src/CombinatorTypes.ts').SeqParser<[import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<"<">, Parser<[any, [string, any][]][], import('../../mini-parse/src').NoTags>, import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<">">]>>, import('../../mini-parse/src/CombinatorTypes.ts').SeqParser<["(", Parser<[any, [string, any][]][], import('../../mini-parse/src').NoTags>, import('../../mini-parse/src/CombinatorTypes.ts').ParserFromArg<")">]>]>;
|
|
15
|
+
export declare const expression: import('../../mini-parse/src/CombinatorTypes.ts').SeqParser<[Parser<any, import('../../mini-parse/src').NoTags>, import('../../mini-parse/src/CombinatorTypes.ts').ParserFromRepeatArg<import('../../mini-parse/src/CombinatorTypes.ts').SeqParser<[import('../../mini-parse/src/CombinatorTypes.ts').OrParser<string[]>, Parser<any, import('../../mini-parse/src').NoTags>]>>]>;
|
|
16
|
+
export declare const fn_decl: Parser<[[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, [[string, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, [string, any] | undefined][], string], [string, [string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], any] | undefined, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, any[], string]]], import('../../mini-parse/src').NoTags & {
|
|
17
|
+
fnParam: [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, [string, any] | undefined][];
|
|
18
|
+
} & {
|
|
19
|
+
returnType: any[];
|
|
20
|
+
}>;
|
|
21
|
+
export declare const global_alias: Parser<[string, string, string, any, string], import('../../mini-parse/src').NoTags>;
|
|
22
|
+
export declare const global_decl: Parser<string | [string, string, [string, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, any][], string]] | [string, [any, [string, any][]], string] | [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, [[string, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, [string, any] | undefined][], string], [string, [string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], any] | undefined, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, any[], string]]] | [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, [string, [string, any] | undefined], [[string, [any, [string, any][]]] | undefined], string] | [string, [string, [string, any] | undefined], string, [[any, [string, any][]]], string] | [string, string, string, any, string] | [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], [string, [string, string[], string] | undefined, [string, [string, any] | undefined], [string, [any, [string, any][]]] | undefined], string], import('../../mini-parse/src').NoTags>;
|
|
23
|
+
export declare const weslRoot: Parser<[[string, [string, any], string | undefined, any][], ([string, [string, any], string | undefined, any] | [[string, [string, string, string, string[], string | undefined, string]] | [string, string[]], string])[], (string | [string, [string, any], string | undefined, any] | [string, string, [string, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, any][], string]] | [string, [any, [string, any][]], string] | [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, string, [[string, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, [string, any] | undefined][], string], [string, [string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], any] | undefined, [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, any[], string]]] | [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], string, [string, [string, any] | undefined], [[string, [any, [string, any][]]] | undefined], string] | [string, [string, [string, any] | undefined], string, [[any, [string, any][]]], string] | [string, string, string, any, string] | [[string, string | [string, [string, string[], string]] | [string, [string, string, string, string[], string | undefined, string]] | [string, [string, [any, [string, any][]][], string]] | [string, [string, [any, [string, any][]][], string] | undefined]][], [string, [string, string[], string] | undefined, [string, [string, any] | undefined], [string, [any, [string, any][]]] | undefined], string])[], [string[], true]], import('../../mini-parse/src').NoTags>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** New lines */
|
|
2
|
+
export declare const eol: RegExp;
|
|
3
|
+
/** Whitespaces including new lines */
|
|
4
|
+
export declare const blankspaces: RegExp;
|
|
5
|
+
export declare const directive: RegExp;
|
|
6
|
+
export declare const ident: RegExp;
|
|
7
|
+
export declare const digits: RegExp;
|
|
8
|
+
/** main set of tokens for WGSL */
|
|
9
|
+
export declare const mainTokens: import('../../mini-parse/src').FullTokenMatcher<{
|
|
10
|
+
directive: RegExp;
|
|
11
|
+
textureStorage: RegExp;
|
|
12
|
+
ident: RegExp;
|
|
13
|
+
digits: RegExp;
|
|
14
|
+
symbol: RegExp;
|
|
15
|
+
quote: RegExp;
|
|
16
|
+
ws: RegExp;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const bracketTokens: import('../../mini-parse/src').FullTokenMatcher<{
|
|
19
|
+
bracket: RegExp;
|
|
20
|
+
ws: RegExp;
|
|
21
|
+
other: RegExp;
|
|
22
|
+
}>;
|
|
23
|
+
/** matching tokens at the start of a '//' line comment that might contain #directives */
|
|
24
|
+
export declare const lineCommentTokens: import('../../mini-parse/src').FullTokenMatcher<{
|
|
25
|
+
ws: RegExp;
|
|
26
|
+
notEol: RegExp;
|
|
27
|
+
eol: RegExp;
|
|
28
|
+
}>;
|
|
29
|
+
/** matching tokens while parsing directive parameters #export foo(param1, param2) */
|
|
30
|
+
export declare const argsTokens: import('../../mini-parse/src').FullTokenMatcher<{
|
|
31
|
+
directive: RegExp;
|
|
32
|
+
quote: RegExp;
|
|
33
|
+
relPath: RegExp;
|
|
34
|
+
arg: RegExp;
|
|
35
|
+
symbol: RegExp;
|
|
36
|
+
ws: RegExp;
|
|
37
|
+
eol: RegExp;
|
|
38
|
+
}>;
|
|
39
|
+
export declare const rootWs: import('../../mini-parse/src').FullTokenMatcher<{
|
|
40
|
+
blanks: RegExp;
|
|
41
|
+
other: RegExp;
|
|
42
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface WgslBundle {
|
|
2
|
+
/** name of the package, e.g. wgsl-rand */
|
|
3
|
+
name: string;
|
|
4
|
+
/** npm version of the package e.g. 0.4.1 */
|
|
5
|
+
version: string;
|
|
6
|
+
/** wesl edition of the code e.g. wesl_unstable_2024_1 */
|
|
7
|
+
edition: string;
|
|
8
|
+
/** map of wesl/wgsl modules:
|
|
9
|
+
* keys are file paths, relative to package root (e.g. "./lib.wgsl")
|
|
10
|
+
* values are wgsl/wesl code strings
|
|
11
|
+
*/
|
|
12
|
+
modules: Record<string, string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** debug utility for constructing strings that wrap at a fixed column width
|
|
2
|
+
* text beyond the column width is wrapped to start on the next line
|
|
3
|
+
*/
|
|
4
|
+
export declare class LineWrapper {
|
|
5
|
+
#private;
|
|
6
|
+
readonly indent: number;
|
|
7
|
+
readonly maxWidth: number;
|
|
8
|
+
readonly hangingIndent: number;
|
|
9
|
+
constructor(indent?: number, maxWidth?: number, hangingIndent?: number);
|
|
10
|
+
/** add a new line to the constructed string */
|
|
11
|
+
nl(): void;
|
|
12
|
+
/** add a string, wrapping to the next line if necessary */
|
|
13
|
+
add(s: string): void;
|
|
14
|
+
/** add a raw block of text with no wrapping */
|
|
15
|
+
addBlock(s: string, andNewLine?: boolean): void;
|
|
16
|
+
/** @return the constructed string */
|
|
17
|
+
get result(): string;
|
|
18
|
+
/** true if the result contains no newlines */
|
|
19
|
+
get oneLine(): boolean;
|
|
20
|
+
private hangingNl;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NoTags, Parser, TagRecord } from '../../../mini-parse/src';
|
|
2
|
+
import { TestParseResult } from '../../../mini-parse/src/test-util';
|
|
3
|
+
import { WeslAST } from '../ParseWESL.js';
|
|
4
|
+
export declare function testAppParse<T, N extends TagRecord = NoTags>(parser: Parser<T, N>, src: string): TestParseResult<T, N, WeslAST>;
|
|
5
|
+
/** Convenience wrapper to link wgsl for tests.
|
|
6
|
+
* The first module is named "package::root",
|
|
7
|
+
* subsequent modules are named "package::file1", "package::file2", etc.
|
|
8
|
+
*/
|
|
9
|
+
export declare function link2Test(...rawWgsl: string[]): string;
|
|
10
|
+
/** link wesl for tests, and return the console log as well */
|
|
11
|
+
export declare function linkWithLog(...rawWgsl: string[]): {
|
|
12
|
+
log: string;
|
|
13
|
+
result: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function parse2Test(src: string): WeslAST;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** trim source for test comparisons
|
|
2
|
+
* rm blank lines
|
|
3
|
+
* rm leading indent consistently across remaining lines
|
|
4
|
+
* rm trailing spaces from each line */
|
|
5
|
+
export declare function trimSrc(src: string): string;
|
|
6
|
+
export declare function dropWhile<T>(a: T[], fn: (el: T) => boolean): T[];
|
|
7
|
+
export declare function dropRightWhile<T>(a: T[], fn: (el: T) => boolean): T[];
|
|
8
|
+
export declare function matchTrimmed(result: string, expected: string): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|