Skip to content

Commit

Permalink
Parser function implementation for parsing 'size' expression
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Nov 21, 2024
1 parent 2f20c96 commit eac6c1a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/n8/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <n8/ast/expression/RegexExpression.hpp>
#include <n8/ast/expression/RenderExpression.hpp>
#include <n8/ast/expression/StringLiteralExpression.hpp>
#include <n8/ast/expression/SizeExpression.hpp>
#include <n8/ast/expression/TypeExpression.hpp>
#include <n8/ast/expression/UnaryExpression.hpp>
#include <n8/ast/expression/UnlessExpression.hpp>
Expand Down Expand Up @@ -433,6 +434,16 @@ std::shared_ptr<ASTNode> Parser::exprRender() {
);
}

std::shared_ptr<ASTNode> Parser::exprSize() {
Token address = this->consume("size");
std::shared_ptr<ASTNode> expression = this->expression();

return std::make_shared<SizeExpression>(
std::make_shared<Token>(address),
std::move(expression)
);
}

std::shared_ptr<ASTNode> Parser::exprType() {
Token address = this->consume("type");
std::shared_ptr<ASTNode> expression = this->expression();
Expand Down Expand Up @@ -592,6 +603,8 @@ std::shared_ptr<ASTNode> Parser::exprPrimary() {
expression = this->exprFunctionDecl();
else if(this->isNext("type", TokenType::KEYWORD))
expression = this->exprType();
else if(this->isNext("size", TokenType::KEYWORD))
expression = this->exprSize();
else if(this->isNext("parallel", TokenType::KEYWORD))
expression = this->exprParallel();
else if(this->isNext("val", TokenType::KEYWORD))
Expand Down

0 comments on commit eac6c1a

Please sign in to comment.