forked from Misaki/GhostEngine
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.
72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
namespace Ghost.Shader.Compiler.Parser;
|
|
|
|
internal static class ParseUtility
|
|
{
|
|
public static List<Token> ParseFunctionArguments(ref TokenStreamSlice stream, TokenType tokenType)
|
|
{
|
|
var args = new List<Token>();
|
|
stream.Expect(TokenType.LParen);
|
|
|
|
while (!stream.Peek().type.Equals(TokenType.RParen))
|
|
{
|
|
var argToken = stream.Expect(tokenType);
|
|
args.Add(argToken);
|
|
|
|
if (stream.Peek().type == TokenType.Comma)
|
|
{
|
|
stream.Consume();
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
stream.Expect(TokenType.RParen);
|
|
return args;
|
|
}
|
|
|
|
public static FunctionCallDeclaration ParseFunction(ref TokenStreamSlice stream, TokenType tokenType)
|
|
{
|
|
var functionToken = stream.Expect(TokenType.Identifier);
|
|
var args = ParseFunctionArguments(ref stream, tokenType);
|
|
stream.Expect(TokenType.Semicolon);
|
|
|
|
return new FunctionCallDeclaration
|
|
{
|
|
name = functionToken,
|
|
arguments = args
|
|
};
|
|
}
|
|
|
|
public static bool TrySliceLine(ref TokenStreamSlice stream, out TokenStreamSlice lineStream)
|
|
{
|
|
var length = 0;
|
|
if (!stream.TryPeek(out var nextToken))
|
|
{
|
|
lineStream = default;
|
|
return false;
|
|
}
|
|
|
|
while (!nextToken.Match(TokenType.Semicolon) && !nextToken.Match(TokenType.RBrace))
|
|
{
|
|
length++;
|
|
|
|
if (!stream.TryPeek(length, out nextToken))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (length > 0)
|
|
{
|
|
lineStream = stream.Slice(length);
|
|
stream.Consume(); // Consume the semicolon
|
|
return true;
|
|
}
|
|
|
|
lineStream = default;
|
|
return false;
|
|
}
|
|
}
|