Skip to content

Commit

Permalink
Parsing method for maybe and loop expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Sep 13, 2024
1 parent ba2e99d commit f9b5df7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions include/parser/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <ast/expression/CatchHandleExpression.hpp>
#include <ast/expression/DoWhileExpression.hpp>
#include <ast/expression/IfElseExpression.hpp>
#include <ast/expression/LoopExpression.hpp>
#include <ast/expression/MaybeExpression.hpp>
#include <ast/expression/NilLiteralExpression.hpp>
#include <ast/expression/NumberLiteralExpression.hpp>
#include <ast/expression/StringLiteralExpression.hpp>
Expand Down Expand Up @@ -212,6 +214,29 @@ class Parser {
);
}

std::unique_ptr<ASTNode> exprLoop() {
Token address = this->consume("loop");
this->consume("(");

std::unique_ptr<ASTNode> initial = this->expression();
this->consume(";");

std::unique_ptr<ASTNode> condition = this->expression();
this->consume(";");

std::unique_ptr<ASTNode> postexpr = this->expression();
this->consume(")");

std::unique_ptr<ASTNode> body = this->expression();
return std::make_unique<LoopExpression>(
std::make_unique<Token>(address),
std::move(initial),
std::move(condition),
std::move(postexpr),
std::move(body)
);
}

std::unique_ptr<ASTNode> exprIf() {
Token address = this->consume("if");
this->consume("(");
Expand Down Expand Up @@ -248,6 +273,10 @@ class Parser {
std::make_unique<Token>(this->consume("false")),
false
);
else if(this->isNext("maybe"))
expr = std::make_unique<MaybeExpression>(
std::make_unique<Token>(this->consume("maybe"))
);
else if(this->isNext("nil"))
expr = std::make_unique<NilLiteralExpression>(
std::make_unique<Token>(this->consume("nil"))
Expand Down

0 comments on commit f9b5df7

Please sign in to comment.