From 9520b98f2e4b54bb8af7ad1fcb151b55489a5169 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 14 Sep 2019 11:05:10 +0200 Subject: [PATCH] Better handling of return followed by end keyword --- src/Parser/Parser.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index ce25104..d54c143 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -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); }