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;
}
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();
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;
}