Skip to content

Commit

Permalink
feat: opt code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sway007 committed Aug 27, 2024
1 parent e4d267c commit 077e009
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions packages/shader-lab/src/contentParser/ShaderContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export class ShaderContentParser {
scanner.scanText(";");
const sm = this._symbolTable.lookup({ type: stateToken.type, ident: variable.lexeme });
if (!sm?.value) {
let error: CompilationError;
// #if _EDITOR
throw new CompilationError(
`Invalid ${stateToken.lexeme} variable: ${variable.lexeme}`,
Expand Down Expand Up @@ -232,27 +231,31 @@ export class ShaderContentParser {
scanner.scanText("]");
scanner.scanText("=");
} else if (op.lexeme !== "=") {
const error = new CompilationError(
// #if _EDITOR
throw new CompilationError(
`Invalid syntax, expect character '=', but got ${op.lexeme}`,
scanner.curPosition,
scanner.source
);
error.log();
throw error;
// #else
throw new Error(`Invalid syntax, expect character '=', but got ${op.lexeme}`);
// #endif
}
renderStateProp += idx;
}

renderStateProp = state + renderStateProp;
const renderStateElementKey = RenderStateDataKey[renderStateProp];
if (renderStateElementKey == undefined) {
const error = new CompilationError(
// #if _EDITOR
throw new CompilationError(
`Invalid render state element ${renderStateProp}`,
scanner.curPosition,
scanner.source
);
error.log();
throw error;
// #else
throw new Error(`Invalid render state element ${renderStateProp}`);
// #endif
}

scanner.skipCommentsAndSpace();
Expand Down Expand Up @@ -282,13 +285,15 @@ export class ShaderContentParser {
const engineTypeProp = scanner.scanToken();
value = ShaderContentParser._engineType[token.lexeme]?.[engineTypeProp.lexeme];
if (value == undefined) {
const error = new CompilationError(
// #if _EDITOR
throw new CompilationError(
`Invalid engine constant: ${token.lexeme}.${engineTypeProp.lexeme}`,
scanner.curPosition,
scanner.source
);
error.log();
throw error;
// #else
throw new Error(`Invalid engine constant: ${token.lexeme}.${engineTypeProp.lexeme}`);
// #endif
}
} else {
value = token.lexeme;
Expand All @@ -308,9 +313,11 @@ export class ShaderContentParser {
scanner.scanText(";");
const value = ShaderContentParser._engineType.RenderQueueType[word.lexeme];
if (value == undefined) {
const error = new CompilationError(`Invalid render queue ${word.lexeme}`, word.location, scanner.source);
error.log();
throw error;
// #if _EDITOR
throw new CompilationError(`Invalid render queue ${word.lexeme}`, word.location, scanner.source);
// #else
throw new Error(`Invalid render queue ${word.lexeme}`);
// #endif
}
const key = RenderStateDataKey.RenderQueueType;
ret.renderStates.constantMap[key] = value;
Expand Down Expand Up @@ -456,9 +463,11 @@ export class ShaderContentParser {
scanner.scanText("=");
const entry = scanner.scanToken();
if (ret[word.lexeme]) {
const error = new CompilationError("reassign main entry", scanner.curPosition, scanner.source);
error.log();
throw error;
// #if _EDITOR
throw new CompilationError("reassign main entry", scanner.curPosition, scanner.source);
// #else
throw new Error("reassign main entry");
// #endif
}
const key = word.type === EKeyword.GS_VertexShader ? "vertexEntry" : "fragmentEntry";
ret[key] = entry.lexeme;
Expand Down

0 comments on commit 077e009

Please sign in to comment.