Implemented generic for loops
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-26 16:19:34 +02:00
parent cfd558b718
commit d86e9ba8ae
18 changed files with 325 additions and 44 deletions

View File

@@ -267,7 +267,47 @@ namespace Porygon::Parser {
}
ParsedStatement *Parser::ParseGenericForStatement(const IToken *current) {
return nullptr;
auto keyIdentifier = ((IdentifierToken*) current)->GetValue();
IdentifierToken* valueIdentifierToken = nullptr;
bool hasErrors = false;
auto next = this -> Next();
if (next -> GetKind() == TokenKind::CommaToken){
next = this -> Next();
if (next->GetKind() != TokenKind::Identifier){
hasErrors = true;
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
next->GetLength());
} else{
valueIdentifierToken = (IdentifierToken*) next;
next = this -> Next();
}
}
if (next->GetKind() != TokenKind::InKeyword && !hasErrors){
hasErrors = true;
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
next->GetLength());
}
auto expression = this -> ParseExpression(this -> Next());
next = this -> Next();
if (next -> GetKind() != TokenKind::DoKeyword && !hasErrors){
hasErrors = true;
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
next->GetLength());
}
auto block = this -> ParseBlock({TokenKind ::EndKeyword});
auto startPos = current->GetStartPosition();
if (hasErrors){
return new ParsedBadStatement(startPos, block -> GetEndPosition() - startPos);
} else{
auto valueIdentifier = HashedString::CreateLookup(0);
if (valueIdentifierToken != nullptr){
return new ParsedGenericForStatement(keyIdentifier, valueIdentifierToken -> GetValue(), expression, block,
startPos, block -> GetEndPosition() - startPos);
} else{
return new ParsedGenericForStatement(keyIdentifier, HashedString::CreateLookup(0), expression, block,
startPos, block -> GetEndPosition() - startPos);
}
}
}
/////////////////