Skip to content

Commit

Permalink
let read token handle errors and keep the removed token peek (caused …
Browse files Browse the repository at this point in the history
…incorrect code parsing)
  • Loading branch information
ArielG-NV committed Mar 11, 2024
1 parent 3f1731a commit e1ab20f
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7760,12 +7760,6 @@ namespace Slang

static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/)
{
#define readElseErrorIfNextTokenIsNotAssign(modToCheck) \
{ \
if (parser->tokenReader.peekTokenType() != TokenType::OpAssign) { parser->diagnose(modToCheck->loc, Diagnostics::unexpectedTokenExpectedTokenType, parser->tokenReader.peekTokenType(), TokenType::OpAssign); break;} \
else { parser->ReadToken(TokenType::OpAssign); } \
}

ModifierListBuilder listBuilder;

GLSLLayoutLocalSizeAttribute* numThreadsAttrib = nullptr;
Expand Down Expand Up @@ -7823,7 +7817,7 @@ namespace Slang
listBuilder.add(attr);
}

readElseErrorIfNextTokenIsNotAssign(attr);
parser->ReadToken(TokenType::OpAssign);

// If the token asked for is not returned found will put in recovering state, and return token found
Token valToken = parser->ReadToken(TokenType::IntegerLiteral);
Expand Down Expand Up @@ -7869,15 +7863,15 @@ namespace Slang
// Special handling for GLSLLayoutModifier
if (auto glslModifier = as<GLSLParsedLayoutModifier>(modifier))
{
readElseErrorIfNextTokenIsNotAssign(modifier);
parser->ReadToken(TokenType::OpAssign);
glslModifier->valToken = parser->ReadToken(TokenType::IntegerLiteral);
}
//Special handling for GLSLOffsetLayoutAttribute to add to the byte offset tracker at a binding location
else if (auto glslOffset = as<GLSLOffsetLayoutAttribute>(modifier))
{
if (auto binding = listBuilder.find<GLSLBindingAttribute>())
{
readElseErrorIfNextTokenIsNotAssign(modifier);
parser->ReadToken(TokenType::OpAssign);
glslOffset->offset = int64_t(getIntegerLiteralValue(parser->ReadToken(TokenType::IntegerLiteral)));
parser->setBindingOffset(binding->binding, glslOffset->offset);
}
Expand All @@ -7901,8 +7895,6 @@ namespace Slang
listBuilder.add(parser->astBuilder->create<GLSLLayoutModifierGroupEnd>());

return listBuilder.getFirst();

#undef readElseErrorIfNextTokenIsNotAssign
}

static NodeBase* parseBuiltinTypeModifier(Parser* parser, void* /*userData*/)
Expand Down

0 comments on commit e1ab20f

Please sign in to comment.