Implements parsing of function calling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
#include "Parser.hpp"
|
||||
#include "ParsedStatements/ParsedStatement.hpp"
|
||||
#include "UnaryOperatorKind.hpp"
|
||||
#include "BinaryOperatorKind.hpp"
|
||||
#include "TypedVariableIdentifier.hpp"
|
||||
@@ -137,7 +138,8 @@ ParsedStatement *Parser::ParseFunctionDeclaration(IToken *current) {
|
||||
|
||||
ParsedExpression* Parser::ParseExpression(IToken* current){
|
||||
auto expression = this -> ParseBinaryExpression(current, OperatorPrecedence::No);
|
||||
if (this -> Peek() -> GetKind() == TokenKind::OpenParenthesis){
|
||||
while (this -> Peek() -> GetKind() == TokenKind::OpenParenthesis){
|
||||
expression = this->ParseFunctionCallExpression(expression);
|
||||
//TODO: Function Evaluation
|
||||
}
|
||||
return expression;
|
||||
@@ -250,6 +252,28 @@ ParsedExpression *Parser::ParseParenthesizedExpression(IToken *current) {
|
||||
return new ParenthesizedExpression(expression, start, closeToken->GetEndPosition() - start);
|
||||
}
|
||||
|
||||
ParsedExpression *Parser::ParseFunctionCallExpression(ParsedExpression* functionExpression) {
|
||||
this -> Next(); // consume the open parenthesis
|
||||
vector<ParsedExpression*> 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());
|
||||
}
|
||||
}
|
||||
auto start = functionExpression->GetStartPosition();
|
||||
return new FunctionCallExpression(functionExpression, parameters, start, peeked->GetEndPosition() - start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user