summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-parser.cpp')
-rw-r--r--source/slang/slang-parser.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 68d06714d..493e707c2 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -557,6 +557,16 @@ namespace Slang
return false;
}
+ bool AdvanceIf(Parser* parser, TokenType tokenType, Token* outToken)
+ {
+ if (parser->LookAheadToken(tokenType))
+ {
+ *outToken = parser->ReadToken();
+ return true;
+ }
+ return false;
+ }
+
// Consume a token and return true it if matches, otherwise false
bool AdvanceIf(Parser* parser, char const* text)
{
@@ -590,6 +600,24 @@ namespace Slang
return false;
}
+ bool AdvanceIfMatch(Parser* parser, TokenType tokenType, Token* outToken)
+ {
+ // If we've run into a syntax error, but haven't recovered inside
+ // the block, then try to recover here.
+ if (parser->isRecovering)
+ {
+ TryRecoverBefore(parser, tokenType);
+ }
+ if (AdvanceIf(parser, tokenType, outToken))
+ return true;
+ if (parser->tokenReader.peekTokenType() == TokenType::EndOfFile)
+ {
+ *outToken = parser->ReadToken(tokenType);
+ return true;
+ }
+ return false;
+ }
+
NodeBase* parseTypeDef(Parser* parser, void* /*userData*/)
{
TypeDefDecl* typeDefDecl = parser->astBuilder->create<TypeDefDecl>();
@@ -3925,7 +3953,9 @@ namespace Slang
{
FillPosition(blockStatement);
}
- while (!AdvanceIfMatch(this, TokenType::RBrace))
+
+ Token closingBraceToken;
+ while (!AdvanceIfMatch(this, TokenType::RBrace, &closingBraceToken))
{
auto stmt = ParseStatement();
if(stmt)
@@ -3952,6 +3982,9 @@ namespace Slang
}
PopScope();
+ // Save the closing braces source loc
+ blockStatement->closingSourceLoc = closingBraceToken.loc;
+
if(!body)
{
body = astBuilder->create<EmptyStmt>();