This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user