Implemented generic for loops
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
|
||||
Reference in New Issue
Block a user