Fix shaders parsing to skip comments in between special macros

This commit is contained in:
Wojtek Figat
2024-12-10 16:45:59 +01:00
parent 84c65b92d0
commit 04a3435200
3 changed files with 47 additions and 44 deletions

View File

@@ -66,10 +66,6 @@ void ShaderProcessing::Parser::init()
bool ShaderProcessing::Parser::process()
{
const Token defineToken("#define");
const Separator singleLineCommentSeparator('/', '/');
const Separator multiLineCommentSeparator('/', '*');
// TODO: split parsing into two phrases: comments preprocessing and parsing
// Read whole source code
Token token;
@@ -77,36 +73,8 @@ bool ShaderProcessing::Parser::process()
{
text.ReadToken(&token);
// Single line comment
if (token.Separator == singleLineCommentSeparator)
{
// Read whole line
text.ReadLine();
}
// Multi line comment
else if (token.Separator == multiLineCommentSeparator)
{
// Read tokens until end sequence
char prev = ' ';
char c;
while (text.CanRead())
{
c = text.ReadChar();
if (prev == '*' && c == '/')
{
break;
}
prev = c;
}
// Check if comment is valid (has end before file end)
if (!text.CanRead())
{
OnWarning(TEXT("Missing multiline comment ending"));
}
}
// Preprocessor definition
else if (token == defineToken)
// Preprocessor definition
if (token == defineToken)
{
// Skip
text.ReadLine();