From d385a9e3ee5246ebe224e12e1cff4809de508ff7 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 8 Jun 2019 16:30:23 +0200 Subject: [PATCH] Fix parametered functions skipping a token --- src/Binder/Binder.cpp | 1 + src/Parser/Parser.cpp | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Binder/Binder.cpp b/src/Binder/Binder.cpp index 2907239..440b500 100644 --- a/src/Binder/Binder.cpp +++ b/src/Binder/Binder.cpp @@ -100,6 +100,7 @@ BoundStatement *Binder::BindFunctionDeclarationStatement(ParsedStatement *statem auto type = make_shared(returnType, parameterTypes, parameterKeys); auto assignment = this->_scope->AssignVariable(identifier.GetHash(), type); if (assignment.GetResult() != VariableAssignmentResult::Ok){ + this -> _scriptData -> Diagnostics -> LogError(DiagnosticCode::CantAssignVariable, statement->GetStartPosition(), statement->GetLength()); return new BoundBadStatement(); } auto boundBlock = this -> BindBlockStatement(functionStatement->GetBlock()); diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index d91ba4a..146803a 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -195,6 +195,8 @@ ParsedExpression* Parser::ParseExpression(IToken* current){ } else { //TODO: index period expression } + if (this -> _position >= this->_tokens.size()) + break; peekKind = this->Peek()->GetKind(); } return expression; @@ -331,20 +333,23 @@ ParsedExpression *Parser::ParseFunctionCallExpression(ParsedExpression* function vector parameters; auto peeked = this -> Peek(); auto peekedKind = peeked->GetKind(); - while (peekedKind != TokenKind::CloseParenthesis){ - if (peekedKind == TokenKind ::EndOfFile){ - this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(), peeked->GetLength()); - return new BadExpression(peeked->GetStartPosition(), peeked->GetLength()); - } - parameters.push_back(this->ParseExpression(this->Next())); - peeked = this -> Next() ; - peekedKind = peeked->GetKind(); - if (peekedKind != TokenKind::CloseParenthesis && peekedKind != TokenKind::CommaToken){ - this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(), peeked->GetLength()); - return new BadExpression(peeked->GetStartPosition(), peeked->GetLength()); + if (peekedKind == TokenKind::CloseParenthesis){ + this->Next(); + } else{ + while (peekedKind != TokenKind::CloseParenthesis){ + if (peekedKind == TokenKind ::EndOfFile){ + this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(), peeked->GetLength()); + return new BadExpression(peeked->GetStartPosition(), peeked->GetLength()); + } + parameters.push_back(this->ParseExpression(this->Next())); + peeked = this -> Next() ; + peekedKind = peeked->GetKind(); + if (peekedKind != TokenKind::CloseParenthesis && peekedKind != TokenKind::CommaToken){ + this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(), peeked->GetLength()); + return new BadExpression(peeked->GetStartPosition(), peeked->GetLength()); + } } } - this -> Next(); auto start = functionExpression->GetStartPosition(); return new FunctionCallExpression(functionExpression, parameters, start, peeked->GetEndPosition() - start); }