@galacean/engine-shader-parser 0.0.0-stage → 2.0.0-alpha.53
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/LICENSE +21 -0
- package/dist/main.analyzer.js +2 -0
- package/dist/main.analyzer.js.map +1 -0
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/main.shared.js +2 -0
- package/dist/main.shared.js.map +1 -0
- package/dist/module.analyzer.js +2 -0
- package/dist/module.analyzer.js.map +1 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/module.shared.js +2 -0
- package/dist/module.shared.js.map +1 -0
- package/dist/shared/GLESShaderInfo.main.js +2 -0
- package/dist/shared/GLESShaderInfo.main.js.map +1 -0
- package/dist/shared/GLESShaderInfo.module.js +2 -0
- package/dist/shared/GLESShaderInfo.module.js.map +1 -0
- package/internal/analyzer/package.json +5 -0
- package/internal/package.json +5 -0
- package/package.json +42 -3
- package/shared/package.json +5 -0
- package/types/GSError.d.ts +31 -0
- package/types/ParsedShaderPass.d.ts +11 -0
- package/types/ParserObjectPool.d.ts +51 -0
- package/types/ParserUtils.d.ts +91 -0
- package/types/Preprocessor.d.ts +71 -0
- package/types/PreprocessorExpression.d.ts +1 -0
- package/types/ShaderCompilerUtils.d.ts +9 -0
- package/types/backends/GLESShaderInfo.d.ts +39 -0
- package/types/common/BaseLexer.d.ts +61 -0
- package/types/common/BaseToken.d.ts +105 -0
- package/types/common/BranchAnalysis.d.ts +84 -0
- package/types/common/BranchIdentity.d.ts +58 -0
- package/types/common/BranchSemantics.d.ts +54 -0
- package/types/common/IBaseSymbol.d.ts +9 -0
- package/types/common/PreprocessorCondition.d.ts +39 -0
- package/types/common/ShaderPosition.d.ts +20 -0
- package/types/common/ShaderRange.d.ts +18 -0
- package/types/common/SymbolTable.d.ts +43 -0
- package/types/common/SymbolTableStack.d.ts +53 -0
- package/types/common/enums/Keyword.d.ts +124 -0
- package/types/common/enums/ShaderStage.d.ts +5 -0
- package/types/common/index.d.ts +5 -0
- package/types/common/types.d.ts +101 -0
- package/types/formatDiagnostic.d.ts +18 -0
- package/types/index.d.ts +37 -0
- package/types/ir/ShaderBuiltinSemantic.d.ts +13 -0
- package/types/ir/ShaderClueIR.d.ts +48 -0
- package/types/ir/ShaderCoreInfo.d.ts +85 -0
- package/types/ir/ShaderDeclarationOwnership.d.ts +36 -0
- package/types/ir/ShaderStructOwnership.d.ts +18 -0
- package/types/ir/index.d.ts +4 -0
- package/types/lalr/CFG.d.ts +5 -0
- package/types/lalr/LALR1.d.ts +27 -0
- package/types/lalr/Production.d.ts +9 -0
- package/types/lalr/State.d.ts +20 -0
- package/types/lalr/StateItem.d.ts +20 -0
- package/types/lalr/Utils.d.ts +29 -0
- package/types/lalr/index.d.ts +2 -0
- package/types/lalr/types.d.ts +14 -0
- package/types/lexer/AnalyzerLexer.d.ts +56 -0
- package/types/lexer/Lexer.d.ts +122 -0
- package/types/lexer/index.d.ts +1 -0
- package/types/parser/AST.d.ts +625 -0
- package/types/parser/AnalyzerSemanticDiagnostics.d.ts +15 -0
- package/types/parser/Grammar.d.ts +11 -0
- package/types/parser/GrammarSymbol.d.ts +128 -0
- package/types/parser/ICodeGenVisitor.d.ts +29 -0
- package/types/parser/MacroExpansionFacts.d.ts +25 -0
- package/types/parser/ParsedShaderPass.d.ts +71 -0
- package/types/parser/ParsedShaderPassHandle.d.ts +29 -0
- package/types/parser/ParserSemanticValidation.d.ts +110 -0
- package/types/parser/PassParser.d.ts +15 -0
- package/types/parser/RuntimePassParser.d.ts +24 -0
- package/types/parser/SemanticAnalyzer.d.ts +174 -0
- package/types/parser/SemanticDiagnostics.d.ts +93 -0
- package/types/parser/ShaderIncludePath.d.ts +23 -0
- package/types/parser/ShaderInfo.d.ts +56 -0
- package/types/parser/ShaderTargetParser.d.ts +65 -0
- package/types/parser/TypeSystem.d.ts +104 -0
- package/types/parser/ValidatedPassParser.d.ts +24 -0
- package/types/parser/builtin/functions.d.ts +34 -0
- package/types/parser/builtin/index.d.ts +2 -0
- package/types/parser/builtin/variables.d.ts +13 -0
- package/types/parser/index.d.ts +7 -0
- package/types/parser/symbolTable/FnSymbol.d.ts +9 -0
- package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
- package/types/parser/symbolTable/SymbolDataType.d.ts +12 -0
- package/types/parser/symbolTable/SymbolInfo.d.ts +33 -0
- package/types/parser/symbolTable/VarSymbol.d.ts +16 -0
- package/types/parser/symbolTable/index.d.ts +6 -0
- package/types/parser/types.d.ts +49 -0
- package/types/preprocessor/PreprocessorCondition.d.ts +56 -0
- package/types/preprocessor/PreprocessorConditionDiagram.d.ts +11 -0
- package/types/preprocessor/PreprocessorConditionNormalization.d.ts +18 -0
- package/types/preprocessor/PreprocessorMacroState.d.ts +84 -0
- package/types/runtime.d.ts +36 -0
- package/types/shared.d.ts +1 -0
- package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
- package/types/sourceParser/ShaderSourceParser.d.ts +36 -0
- package/types/sourceParser/ShaderSourceSymbol.d.ts +12 -0
- package/types/sourceParser/SourceLexer.d.ts +20 -0
- package/types/sourceParser/index.d.ts +1 -0
- package/README.md +0 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Condition } from "@galacean/engine-design";
|
|
2
|
+
type Range = readonly [number, number];
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes the truth of a fully expanded condition while preserving integer and short-circuit semantics.
|
|
5
|
+
* @param condition - Expression containing constants and definition checks.
|
|
6
|
+
* @returns An equivalent condition without modifying the input tree.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizePreprocessorCondition(condition: Condition): Condition;
|
|
10
|
+
/**
|
|
11
|
+
* Bounds every result of a fully expanded expression over all definition configurations.
|
|
12
|
+
* @param condition - Expression containing constants and definition checks.
|
|
13
|
+
* @param cache - Optional memoization shared within one call over unchanged expression trees.
|
|
14
|
+
* @returns Inclusive signed integer bounds, or undefined when total evaluation cannot be established.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPreprocessorConditionRange(condition: Condition, cache?: WeakMap<Condition, Range | undefined>): Range | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type PreprocessorConditionalArm } from "./PreprocessorCondition";
|
|
2
|
+
interface MacroState {
|
|
3
|
+
readonly defined: boolean | undefined;
|
|
4
|
+
readonly replacementKey?: string;
|
|
5
|
+
readonly functionParams?: readonly string[];
|
|
6
|
+
readonly functionBody?: string;
|
|
7
|
+
}
|
|
8
|
+
type MacroStateMap = Record<string, MacroState>;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export interface PreprocessorMacroSnapshot {
|
|
11
|
+
readonly states: MacroStateMap;
|
|
12
|
+
readonly versions: Readonly<Record<string, number>>;
|
|
13
|
+
}
|
|
14
|
+
/** @internal */
|
|
15
|
+
export interface CachedPreprocessorMacroState {
|
|
16
|
+
readonly snapshot: PreprocessorMacroSnapshot;
|
|
17
|
+
readonly mutatedNames: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
export interface PreprocessorDirectiveResult {
|
|
21
|
+
/** Whether the directive remains reachable in at least one macro configuration. */
|
|
22
|
+
readonly keep: boolean;
|
|
23
|
+
/** Truth and captured predicates of the entire arm relative to its enclosing parent. */
|
|
24
|
+
readonly arm?: PreprocessorConditionalArm;
|
|
25
|
+
/** Deterministic expression failure, when present. */
|
|
26
|
+
readonly error?: string;
|
|
27
|
+
/** Start offset of the failure relative to the trimmed directive expression. */
|
|
28
|
+
readonly errorStart?: number;
|
|
29
|
+
/** Exclusive end offset of the failure relative to the trimmed directive expression. */
|
|
30
|
+
readonly errorEnd?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Tracks source-defined macros while the include expander walks one preprocessing stream.
|
|
34
|
+
*
|
|
35
|
+
* External macros start unknown. Conditional mutations are merged across every reachable arm, so
|
|
36
|
+
* callers only prune source when all configurations agree that an arm is dead.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare class PreprocessorMacroState {
|
|
40
|
+
private _states;
|
|
41
|
+
private _versions;
|
|
42
|
+
private _versionKey;
|
|
43
|
+
private readonly _frames;
|
|
44
|
+
private readonly _expressionContext;
|
|
45
|
+
reachable: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Applies a non-include directive and reports reachability plus definite evaluation failures.
|
|
48
|
+
* @param directive - Directive keyword without `#`.
|
|
49
|
+
* @param body - Comment-masked logical directive body.
|
|
50
|
+
* @returns Directive reachability and an optional deterministic expression error.
|
|
51
|
+
*/
|
|
52
|
+
processDirective(directive: string, body: string): PreprocessorDirectiveResult;
|
|
53
|
+
/** @internal */
|
|
54
|
+
captureSnapshot(): PreprocessorMacroSnapshot;
|
|
55
|
+
/** @internal */
|
|
56
|
+
createCachedState(before: PreprocessorMacroSnapshot): CachedPreprocessorMacroState;
|
|
57
|
+
/** @internal */
|
|
58
|
+
applyCachedState(cached: CachedPreprocessorMacroState): void;
|
|
59
|
+
/** @internal */
|
|
60
|
+
cacheKey(): string;
|
|
61
|
+
private _openConditional;
|
|
62
|
+
private _advanceConditional;
|
|
63
|
+
private _advanceElse;
|
|
64
|
+
private _closeConditional;
|
|
65
|
+
private _finishCurrentArm;
|
|
66
|
+
private _mergeStates;
|
|
67
|
+
private _define;
|
|
68
|
+
private _undef;
|
|
69
|
+
private _markMutation;
|
|
70
|
+
private _evaluate;
|
|
71
|
+
private _definedCondition;
|
|
72
|
+
private _arm;
|
|
73
|
+
private _appendCondition;
|
|
74
|
+
private _macroVersionKey;
|
|
75
|
+
private _applyAssumption;
|
|
76
|
+
private _macro;
|
|
77
|
+
private _state;
|
|
78
|
+
private _stateFrom;
|
|
79
|
+
private static _cloneStates;
|
|
80
|
+
private static _sameState;
|
|
81
|
+
private static _and;
|
|
82
|
+
private static _conditionAssumptions;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from "./common";
|
|
2
|
+
export { BaseToken, EMPTY_BRANCH, EOF, sameBranch } from "./common/BaseToken";
|
|
3
|
+
export type { BranchCondition, BranchConstraint, BranchSignature } from "./common/BaseToken";
|
|
4
|
+
export * from "./common/BaseLexer";
|
|
5
|
+
export * from "./common/PreprocessorCondition";
|
|
6
|
+
export * from "./common/SymbolTable";
|
|
7
|
+
export * from "./common/SymbolTableStack";
|
|
8
|
+
export * from "./common/IBaseSymbol";
|
|
9
|
+
export { getLexicalDeclarationCoexistence } from "./common/BranchIdentity";
|
|
10
|
+
export { canInheritanceBranchesCover, proveInheritanceBranchesCover } from "./preprocessor/PreprocessorCondition";
|
|
11
|
+
export * from "./common/enums/ShaderStage";
|
|
12
|
+
export * from "./lexer";
|
|
13
|
+
export * from "./lalr";
|
|
14
|
+
export { ShaderTargetParser } from "./parser/ShaderTargetParser";
|
|
15
|
+
export { Grammar } from "./parser/Grammar";
|
|
16
|
+
export { getParsedShaderPassPayload, type ParsedShaderPassPayload } from "./parser/ParsedShaderPassHandle";
|
|
17
|
+
export { normalizeShaderIncludeMap } from "./parser/ShaderIncludePath";
|
|
18
|
+
export type { ParsedShaderPassData } from "./parser/ParsedShaderPass";
|
|
19
|
+
export { mapExpandedShaderError } from "./parser/ParsedShaderPass";
|
|
20
|
+
export * from "./parser/RuntimePassParser";
|
|
21
|
+
export * from "./parser/AST";
|
|
22
|
+
export * from "./parser/types";
|
|
23
|
+
export * from "./parser/GrammarSymbol";
|
|
24
|
+
export * from "./parser/ShaderInfo";
|
|
25
|
+
export * from "./parser/ICodeGenVisitor";
|
|
26
|
+
export * from "./parser/symbolTable";
|
|
27
|
+
export * from "./ir";
|
|
28
|
+
export * from "./sourceParser";
|
|
29
|
+
export * from "./sourceParser/ShaderSourceFactory";
|
|
30
|
+
export * from "./Preprocessor";
|
|
31
|
+
export * from "./PreprocessorExpression";
|
|
32
|
+
export * from "./ParserObjectPool";
|
|
33
|
+
export * from "./ParserUtils";
|
|
34
|
+
export * from "./GSError";
|
|
35
|
+
export * from "./ShaderCompilerUtils";
|
|
36
|
+
export * from "./backends/GLESShaderInfo";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ParsedShaderPass } from "./ParsedShaderPass";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IRenderStates, IShaderPassSource, IShaderSource, ISubShaderSource } from "@galacean/engine-design";
|
|
2
|
+
export declare class ShaderSourceFactory {
|
|
3
|
+
static createRenderStates(): IRenderStates;
|
|
4
|
+
static createShaderSource(name: string): IShaderSource;
|
|
5
|
+
static createSubShaderSource(name: string): ISubShaderSource;
|
|
6
|
+
static createShaderPassSource(name: string): IShaderPassSource;
|
|
7
|
+
static createUsePass(name: string): IShaderPassSource;
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IShaderSource } from "@galacean/engine-design";
|
|
2
|
+
import type { ParserObjectPool } from "../ParserObjectPool";
|
|
3
|
+
/** Result of parsing one ShaderLab source document. */
|
|
4
|
+
export interface ShaderSourceParseResult {
|
|
5
|
+
/** Parsed source structure, including subshaders, passes, entries, and render states. */
|
|
6
|
+
shaderSource: IShaderSource;
|
|
7
|
+
/** Source-structure diagnostics captured during this parse. */
|
|
8
|
+
errors: readonly Error[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parses complete ShaderLab documents using a request-owned parser session.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare class ShaderSourceParser {
|
|
15
|
+
/**
|
|
16
|
+
* Parses ShaderLab source and returns the source object for compatibility callers.
|
|
17
|
+
* @param sourceCode - Complete ShaderLab source.
|
|
18
|
+
* @returns Parsed source structure.
|
|
19
|
+
*/
|
|
20
|
+
static parse(sourceCode: string): IShaderSource;
|
|
21
|
+
/**
|
|
22
|
+
* Parses ShaderLab source without converting scanner exceptions into diagnostics.
|
|
23
|
+
* @param sourceCode - Complete ShaderLab source.
|
|
24
|
+
* @param objectPool - Optional compiler-owned allocator for synchronous source parsing.
|
|
25
|
+
* @returns Parsed source structure and recoverable structural diagnostics.
|
|
26
|
+
* @throws GSError when token scanning cannot continue.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
static parseStrict(sourceCode: string, objectPool?: ParserObjectPool): ShaderSourceParseResult;
|
|
30
|
+
/**
|
|
31
|
+
* Parses ShaderLab source with a parse-local diagnostic snapshot.
|
|
32
|
+
* @param sourceCode - Complete ShaderLab source.
|
|
33
|
+
* @returns Parsed source structure and diagnostics from the same parse.
|
|
34
|
+
*/
|
|
35
|
+
static parseWithErrors(sourceCode: string): ShaderSourceParseResult;
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BranchSignature } from "../common/BaseToken";
|
|
2
|
+
import { IBaseSymbol } from "../common/IBaseSymbol";
|
|
3
|
+
export declare class ShaderSourceSymbol implements IBaseSymbol {
|
|
4
|
+
ident: string;
|
|
5
|
+
type: number | null;
|
|
6
|
+
value?: any;
|
|
7
|
+
isInMacroBranch: boolean;
|
|
8
|
+
branchSignature: BranchSignature;
|
|
9
|
+
constructor(ident: string, type: number | null, value?: any);
|
|
10
|
+
set(ident: string, type: number, value?: any): void;
|
|
11
|
+
equal(other: ShaderSourceSymbol): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Color } from "@galacean/engine-math";
|
|
2
|
+
import { ShaderPosition, ShaderRange } from "../common";
|
|
3
|
+
import { BaseLexer } from "../common/BaseLexer";
|
|
4
|
+
import { BaseToken } from "../common/BaseToken";
|
|
5
|
+
export default class SourceLexer extends BaseLexer {
|
|
6
|
+
hasPendingContent: boolean;
|
|
7
|
+
setSource(source: string): void;
|
|
8
|
+
private static _keywordLexemeTable;
|
|
9
|
+
private static _symbolLexemeTable;
|
|
10
|
+
private static _isWordSeparatorChar;
|
|
11
|
+
private static _scanDigits;
|
|
12
|
+
scanNumber(): number;
|
|
13
|
+
scanColor(): Color;
|
|
14
|
+
scanToken(): BaseToken | undefined;
|
|
15
|
+
scanToCharacter(char: string): boolean;
|
|
16
|
+
createCompileError(message: string, location?: ShaderPosition | ShaderRange, code?: string): import("../GSError").GSError;
|
|
17
|
+
private _scanWord;
|
|
18
|
+
private _validateWordBoundaries;
|
|
19
|
+
private _isValidWordBoundary;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ShaderSourceParser, type ShaderSourceParseResult } from "./ShaderSourceParser";
|
package/README.md
DELETED