Implements return statement
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-07 15:23:13 +02:00
parent f143e526ab
commit f4a3918947
12 changed files with 145 additions and 18 deletions

View File

@@ -33,6 +33,7 @@ ParsedStatement* Parser::ParseStatement(IToken* current){
switch (currentKind){
case TokenKind ::LocalKeyword: return this -> ParseAssignment(current);
case TokenKind ::FunctionKeyword: return this -> ParseFunctionDeclaration(current);
case TokenKind ::ReturnKeyword: return this->ParseReturnStatement(current);
default: break;
}
if (this->Peek()->GetKind() == TokenKind::AssignmentToken){
@@ -134,7 +135,13 @@ ParsedStatement *Parser::ParseFunctionDeclaration(IToken *current) {
}
auto functionIdentifier = ((IdentifierToken*) functionIdentifierToken)->Value;
return new ParsedFunctionDeclarationStatement(HashedString(functionIdentifier), parameters, (ParsedBlockStatement*)block, start, block->GetEndPosition() - start);
}
ParsedStatement* Parser::ParseReturnStatement(IToken* current){
//TODO: if next token is on a different line, don't parse it as return expression.
auto expression = this->ParseExpression(this->Next());
auto start = current->GetStartPosition();
return new ParsedReturnStatement(expression, start, expression->GetEndPosition() - start);
}
ParsedExpression* Parser::ParseExpression(IToken* current){