diff options
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index bca493780..6d2abef49 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -147,9 +147,14 @@ namespace Slang Token ReadToken(); Token ReadToken(TokenType type); - Token ReadToken(const char * string); - bool LookAheadToken(TokenType type, int offset = 0); - bool LookAheadToken(const char * string, int offset = 0); + Token ReadToken(const char* string); + + bool LookAheadToken(TokenType type); + bool LookAheadToken(const char* string); + + bool LookAheadToken(TokenType type, int offset); + bool LookAheadToken(const char* string, int offset); + void parseSourceFile(ModuleDecl* program); Decl* ParseStruct(); ClassDecl* ParseClass(); @@ -537,7 +542,7 @@ namespace Slang } } - bool Parser::LookAheadToken(const char * string, int offset) + bool Parser::LookAheadToken(const char* string, int offset) { TokenReader r = tokenReader; for (int ii = 0; ii < offset; ++ii) @@ -556,6 +561,17 @@ namespace Slang return r.peekTokenType() == type; } + bool Parser::LookAheadToken(TokenType type) + { + return tokenReader.peekTokenType() == type; + } + + bool Parser::LookAheadToken(const char* string) + { + const auto& token = tokenReader.peekToken(); + return token.type == TokenType::Identifier && token.getContent() == string; + } + // Consume a token and return true it if matches, otherwise false bool AdvanceIf(Parser* parser, TokenType tokenType) { @@ -1291,8 +1307,15 @@ namespace Slang { parser->ReadToken(TokenType::OpLess); parser->genericDepth++; - while (!parser->LookAheadToken(TokenType::OpGreater)) + for (;;) { + const TokenType tokenType = parser->tokenReader.peekTokenType(); + if (tokenType == TokenType::OpGreater || + tokenType == TokenType::EndOfFile) + { + break; + } + AddMember(decl, ParseGenericParamDecl(parser, decl)); if (parser->LookAheadToken(TokenType::OpGreater)) |
