From 5793b6d864b572e464dd5e17dc842e99d13d310d Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 1 Oct 2025 09:23:48 -0700 Subject: Misc parser improvements. (#8563) - Fix bug parsing multiple link-time structs on the same line. Closes #8553. - Fix bug parsing anonymous struct type as function return type in modern syntax. Closes #8558 - Support semantics on modern style param/var declarations. --- source/slang/slang-parser.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index eb1671aa7..c225ff4ee 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -4250,6 +4250,9 @@ static void parseModernVarDeclBaseCommon(Parser* parser, VarDeclBase* decl) decl->type = parser->ParseTypeExp(); } + auto modifiers = _parseOptSemantics(parser); + _addModifiers(decl, modifiers); + if (AdvanceIf(parser, TokenType::OpAssign)) { decl->initExpr = parser->ParseInitExpr(); @@ -4351,6 +4354,8 @@ static NodeBase* parseFuncDecl(Parser* parser, void* /*userData*/) { parser->PushScope(decl); parseModernParamList(parser, decl); + auto funcScope = parser->currentScope; + parser->PopScope(); if (AdvanceIf(parser, "throws")) { decl->errorType = parser->ParseTypeExp(); @@ -4359,8 +4364,6 @@ static NodeBase* parseFuncDecl(Parser* parser, void* /*userData*/) { decl->returnType = parser->ParseTypeExp(); } - auto funcScope = parser->currentScope; - parser->PopScope(); maybeParseGenericConstraints(parser, genericParent); parser->PushScope(funcScope); decl->body = parseOptBody(parser); @@ -5509,10 +5512,16 @@ Decl* Parser::ParseStruct() rs->wrappedType = ParseTypeExp(); PushScope(rs); PopScope(); - ReadToken(TokenType::Semicolon); + if (!LookAheadToken(TokenType::Semicolon)) + { + this->diagnose( + this->tokenReader.peekToken().loc, + Diagnostics::unexpectedTokenExpectedTokenType, + "';'"); + } return rs; } - if (AdvanceIf(this, TokenType::Semicolon)) + if (LookAheadToken(TokenType::Semicolon)) { rs->hasBody = false; return rs; -- cgit v1.2.3