Better handling of return followed by end keyword
This commit is contained in:
parent
e75d13f509
commit
9520b98f2e
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue