From e75d13f509b969c99c5c4ef552a5364a1e312720 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 14 Sep 2019 10:45:32 +0200 Subject: [PATCH] Fixed return followed by end keyword log an error --- src/Parser/Parser.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 20ab8b8..ce25104 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -128,7 +128,7 @@ namespace Porygon::Parser { return new ParsedBlockStatement(statements, start); } auto end = 0; - if (statements.size() > 0){ + if (!statements.empty()){ end = statements.back()->GetEndPosition(); } return new ParsedBlockStatement(statements, start, end - start); @@ -214,7 +214,11 @@ namespace Porygon::Parser { if (startLine != this -> ScriptData -> Diagnostics -> GetLineFromPosition(this -> Peek() -> GetStartPosition())){ return new ParsedReturnStatement(nullptr, start, current->GetLength()); } - auto expression = this->ParseExpression(this->Next()); + auto n = this->Peek()->GetKind(); + ParsedExpression* expression = nullptr; + if (n != TokenKind::EndKeyword && + n != TokenKind::EndOfFile) + expression = this->ParseExpression(this->Next()); return new ParsedReturnStatement(expression, start, expression->GetEndPosition() - start); }