diff options
| author | Yong He <yonghe@outlook.com> | 2025-10-01 09:23:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-01 16:23:48 +0000 |
| commit | 5793b6d864b572e464dd5e17dc842e99d13d310d (patch) | |
| tree | 18c67a633385f5db5d9fc673d99ee4b39d42e705 /source/slang | |
| parent | 4d241f2ccc2b07673615e94ea8e99060cf2da66c (diff) | |
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.
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-parser.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
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; |
