From f54029b27891cb475b465977a9b9fb14eb62f521 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 1 Nov 2020 13:20:00 +0100 Subject: [PATCH] Fixes parse scope consuming non-scope items. --- src/Parser/Parser.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 407a256..84fa1e4 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -262,27 +262,30 @@ namespace MalachScript::Parser { return true; } bool Parser::ParseScope(std::vector& scope, const LexToken*& currentToken) { - if (currentToken->GetKind() == LexTokenKind::ColonColonSymbol) { + const auto* current = currentToken; + if (current->GetKind() == LexTokenKind::ColonColonSymbol) { scope.emplace_back(); - PROGRESS_TOKEN(currentToken); + PROGRESS_TOKEN(current); } Identifier identifier; - if (ParseIdentifier(identifier, currentToken)) { - const auto* n = currentToken->GetNext().get(); - currentToken = n; + if (ParseIdentifier(identifier, current)) { + PROGRESS_TOKEN(current); scope.push_back(identifier); + if (current->GetKind() != LexTokenKind::ColonColonSymbol){ + return false; + } } else { return false; } - while (currentToken != nullptr && currentToken->GetKind() == LexTokenKind::ColonColonSymbol) { - PROGRESS_TOKEN(currentToken); - const auto* n = currentToken; + while (current != nullptr && current->GetKind() == LexTokenKind::ColonColonSymbol) { + PROGRESS_TOKEN(current); + const auto* n = current; if (ParseIdentifier(identifier, n)) { PROGRESS_TOKEN(n); if (n->GetKind() == LexTokenKind::ColonColonSymbol) { - currentToken = n; + current = n; scope.push_back(identifier); } else { break; @@ -293,6 +296,7 @@ namespace MalachScript::Parser { } } // TODO: Handle generics in script class name. + currentToken = current; return true; }