forked from Misaki/GhostEngine
Refactoring Rendering backend
This commit is contained in:
58
Ghost.Shader/ParseUtility.cs
Normal file
58
Ghost.Shader/ParseUtility.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
namespace Ghost.Shader;
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user