Implements while loop
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-28 13:28:39 +02:00
parent f7a6ff7d87
commit df79489d4d
9 changed files with 142 additions and 29 deletions

View File

@@ -46,6 +46,8 @@ namespace Porygon::Parser {
return this->ParseIfStatement(current);
case TokenKind ::ForKeyword:
return this->ParseForStatement();
case TokenKind ::WhileKeyword:
return this->ParseWhileStatement(current);
case TokenKind ::BreakKeyword:
return new ParsedBreakStatement(current->GetStartPosition(), current -> GetLength());
default:
@@ -312,6 +314,19 @@ namespace Porygon::Parser {
}
}
ParsedStatement *Parser::ParseWhileStatement(const IToken *current) {
auto condition = this -> ParseExpression(this -> Next());
auto doKeyword = this -> Next();
if (doKeyword -> GetKind() != TokenKind::DoKeyword){
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, doKeyword->GetStartPosition(),
doKeyword->GetLength());
return new ParsedBadStatement(doKeyword->GetStartPosition(), doKeyword->GetLength());
}
auto block = this -> ParseBlock({TokenKind ::EndKeyword});
auto start = current -> GetStartPosition();
return new ParsedWhileStatement(condition, block, start, block->GetEndPosition() - start);
}
/////////////////
// Expressions //
/////////////////
@@ -597,5 +612,4 @@ namespace Porygon::Parser {
return new ParsedTableExpression(block, start, closeToken->GetEndPosition() - start);
}
}
}