Fixes parse scope consuming non-scope items.

This commit is contained in:
Deukhoofd 2020-11-01 13:20:00 +01:00
parent 6e0aa65625
commit f54029b278
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 13 additions and 9 deletions

View File

@ -262,27 +262,30 @@ namespace MalachScript::Parser {
return true; return true;
} }
bool Parser::ParseScope(std::vector<Identifier>& scope, const LexToken*& currentToken) { bool Parser::ParseScope(std::vector<Identifier>& scope, const LexToken*& currentToken) {
if (currentToken->GetKind() == LexTokenKind::ColonColonSymbol) { const auto* current = currentToken;
if (current->GetKind() == LexTokenKind::ColonColonSymbol) {
scope.emplace_back(); scope.emplace_back();
PROGRESS_TOKEN(currentToken); PROGRESS_TOKEN(current);
} }
Identifier identifier; Identifier identifier;
if (ParseIdentifier(identifier, currentToken)) { if (ParseIdentifier(identifier, current)) {
const auto* n = currentToken->GetNext().get(); PROGRESS_TOKEN(current);
currentToken = n;
scope.push_back(identifier); scope.push_back(identifier);
if (current->GetKind() != LexTokenKind::ColonColonSymbol){
return false;
}
} else { } else {
return false; return false;
} }
while (currentToken != nullptr && currentToken->GetKind() == LexTokenKind::ColonColonSymbol) { while (current != nullptr && current->GetKind() == LexTokenKind::ColonColonSymbol) {
PROGRESS_TOKEN(currentToken); PROGRESS_TOKEN(current);
const auto* n = currentToken; const auto* n = current;
if (ParseIdentifier(identifier, n)) { if (ParseIdentifier(identifier, n)) {
PROGRESS_TOKEN(n); PROGRESS_TOKEN(n);
if (n->GetKind() == LexTokenKind::ColonColonSymbol) { if (n->GetKind() == LexTokenKind::ColonColonSymbol) {
currentToken = n; current = n;
scope.push_back(identifier); scope.push_back(identifier);
} else { } else {
break; break;
@ -293,6 +296,7 @@ namespace MalachScript::Parser {
} }
} }
// TODO: Handle generics in script class name. // TODO: Handle generics in script class name.
currentToken = current;
return true; return true;
} }