Better handling of return followed by end keyword

This commit is contained in:
Deukhoofd 2019-09-14 11:05:10 +02:00
parent e75d13f509
commit 9520b98f2e
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 6 additions and 5 deletions

View File

@ -209,16 +209,17 @@ namespace Porygon::Parser {
}
ParsedStatement *Parser::ParseReturnStatement(const Token *current) {
auto n = this->Peek()->GetKind();
auto start = current->GetStartPosition();
if (n == TokenKind::EndKeyword || n == TokenKind::EndOfFile){
return new ParsedReturnStatement(nullptr, start, current->GetLength());
}
auto startLine = this -> ScriptData -> Diagnostics ->GetLineFromPosition(start);
if (startLine != this -> ScriptData -> Diagnostics -> GetLineFromPosition(this -> Peek() -> GetStartPosition())){
return new ParsedReturnStatement(nullptr, start, current->GetLength());
}
auto n = this->Peek()->GetKind();
ParsedExpression* expression = nullptr;
if (n != TokenKind::EndKeyword &&
n != TokenKind::EndOfFile)
expression = this->ParseExpression(this->Next());
ParsedExpression* expression = this->ParseExpression(this->Next());
return new ParsedReturnStatement(expression, start, expression->GetEndPosition() - start);
}