diff options
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index c8a990ab1..f6d85ade9 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -854,6 +854,8 @@ namespace Slang { parser->ReadToken(TokenType::Scope); } + if (parser->LookAheadToken(TokenType::CompletionRequest)) + return parser->ReadToken(); const Token firstIdentifier = parser->ReadToken(TokenType::Identifier); if (initialTokenType != TokenType::Scope && parser->tokenReader.peekTokenType() != TokenType::Scope) @@ -942,6 +944,7 @@ namespace Slang break; parser->ReadToken(TokenType::Comma); + } if (hasDoubleBracket) @@ -1133,6 +1136,7 @@ namespace Slang auto decl = parser->astBuilder->create<ImportDecl>(); decl->scope = parser->currentScope; + decl->startLoc = parser->tokenReader.peekLoc(); if (peekTokenType(parser) == TokenType::StringLiteral) { @@ -1162,7 +1166,7 @@ namespace Slang decl->moduleNameAndLoc = moduleNameAndLoc; } - + decl->endLoc = parser->tokenReader.peekLoc(); parser->ReadToken(TokenType::Semicolon); return decl; @@ -1538,7 +1542,10 @@ namespace Slang _parseOptSemantics(parser, decl); decl->body = parseOptBody(parser); - + if (auto block = as<BlockStmt>(decl->body)) + { + decl->closingSourceLoc = block->closingSourceLoc; + } parser->PopScope(); return decl; @@ -2686,6 +2693,13 @@ namespace Slang semantic->name = parser->ReadToken(TokenType::Identifier); return semantic; } + else if (parser->LookAheadToken(TokenType::CompletionRequest)) + { + HLSLSimpleSemantic* semantic = parser->astBuilder->create<HLSLSimpleSemantic>(); + parser->FillPosition(semantic); + semantic->name = parser->ReadToken(); + return semantic; + } else { // expect an identifier, just to produce an error message @@ -2966,6 +2980,9 @@ namespace Slang { InterfaceDecl* decl = parser->astBuilder->create<InterfaceDecl>(); parser->FillPosition(decl); + + AdvanceIf(parser, TokenType::CompletionRequest); + decl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); parseOptionalInheritanceClause(parser, decl); @@ -3147,6 +3164,9 @@ namespace Slang decl->body = parseOptBody(parser); + if (auto block = as<BlockStmt>(decl->body)) + decl->closingSourceLoc = block->closingSourceLoc; + parser->PopScope(); return decl; } @@ -3469,6 +3489,8 @@ namespace Slang decl->returnType = parser->ParseTypeExp(); } decl->body = parseOptBody(parser); + if (auto blockStmt = as<BlockStmt>(decl->body)) + decl->closingSourceLoc = blockStmt->closingSourceLoc; parser->PopScope(); return decl; }); @@ -3914,9 +3936,11 @@ namespace Slang ParseSquareBracketAttributes(this, &modifierLink); } + // Skip completion request token to prevent producing a type named completion request. + AdvanceIf(this, TokenType::CompletionRequest); + // TODO: support `struct` declaration without tag rs->nameAndLoc = expectIdentifier(this); - return parseOptGenericDecl(this, [&](GenericDecl*) { // We allow for an inheritance clause on a `struct` @@ -3931,6 +3955,9 @@ namespace Slang { ClassDecl* rs = astBuilder->create<ClassDecl>(); ReadToken("class"); + + AdvanceIf(this, TokenType::CompletionRequest); + FillPosition(rs); rs->nameAndLoc = expectIdentifier(this); @@ -3969,6 +3996,8 @@ namespace Slang // AdvanceIf(parser, "class"); + AdvanceIf(parser, TokenType::CompletionRequest); + parser->FillPosition(decl); decl->nameAndLoc = expectIdentifier(parser); @@ -5586,7 +5615,7 @@ namespace Slang return constExpr; } - + case TokenType::CompletionRequest: case TokenType::Identifier: { // We will perform name lookup here so that we can find syntax @@ -5608,7 +5637,7 @@ namespace Slang varExpr->scope = parser->currentScope; parser->FillPosition(varExpr); - auto nameAndLoc = expectIdentifier(parser); + auto nameAndLoc = NameLoc(parser->ReadToken()); varExpr->name = nameAndLoc.name; if(peekTokenType(parser) == TokenType::OpLess) @@ -5725,7 +5754,7 @@ namespace Slang parser->ReadToken(TokenType::Dot); parser->FillPosition(memberExpr); memberExpr->name = expectIdentifier(parser).name; - + if (peekTokenType(parser) == TokenType::OpLess) expr = maybeParseGenericApp(parser, memberExpr); else |
