diff options
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 6401b3d06..0efa6a4b3 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -1859,53 +1859,46 @@ static Stmt* parseOptBody(Parser* parser) } } - if (parser->getStage() == ParsingStage::Decl) - { - // If we are at the initial parsing stage, just collect the tokens - // without actually parsing them. - if (peekTokenType(parser) != TokenType::LBrace) - { - return parser->parseBlockStatement(); - } - auto unparsedStmt = parser->astBuilder->create<UnparsedStmt>(); - unparsedStmt->currentScope = parser->currentScope; - unparsedStmt->outerScope = parser->outerScope; - unparsedStmt->sourceLanguage = parser->getSourceLanguage(); - unparsedStmt->isInVariadicGenerics = parser->isInVariadicGenerics; - parser->FillPosition(unparsedStmt); - List<Token>& tokens = unparsedStmt->tokens; - int braceDepth = 0; - for (;;) + // If we are at the initial parsing stage, just collect the tokens + // without actually parsing them. + if (peekTokenType(parser) != TokenType::LBrace) + { + return parser->parseBlockStatement(); + } + auto unparsedStmt = parser->astBuilder->create<UnparsedStmt>(); + unparsedStmt->currentScope = parser->currentScope; + unparsedStmt->outerScope = parser->outerScope; + unparsedStmt->sourceLanguage = parser->getSourceLanguage(); + unparsedStmt->isInVariadicGenerics = parser->isInVariadicGenerics; + parser->FillPosition(unparsedStmt); + List<Token>& tokens = unparsedStmt->tokens; + int braceDepth = 0; + for (;;) + { + auto token = parser->ReadToken(); + if (token.type == TokenType::EndOfFile) { - auto token = parser->ReadToken(); - if (token.type == TokenType::EndOfFile) - { - break; - } - if (token.type == TokenType::LBrace) - { - braceDepth++; - } - else if (token.type == TokenType::RBrace) - { - braceDepth--; - } - tokens.add(token); - if (braceDepth == 0) - { - break; - } + break; + } + if (token.type == TokenType::LBrace) + { + braceDepth++; + } + else if (token.type == TokenType::RBrace) + { + braceDepth--; + } + tokens.add(token); + if (braceDepth == 0) + { + break; } - Token eofToken; - eofToken.type = TokenType::EndOfFile; - eofToken.loc = parser->tokenReader.peekLoc(); - tokens.add(eofToken); - return unparsedStmt; } - - // If we are in the second stage of parsing, then we need to actually - // parse the block statement for real. - return parser->parseBlockStatement(); + Token eofToken; + eofToken.type = TokenType::EndOfFile; + eofToken.loc = parser->tokenReader.peekLoc(); + tokens.add(eofToken); + return unparsedStmt; } /// Complete parsing of a function using traditional (C-like) declarator syntax @@ -5500,7 +5493,6 @@ static EnumCaseDecl* parseEnumCaseDecl(Parser* parser) static Decl* parseEnumDecl(Parser* parser) { EnumDecl* decl = parser->astBuilder->create<EnumDecl>(); - parser->ReadToken("enum"); // HACK: allow the user to write `enum class` in case |
