forked from Misaki/GhostEngine
Refactor and enhance graphics and audio systems
Updated target frameworks to .NET 10.0 across multiple projects for compatibility with the latest features. Refactored namespaces and introduced new classes for shader descriptors, FMOD integration, and DirectX 12 utilities using TerraFX. Replaced `Win32` bindings with TerraFX equivalents for DirectX 12. Added a C# wrapper for FMOD Studio API, including DSP and error handling. Enhanced entity queries, component storage, and query filters for better performance and type safety. Introduced new test projects and updated the solution structure. Added `meshoptimizer` bindings and integrated `meshoptimizer_native.dll`. Improved code readability, maintainability, and performance.
This commit is contained in:
84
Ghost.Shader/Compiler/Parser/KeywordsBlock.cs
Normal file
84
Ghost.Shader/Compiler/Parser/KeywordsBlock.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Ghost.Shader.Compiler.Parser;
|
||||
|
||||
namespace Ghost.Shader.Compiler.Parser;
|
||||
|
||||
internal class KeywordsBlock : IBlockParser<List<FunctionCallDeclaration>, List<KeywordsGroup>>
|
||||
{
|
||||
public static bool ShouldEnter(Token token)
|
||||
{
|
||||
return token.Match(TokenType.Keyword, TokenLexicon.KnownKeywords.KEYWORDS);
|
||||
}
|
||||
|
||||
public static List<FunctionCallDeclaration> Parse(TokenStreamSlice stream)
|
||||
{
|
||||
stream.Expect(TokenType.Keyword);
|
||||
stream.Expect(TokenType.LBrace);
|
||||
|
||||
var keywords = new List<FunctionCallDeclaration>();
|
||||
|
||||
var bodyStream = stream.Slice(stream.Remaining - 1);
|
||||
while (bodyStream.HasMore)
|
||||
{
|
||||
var keywordToken = bodyStream.Expect(TokenType.Identifier);
|
||||
var args = ParseUtility.ParseFunctionArguments(ref bodyStream, TokenType.Identifier);
|
||||
keywords.Add(new FunctionCallDeclaration { name = keywordToken, arguments = args });
|
||||
bodyStream.Expect(TokenType.Semicolon);
|
||||
}
|
||||
|
||||
stream.Expect(TokenType.RBrace);
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public static List<KeywordsGroup>? SemanticAnalysis(List<FunctionCallDeclaration>? syntax, List<ShaderError> errors)
|
||||
{
|
||||
if (syntax == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var keywords = new List<KeywordsGroup>(syntax.Count);
|
||||
foreach (var keyword in syntax)
|
||||
{
|
||||
if (keyword.arguments == null || keyword.arguments.Count == 0)
|
||||
{
|
||||
errors.Add(new ShaderError
|
||||
{
|
||||
message = $"Function '{keyword.name.lexeme}' must have at least one argument.",
|
||||
line = keyword.name.line,
|
||||
column = keyword.name.column
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
var group = new KeywordsGroup();
|
||||
switch (keyword.name.lexeme)
|
||||
{
|
||||
case TokenLexicon.KnownFunctions.DYNAMIC:
|
||||
group.type = KeywordType.Dynamic;
|
||||
break;
|
||||
case TokenLexicon.KnownFunctions.STATIC:
|
||||
group.type = KeywordType.Static;
|
||||
break;
|
||||
default:
|
||||
errors.Add(new ShaderError
|
||||
{
|
||||
message = $"Unknown function name '{keyword.name.lexeme}'.",
|
||||
line = keyword.name.line,
|
||||
column = keyword.name.column
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var arg in keyword.arguments)
|
||||
{
|
||||
group.keywords ??= new List<string>(keyword.arguments.Count);
|
||||
group.keywords.Add(arg.lexeme);
|
||||
}
|
||||
|
||||
keywords.Add(group);
|
||||
}
|
||||
|
||||
return keywords;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user