Skip to content

Commit

Permalink
Updated Parser for multiple variable declaration on single statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Oct 4, 2024
1 parent 06143bb commit 9888659
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ std::unique_ptr<ASTNode> Parser::stmtTest() {

std::unique_ptr<ASTNode> Parser::stmtVal() {
std::string nativePath = "";
this->consume("val");
Token address = this->consume("val");

if(this->isNext("(", TokenType::OPERATOR)) {
this->consume("(");
Expand All @@ -882,21 +882,29 @@ std::unique_ptr<ASTNode> Parser::stmtVal() {
this->consume(")");
}

std::unique_ptr<ASTNode> value;
Token address = this->consume(TokenType::IDENTIFIER);
std::map<Token, std::unique_ptr<ASTNode>> declarations;
while(!this->isNext(";", TokenType::OPERATOR)) {
if(!declarations.empty())
this->consume(",");

std::unique_ptr<ASTNode> value;
Token variable = this->consume(TokenType::IDENTIFIER);

if(nativePath == "") {
this->consume("=");
value = this->expression();
if(nativePath == "") {
this->consume("=");
value = this->expression();
}
else value = std::make_unique<NilLiteralExpression>(
std::make_unique<Token>(variable)
);

declarations.insert({variable, std::move(value)});
}
else value = std::make_unique<NilLiteralExpression>(
std::make_unique<Token>(address)
);

this->consume(";");
return std::make_unique<VariableDeclarationStatement>(
std::make_unique<Token>(address),
std::move(value),
std::move(declarations),
nativePath
);
}
Expand Down

0 comments on commit 9888659

Please sign in to comment.