@galacean/engine-shader-parser 0.0.0-stage → 2.0.0-alpha.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/dist/main.analyzer.js +2 -0
  3. package/dist/main.analyzer.js.map +1 -0
  4. package/dist/main.js +2 -0
  5. package/dist/main.js.map +1 -0
  6. package/dist/main.shared.js +2 -0
  7. package/dist/main.shared.js.map +1 -0
  8. package/dist/module.analyzer.js +2 -0
  9. package/dist/module.analyzer.js.map +1 -0
  10. package/dist/module.js +2 -0
  11. package/dist/module.js.map +1 -0
  12. package/dist/module.shared.js +2 -0
  13. package/dist/module.shared.js.map +1 -0
  14. package/dist/shared/GLESShaderInfo.main.js +2 -0
  15. package/dist/shared/GLESShaderInfo.main.js.map +1 -0
  16. package/dist/shared/GLESShaderInfo.module.js +2 -0
  17. package/dist/shared/GLESShaderInfo.module.js.map +1 -0
  18. package/internal/analyzer/package.json +5 -0
  19. package/internal/package.json +5 -0
  20. package/package.json +42 -3
  21. package/shared/package.json +5 -0
  22. package/types/GSError.d.ts +31 -0
  23. package/types/ParsedShaderPass.d.ts +11 -0
  24. package/types/ParserObjectPool.d.ts +51 -0
  25. package/types/ParserUtils.d.ts +91 -0
  26. package/types/Preprocessor.d.ts +71 -0
  27. package/types/PreprocessorExpression.d.ts +1 -0
  28. package/types/ShaderCompilerUtils.d.ts +9 -0
  29. package/types/backends/GLESShaderInfo.d.ts +39 -0
  30. package/types/common/BaseLexer.d.ts +61 -0
  31. package/types/common/BaseToken.d.ts +105 -0
  32. package/types/common/BranchAnalysis.d.ts +84 -0
  33. package/types/common/BranchIdentity.d.ts +58 -0
  34. package/types/common/BranchSemantics.d.ts +54 -0
  35. package/types/common/IBaseSymbol.d.ts +9 -0
  36. package/types/common/PreprocessorCondition.d.ts +39 -0
  37. package/types/common/ShaderPosition.d.ts +20 -0
  38. package/types/common/ShaderRange.d.ts +18 -0
  39. package/types/common/SymbolTable.d.ts +43 -0
  40. package/types/common/SymbolTableStack.d.ts +53 -0
  41. package/types/common/enums/Keyword.d.ts +124 -0
  42. package/types/common/enums/ShaderStage.d.ts +5 -0
  43. package/types/common/index.d.ts +5 -0
  44. package/types/common/types.d.ts +101 -0
  45. package/types/formatDiagnostic.d.ts +18 -0
  46. package/types/index.d.ts +37 -0
  47. package/types/ir/ShaderBuiltinSemantic.d.ts +13 -0
  48. package/types/ir/ShaderClueIR.d.ts +48 -0
  49. package/types/ir/ShaderCoreInfo.d.ts +85 -0
  50. package/types/ir/ShaderDeclarationOwnership.d.ts +36 -0
  51. package/types/ir/ShaderStructOwnership.d.ts +18 -0
  52. package/types/ir/index.d.ts +4 -0
  53. package/types/lalr/CFG.d.ts +5 -0
  54. package/types/lalr/LALR1.d.ts +27 -0
  55. package/types/lalr/Production.d.ts +9 -0
  56. package/types/lalr/State.d.ts +20 -0
  57. package/types/lalr/StateItem.d.ts +20 -0
  58. package/types/lalr/Utils.d.ts +29 -0
  59. package/types/lalr/index.d.ts +2 -0
  60. package/types/lalr/types.d.ts +14 -0
  61. package/types/lexer/AnalyzerLexer.d.ts +56 -0
  62. package/types/lexer/Lexer.d.ts +122 -0
  63. package/types/lexer/index.d.ts +1 -0
  64. package/types/parser/AST.d.ts +625 -0
  65. package/types/parser/AnalyzerSemanticDiagnostics.d.ts +15 -0
  66. package/types/parser/Grammar.d.ts +11 -0
  67. package/types/parser/GrammarSymbol.d.ts +128 -0
  68. package/types/parser/ICodeGenVisitor.d.ts +29 -0
  69. package/types/parser/MacroExpansionFacts.d.ts +25 -0
  70. package/types/parser/ParsedShaderPass.d.ts +71 -0
  71. package/types/parser/ParsedShaderPassHandle.d.ts +29 -0
  72. package/types/parser/ParserSemanticValidation.d.ts +110 -0
  73. package/types/parser/PassParser.d.ts +15 -0
  74. package/types/parser/RuntimePassParser.d.ts +24 -0
  75. package/types/parser/SemanticAnalyzer.d.ts +174 -0
  76. package/types/parser/SemanticDiagnostics.d.ts +93 -0
  77. package/types/parser/ShaderIncludePath.d.ts +23 -0
  78. package/types/parser/ShaderInfo.d.ts +56 -0
  79. package/types/parser/ShaderTargetParser.d.ts +65 -0
  80. package/types/parser/TypeSystem.d.ts +104 -0
  81. package/types/parser/ValidatedPassParser.d.ts +24 -0
  82. package/types/parser/builtin/functions.d.ts +34 -0
  83. package/types/parser/builtin/index.d.ts +2 -0
  84. package/types/parser/builtin/variables.d.ts +13 -0
  85. package/types/parser/index.d.ts +7 -0
  86. package/types/parser/symbolTable/FnSymbol.d.ts +9 -0
  87. package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
  88. package/types/parser/symbolTable/SymbolDataType.d.ts +12 -0
  89. package/types/parser/symbolTable/SymbolInfo.d.ts +33 -0
  90. package/types/parser/symbolTable/VarSymbol.d.ts +16 -0
  91. package/types/parser/symbolTable/index.d.ts +6 -0
  92. package/types/parser/types.d.ts +49 -0
  93. package/types/preprocessor/PreprocessorCondition.d.ts +56 -0
  94. package/types/preprocessor/PreprocessorConditionDiagram.d.ts +11 -0
  95. package/types/preprocessor/PreprocessorConditionNormalization.d.ts +18 -0
  96. package/types/preprocessor/PreprocessorMacroState.d.ts +84 -0
  97. package/types/runtime.d.ts +36 -0
  98. package/types/shared.d.ts +1 -0
  99. package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
  100. package/types/sourceParser/ShaderSourceParser.d.ts +36 -0
  101. package/types/sourceParser/ShaderSourceSymbol.d.ts +12 -0
  102. package/types/sourceParser/SourceLexer.d.ts +20 -0
  103. package/types/sourceParser/index.d.ts +1 -0
  104. package/README.md +0 -3
@@ -0,0 +1,85 @@
1
+ import { EShaderStage } from "../common/enums/ShaderStage";
2
+ import { type BranchCoverage, type BranchSignature, type DeclarationCoexistence } from "../common/BaseToken";
3
+ import { ASTNode } from "../parser/AST";
4
+ import { FnSymbol, SymbolInfo, VarSymbol } from "../parser/symbolTable";
5
+ import type { StructProp } from "../parser/types";
6
+ import type { ShaderClueIR } from "./ShaderClueIR";
7
+ import { type DeferredDeclarationOwnership } from "./ShaderDeclarationOwnership";
8
+ /** Role a struct type plays in backend stage IO. @internal */
9
+ export declare enum ShaderStructRole {
10
+ Varying = "varying",
11
+ Attribute = "attribute",
12
+ Mrt = "mrt"
13
+ }
14
+ /** Backend-relevant stage entry and its matching declarations. @internal */
15
+ export interface ShaderEntryPointInfo {
16
+ /** Pipeline stage represented by this entry. */
17
+ readonly stage: EShaderStage;
18
+ /** Entry function name from the ShaderLab pass. */
19
+ readonly name: string;
20
+ /** Matching function declarations retained across macro branches. */
21
+ readonly functions: readonly FnSymbol[];
22
+ /** Whether two declarations are proven active under the same macro configuration. */
23
+ readonly hasDefiniteAmbiguity: boolean;
24
+ }
25
+ /** A struct assigned incompatible IO roles. The analyzer decides how to diagnose this fact. @internal */
26
+ export interface ShaderStructRoleConflict {
27
+ /** Conflicting struct declaration. */
28
+ readonly struct: ASTNode.StructSpecifier;
29
+ /** Roles inferred from the two entry signatures. */
30
+ readonly roles: readonly ShaderStructRole[];
31
+ }
32
+ /** Backend-required shader input/output facts. @internal */
33
+ export interface ShaderIOInfo {
34
+ readonly attributeStructs: readonly ASTNode.StructSpecifier[];
35
+ readonly attributeList: readonly StructProp[];
36
+ readonly varyingStructs: readonly ASTNode.StructSpecifier[];
37
+ readonly varyingList: readonly StructProp[];
38
+ readonly mrtStructs: readonly ASTNode.StructSpecifier[];
39
+ readonly mrtList: readonly StructProp[];
40
+ /** Exact variable identities whose custom structs are lowered as stage interfaces. */
41
+ readonly structVariableRoles: ReadonlyMap<VarSymbol, ShaderStructRole>;
42
+ /** Interface variables reachable from the vertex entry, used for unresolved global macro values. */
43
+ readonly vertexStructVariableRoles: ReadonlyMap<VarSymbol, ShaderStructRole>;
44
+ /** Interface variables reachable from the fragment entry, used for unresolved global macro values. */
45
+ readonly fragmentStructVariableRoles: ReadonlyMap<VarSymbol, ShaderStructRole>;
46
+ }
47
+ /**
48
+ * Lightweight semantic information required by shader backends.
49
+ *
50
+ * It derives entry and IO facts from `ShaderClueIR` without creating diagnostics or depending on an
51
+ * analyzer. Invalid-role facts are retained separately so emitters can stay deterministic while an
52
+ * analyzer chooses the diagnostic policy.
53
+ * @internal
54
+ */
55
+ export declare class ShaderCoreInfo {
56
+ readonly getDeclarationCoexistence: DeclarationCoexistenceResolver;
57
+ readonly getBranchCoverage: BranchCoverageResolver;
58
+ /** Vertex entry facts. */
59
+ readonly vertexEntry: ShaderEntryPointInfo;
60
+ /** Fragment entry facts. */
61
+ readonly fragmentEntry: ShaderEntryPointInfo;
62
+ /** Valid, unambiguous stage IO consumed by backends. */
63
+ readonly io: ShaderIOInfo;
64
+ /** IO role conflicts excluded from `io`. */
65
+ readonly roleConflicts: readonly ShaderStructRoleConflict[];
66
+ /** Global preprocessor declarations that backends may reproduce. */
67
+ readonly outerGlobalMacroDeclarations: readonly ASTNode.GlobalDeclaration[];
68
+ /** Surviving declarations whose inheritance ownership must be selected for the concrete macro variant. */
69
+ readonly deferredDeclarationOwnership: ReadonlyMap<SymbolInfo, DeferredDeclarationOwnership>;
70
+ /** Deferred candidates whose unresolved signatures or known inheritance conflicts prevent safe selection. */
71
+ readonly unsupportedDeferredDeclarations: readonly SymbolInfo[];
72
+ /**
73
+ * Derives backend-required facts from a neutral shader IR.
74
+ * @param ir - Neutral shader IR.
75
+ * @param vertexEntry - Vertex entry function name.
76
+ * @param fragmentEntry - Fragment entry function name.
77
+ * @param getDeclarationCoexistence - Optional full macro-proof function for authoring/offline validation.
78
+ * @param getBranchCoverage - Optional full coverage proof for conditional runtime owners.
79
+ * @returns Lightweight backend information with no diagnostics.
80
+ */
81
+ static create(ir: ShaderClueIR, vertexEntry: string, fragmentEntry: string, getDeclarationCoexistence?: DeclarationCoexistenceResolver, getBranchCoverage?: BranchCoverageResolver): ShaderCoreInfo;
82
+ private constructor();
83
+ }
84
+ export type DeclarationCoexistenceResolver = (earlier: BranchSignature, later: BranchSignature) => DeclarationCoexistence;
85
+ export type BranchCoverageResolver = (candidates: readonly BranchSignature[], callSiteBranch: BranchSignature) => BranchCoverage;
@@ -0,0 +1,36 @@
1
+ import type { SymbolTable } from "../common/SymbolTable";
2
+ import { type SymbolInfo } from "../parser/symbolTable";
3
+ /** Variant-time ownership of a declaration whose static inheritance coverage remains unknown. @internal */
4
+ export interface DeferredDeclarationOwnership {
5
+ /** Unique declaration identity within the parsed pass. */
6
+ readonly id: number;
7
+ /** Exact declaration family resolved together at variant selection. */
8
+ readonly group: number;
9
+ /** ShaderLab inheritance layer; larger values take precedence. */
10
+ readonly sourceScope: number;
11
+ }
12
+ /** Request-owned inheritance facts derived from the completed symbol table. @internal */
13
+ export interface ShaderDeclarationOwnershipInfo {
14
+ /** Declarations requiring variant-time ownership selection. */
15
+ readonly declarations: ReadonlyMap<SymbolInfo, DeferredDeclarationOwnership>;
16
+ /** Candidates with unresolved signatures or known conflicts that variant-time selection must not hide. */
17
+ readonly unsupported: readonly SymbolInfo[];
18
+ /** Coverage of each inherited declaration by all strictly matching narrower candidates. */
19
+ readonly coverage: ReadonlyMap<SymbolInfo, boolean | undefined>;
20
+ }
21
+ /**
22
+ * Derives deferred declaration families without treating wildcard overload compatibility as identity.
23
+ * @param symbolTable - Completed global symbol table, after known inheritance coverage has been removed.
24
+ * @returns Ownership facts that share the lifetime of the parsed pass.
25
+ * @internal
26
+ */
27
+ export declare function createShaderDeclarationOwnership(symbolTable: SymbolTable<SymbolInfo>): ShaderDeclarationOwnershipInfo;
28
+ /**
29
+ * Tests whether one cross-scope conflict is specifically deferred, preserving known partial-coverage errors.
30
+ * @param facts - Ownership facts from the completed table.
31
+ * @param left - One surviving declaration.
32
+ * @param right - Another surviving declaration.
33
+ * @returns Whether variant-time selection replaces static coexistence rejection for this pair.
34
+ * @internal
35
+ */
36
+ export declare function isDeferredDeclarationPair(facts: ShaderDeclarationOwnershipInfo, left: SymbolInfo, right: SymbolInfo): boolean;
@@ -0,0 +1,18 @@
1
+ import type { ReferenceResolutionSnapshot } from "../parser/ShaderInfo";
2
+ import { ASTNode } from "../parser/AST";
3
+ import { FnSymbol, SymbolInfo } from "../parser/symbolTable";
4
+ import type { ShaderDeclarationOwnershipInfo } from "./ShaderDeclarationOwnership";
5
+ /**
6
+ * Checks that a deferred struct can satisfy references retained from another declaration owner.
7
+ *
8
+ * This is an admission proof over parser identities, not a macro-variant selector. Only referenced
9
+ * fields are compared: removing an unused field or discarding its only consumer remains supported.
10
+ * An unreferenced ordinary struct cannot replace an emitted interface declaration.
11
+ * @param ownership - The completed pass's declaration families and static coverage facts.
12
+ * @param entries - All possible stage-entry declarations.
13
+ * @param roles - Interface roles assigned to exact struct declarations by the entry signatures.
14
+ * @param snapshots - Existing call-site projections of macro member-owner identities.
15
+ * @returns Struct owners whose selected fields or interface roles cannot satisfy a surviving consumer.
16
+ * @internal
17
+ */
18
+ export declare function findUnsupportedStructOwnership(ownership: ShaderDeclarationOwnershipInfo, entries: readonly FnSymbol[], roles: ReadonlyMap<ASTNode.StructSpecifier, string>, snapshots: readonly ReferenceResolutionSnapshot[]): readonly SymbolInfo[];
@@ -0,0 +1,4 @@
1
+ export * from "./ShaderClueIR";
2
+ export * from "./ShaderCoreInfo";
3
+ export * from "./ShaderBuiltinSemantic";
4
+ export * from "./ShaderDeclarationOwnership";
@@ -0,0 +1,5 @@
1
+ import { Grammar } from "../parser/Grammar";
2
+ import SemanticAnalyzer from "../parser/SemanticAnalyzer";
3
+ declare const createGrammar: () => Grammar;
4
+ declare const addTranslationRule: (sa: SemanticAnalyzer) => void;
5
+ export { addTranslationRule, createGrammar };
@@ -0,0 +1,27 @@
1
+ import { Grammar } from "../parser/Grammar";
2
+ import { NoneTerminal, Terminal } from "../parser/GrammarSymbol";
3
+ import { StateActionTable, StateGotoTable } from "./types";
4
+ /**
5
+ * The [LALR1](https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/140%20LALR%20Parsing.pdf) Parser generator
6
+ */
7
+ export declare class LALR1 {
8
+ readonly firstSetMap: Map<NoneTerminal, Set<Terminal>>;
9
+ readonly followSetMap: Map<NoneTerminal, Set<Terminal>>;
10
+ readonly actionTable: StateActionTable;
11
+ readonly gotoTable: StateGotoTable;
12
+ private grammar;
13
+ /** For circle detect */
14
+ private _firstSetNTStack;
15
+ constructor(grammar: Grammar);
16
+ generate(): void;
17
+ private buildStateTable;
18
+ private _extendState;
19
+ private _closure;
20
+ private _extendStateItem;
21
+ private _inferNextState;
22
+ /** Resolve shift-reduce/reduce-reduce conflict detect */
23
+ private _addAction;
24
+ private static _isKnownShiftPreferred;
25
+ private computeFirstSet;
26
+ private _computeFirstSetForNT;
27
+ }
@@ -0,0 +1,9 @@
1
+ import { NoneTerminal, GrammarSymbol } from "../parser/GrammarSymbol";
2
+ export default class Production {
3
+ private static _id;
4
+ static pool: Map<number, Production>;
5
+ readonly goal: NoneTerminal;
6
+ readonly derivation: GrammarSymbol[];
7
+ readonly id: number;
8
+ constructor(goal: NoneTerminal, derivation: GrammarSymbol[]);
9
+ }
@@ -0,0 +1,20 @@
1
+ import { Terminal } from "../parser/GrammarSymbol";
2
+ import Production from "./Production";
3
+ import StateItem from "./StateItem";
4
+ export default class State {
5
+ static closureMap: Map<string /** state mapKey */, State>;
6
+ static pool: Map<number, State>;
7
+ static _id: number;
8
+ readonly id: number;
9
+ readonly cores: Set<StateItem>;
10
+ private _items;
11
+ get items(): Set<StateItem>;
12
+ closured: boolean;
13
+ get needReInfer(): boolean;
14
+ private _stateItemPool;
15
+ static create(cores: StateItem[]): State;
16
+ static getMapKey(cores: StateItem[]): string;
17
+ private constructor();
18
+ getStateItemMapKey(production: Production, position: number): string;
19
+ createStateItem(production: Production, position: number, lookaheadSet?: Iterable<Terminal>): StateItem;
20
+ }
@@ -0,0 +1,20 @@
1
+ import { Terminal } from "../parser/GrammarSymbol";
2
+ import Production from "./Production";
3
+ export default class StateItem {
4
+ static _id: number;
5
+ readonly production: Production;
6
+ readonly position: number;
7
+ readonly lookaheadSet: Set<Terminal>;
8
+ readonly id: number;
9
+ _needReInfer: boolean;
10
+ get needReInfer(): boolean;
11
+ set needReInfer(v: boolean);
12
+ get curSymbol(): import("../parser/GrammarSymbol").GrammarSymbol;
13
+ get nextSymbol(): import("../parser/GrammarSymbol").GrammarSymbol;
14
+ constructor(production: Production, position: number, lookahead: Iterable<Terminal>);
15
+ addLookahead(ts: Iterable<Terminal>): void;
16
+ symbolByOffset(offset: number): import("../parser/GrammarSymbol").GrammarSymbol;
17
+ canReduce(): boolean;
18
+ advance(): StateItem;
19
+ toString(): string;
20
+ }
@@ -0,0 +1,29 @@
1
+ import { TreeNode } from "../parser/AST";
2
+ import { TranslationRule } from "../parser/SemanticAnalyzer";
3
+ import { NoneTerminal, GrammarSymbol } from "../parser/GrammarSymbol";
4
+ import Production from "./Production";
5
+ import { ActionInfo } from "./types";
6
+ type ASTNodeConstructor = new () => TreeNode;
7
+ export default class GrammarUtils {
8
+ static isTerminal(sm: GrammarSymbol): boolean;
9
+ static toString(sm: GrammarSymbol): string;
10
+ static createProductionWithOptions(goal: NoneTerminal, options: GrammarSymbol[][],
11
+ /** the ast node */
12
+ astType?: ASTNodeConstructor): [GrammarSymbol[], TranslationRule][];
13
+ /**
14
+ * Creates productions whose typed AST nodes are needed only by analyzer diagnostics.
15
+ * @param goal - Production goal symbol.
16
+ * @param options - Alternative right-hand sides.
17
+ * @param analyzerType - Typed node constructor used by analyzer parses.
18
+ * @returns Grammar productions with mode-specific translation rules.
19
+ * @internal
20
+ */
21
+ static createAnalyzerProductionWithOptions(goal: NoneTerminal, options: GrammarSymbol[][], analyzerType: ASTNodeConstructor): [GrammarSymbol[], TranslationRule][];
22
+ private static _createProductionWithOptions;
23
+ static addMapSetItem<K, T>(map: Map<K, Set<T>>, k: K, v: T): void;
24
+ static isSubSet<T>(sa: Set<T>, sb: Set<T>): boolean;
25
+ static isActionEqual(a: ActionInfo, b: ActionInfo): boolean;
26
+ static printAction(actionInfo: ActionInfo): string;
27
+ static printProduction(production: Production): string;
28
+ }
29
+ export {};
@@ -0,0 +1,2 @@
1
+ export { LALR1 } from "./LALR1";
2
+ export * from "./CFG";
@@ -0,0 +1,14 @@
1
+ import { NoneTerminal, Terminal } from "../parser/GrammarSymbol";
2
+ export type StateActionTable = Map<number /** state ID */, ActionTable>;
3
+ export type ActionTable = Map<Terminal, ActionInfo>;
4
+ export type StateGotoTable = Map<number /** state ID */, GotoTable>;
5
+ export type GotoTable = Map<NoneTerminal, number /** state ID */>;
6
+ export declare enum EAction {
7
+ Shift = 0,
8
+ Reduce = 1,
9
+ Accept = 2
10
+ }
11
+ export interface ActionInfo {
12
+ action: EAction;
13
+ target?: number;
14
+ }
@@ -0,0 +1,56 @@
1
+ import { type BranchSignature } from "../common/BaseToken";
2
+ import { Lexer } from "./Lexer";
3
+ /**
4
+ * Lexer variant that retains conditional facts required by the standalone analyzer.
5
+ * @internal
6
+ */
7
+ export declare class AnalyzerLexer extends Lexer {
8
+ private _conditionalFrames;
9
+ private _guardUndefBranches;
10
+ private _macroStates;
11
+ private _macroVersions;
12
+ private _pendingGuardUndef;
13
+ private _pendingOpaqueConditional;
14
+ private _pendingArm;
15
+ tokenize(): Generator<import("../common/BaseToken").BaseToken<number>, import("../common/BaseToken").BaseToken<number>, unknown>;
16
+ private _pushOpaqueConditional;
17
+ private _advanceOpaqueConditionalArm;
18
+ private _advanceElseArm;
19
+ private _openConditional;
20
+ private _closeConditional;
21
+ private _finishCurrentArm;
22
+ private _mergeMacroStates;
23
+ private _resolveCondition;
24
+ private _expandDefinedMacroConditions;
25
+ /** Resolve a macro test from the symbolic state produced by preceding define and undef directives. */
26
+ private _resolveDefinedMacroCondition;
27
+ private _branchCondition;
28
+ private _bindCondition;
29
+ private _evaluateCondition;
30
+ private _assumeCondition;
31
+ private _applyMacroUndef;
32
+ private _applyMacroDefine;
33
+ private _markMacroMutation;
34
+ private _setMacroState;
35
+ private _macroState;
36
+ private _defaultMacroState;
37
+ private _macroVersion;
38
+ private _nextMacroVersion;
39
+ private _recordGuardUndef;
40
+ private _parseSimpleCondition;
41
+ private _toBranchCondition;
42
+ private static _conditionNames;
43
+ private static _conditionKey;
44
+ private static _sameCondition;
45
+ private static _combineConditions;
46
+ private static _collectConditionVersions;
47
+ private static _negateSimpleCondition;
48
+ private static _parseNumericLiteral;
49
+ private static _matchesComparison;
50
+ private static _cloneMacroStates;
51
+ private static _sameMacroState;
52
+ protected _isBranchReachable(branch: BranchSignature): boolean;
53
+ protected _registerMacroDefine(name: string, paramsLexeme: string | undefined, valueStart: number, valueEnd: number): void;
54
+ protected _sameDefinitionBranch(left: BranchSignature, right: BranchSignature): boolean;
55
+ protected _branchesOverlap(left: BranchSignature, right: BranchSignature): boolean;
56
+ }
@@ -0,0 +1,122 @@
1
+ import type { PreprocessorConditionalArm } from "../preprocessor/PreprocessorCondition";
2
+ import { BaseLexer } from "../common/BaseLexer";
3
+ import { BaseToken, BranchConstraint, BranchSignature } from "../common/BaseToken";
4
+ import { MacroDefineList } from "../Preprocessor";
5
+ import type { ParserObjectPool } from "../ParserObjectPool";
6
+ import { type PreprocessorExpressionParseResult } from "@galacean/engine-design";
7
+ /**
8
+ * The Lexer of Shader Compiler
9
+ */
10
+ export declare class Lexer extends BaseLexer {
11
+ macroDefineList: MacroDefineList;
12
+ protected readonly _conditionalArms?: ReadonlyMap<number, PreprocessorConditionalArm>;
13
+ /** Complete expression trees retained for the instruction encoder. @internal */
14
+ readonly preprocessorExpressions: Map<string, PreprocessorExpressionParseResult>;
15
+ private static _lexemeTable;
16
+ private _needScanMacroConditionExpression;
17
+ protected _inMacroDefineValue: boolean;
18
+ private _macroDefineExpectsNameToken;
19
+ private _macroDefineExpectsParamsToken;
20
+ private _currentMacroName;
21
+ private _currentMacroParamsLexeme;
22
+ private _currentMacroValueStart;
23
+ protected _branchStack: BranchConstraint[];
24
+ private _branchSnapshot;
25
+ protected _conditionalGroup: number;
26
+ protected _pendingBranchPushDefined: boolean | null;
27
+ private _pendingCodegenConditional;
28
+ private _codegenConditionalFrames;
29
+ private _pendingCodegenArm;
30
+ tokenize(): Generator<BaseToken<number>, BaseToken<number>, unknown>;
31
+ private _tokenizeForCodegen;
32
+ private _parseCodegenConstantCondition;
33
+ private static _isCodegenBranchReachable;
34
+ /** @internal */
35
+ protected _isBranchReachable(branch: BranchSignature): boolean;
36
+ /** @internal */
37
+ protected _sameDefinitionBranch(left: BranchSignature, right: BranchSignature): boolean;
38
+ /** @internal */
39
+ protected _branchesOverlap(left: BranchSignature, right: BranchSignature): boolean;
40
+ constructor(source: string, macroDefineList: MacroDefineList, objectPool?: ParserObjectPool, _conditionalArms?: ReadonlyMap<number, PreprocessorConditionalArm>);
41
+ scanToken(): BaseToken;
42
+ private _scanStringConst;
43
+ private _scanNumAfterDot;
44
+ private _scanUtilBreakLine;
45
+ private _scanDirectives;
46
+ /** True if the current char is an unescaped line break (ignoring `\` continuation). */
47
+ private _isAtLineBreak;
48
+ /**
49
+ * Walk a `#define` directive head once and produce everything both routing
50
+ * and registration need: name range, optional params range, value range,
51
+ * and whether the value parses as an `expression`.
52
+ *
53
+ * The replacement list is split into two paths:
54
+ *
55
+ * - **AST path** (`isExpression = true`): value parses as `expression`.
56
+ * Covers identifiers, literals, parenthesized sub-expressions, operator
57
+ * expressions, function calls, top-level comma lists (per C99 §6.10.3).
58
+ *
59
+ * - **Opaque path** (`isExpression = false`): every replacement list that
60
+ * cannot safely enter the expression grammar. Preprocessor replacement
61
+ * lists are token sequences, not GLSL expressions; fragments such as
62
+ * `#define ADD +` or `#define OPEN (` are valid and must be preserved.
63
+ *
64
+ * Returns `null` if the directive is malformed before the name.
65
+ */
66
+ private _peekMacroDefine;
67
+ /** GLSL type / qualifier keywords that aren't expression starters when standing alone.
68
+ * `true` / `false` are excluded — they're `primary_expression` literals.
69
+ * `#`-prefixed entries are excluded — they're preprocessor directive names. */
70
+ private static _isNonExpressionLeadingKeyword;
71
+ /**
72
+ * If `i` points at a `\` immediately followed by a newline (`\n`, `\r`, or
73
+ * `\r\n`), return the index just past the pair (a single atom in the C/GLSL
74
+ * preprocessor view). Otherwise return `i` unchanged. This is the single
75
+ * source of truth for line-continuation detection — callers along the
76
+ * directive-scanning path (`_skipNonSemantic`, `_scanUtilBreakLine`,
77
+ * `_scanMacroDefineParams`) all delegate here so the rule stays in one
78
+ * place.
79
+ */
80
+ private static _skipLineContinuation;
81
+ /**
82
+ * Pure positional version of "skip non-semantic characters within a single
83
+ * `#define` directive": spaces, tabs, `\` + newline line-continuation, block
84
+ * comments, line comments. A real `\n` (without preceding `\`) is *not*
85
+ * consumed — it terminates the directive — so callers can detect
86
+ * end-of-directive after this returns. Shared by `_peekMacroDefine` (peek
87
+ * path) and `_skipInlineSpaceAndComments` (consuming path) so both honor
88
+ * the same lexical view.
89
+ */
90
+ private static _skipNonSemantic;
91
+ /** Consuming wrapper around `_skipNonSemantic` operating on the lexer's
92
+ * current position. Used by the `#define`-value scan state machine. Goes
93
+ * through `advance(diff)` to keep the line/column counters in sync
94
+ * (advance walks the consumed slice and bumps `_line` on `\n`). */
95
+ private _skipInlineSpaceAndComments;
96
+ /**
97
+ * Capture a `(param1, param2, …)` block immediately after the macro name in a
98
+ * `#define` directive, producing a single `MACRO_DEFINE_PARAMS` token whose lexeme
99
+ * is the complete `(…)` text (including parens). Balanced parentheses are honored
100
+ * so the scanner doesn't terminate early on inner `()`. Newlines inside the
101
+ * parameter list are tolerated (rare; appears when the directive uses `\` line
102
+ * continuation), but any newline raises no special error here — it simply stops
103
+ * capture and parser handles the resulting token however it can.
104
+ */
105
+ private _scanMacroDefineParams;
106
+ /** Emit `MACRO_DEFINE_END` at the end of a `#define` value, consuming the newline. */
107
+ private _emitMacroDefineEnd;
108
+ protected _registerMacroDefine(name: string, paramsLexeme: string | undefined, valueStart: number, valueEnd: number): void;
109
+ protected _captureBranchSignature(): BranchSignature;
110
+ /** Render a `[start, end)` value range as space-separated significant chars,
111
+ * using the same comment / line-continuation rules `_skipNonSemantic`
112
+ * applies on the token-stream path. Used as the dedup key body. */
113
+ protected static _normalizeValueText(src: string, start: number, end: number): string;
114
+ private _scanMacroConditionExpression;
115
+ private _scanWord;
116
+ /** True iff at least one `#define <word>` is reachable from the current branch. */
117
+ private _isVisibleMacro;
118
+ private static _sameCodegenBranch;
119
+ private _scanNum;
120
+ private _scanFloatSuffix;
121
+ private _scanIntegerSuffix;
122
+ }
@@ -0,0 +1 @@
1
+ export * from "./Lexer";