Skip to content

Commit

Permalink
Adjusted Parser class logic for dotted variadic names.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Oct 4, 2024
1 parent 52d6927 commit ee1e1ec
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,18 @@ std::unique_ptr<ASTNode> Parser::exprLiteral() {
);
}
else if(this->peek().getType() == TokenType::IDENTIFIER) {
Token var = this->consume(TokenType::IDENTIFIER);
while(this->isNext(".", TokenType::OPERATOR)) {
this->consume(".");
var.appendToImage(
"." +
this->consume(TokenType::IDENTIFIER)
.getImage()
);
}

expr = std::make_unique<VariableAccessExpression>(
std::make_unique<Token>(this->consume(TokenType::IDENTIFIER))
std::make_unique<Token>(var)
);

while(this->isNext("[", TokenType::OPERATOR)) {
Expand Down Expand Up @@ -566,8 +576,18 @@ std::unique_ptr<ASTNode> Parser::exprPrimary() {
else if(this->isNext("[", TokenType::OPERATOR))
expression = this->exprArray();
else if(this->peek().getType() == TokenType::IDENTIFIER) {
Token var = this->consume(TokenType::IDENTIFIER);
while(this->isNext(".", TokenType::OPERATOR)) {
this->consume(".");
var.appendToImage(
"." +
this->consume(TokenType::IDENTIFIER)
.getImage()
);
}

expression = std::make_unique<VariableAccessExpression>(
std::make_unique<Token>(this->consume(TokenType::IDENTIFIER))
std::make_unique<Token>(var)
);

while(this->isNext("[", TokenType::OPERATOR)) {
Expand Down Expand Up @@ -889,6 +909,14 @@ std::unique_ptr<ASTNode> Parser::stmtVal() {

std::unique_ptr<ASTNode> value;
Token variable = this->consume(TokenType::IDENTIFIER);
while(this->isNext(".", TokenType::OPERATOR)) {
this->consume(".");
variable.appendToImage(
"." +
this->consume(TokenType::IDENTIFIER)
.getImage()
);
}

if(nativePath == "") {
this->consume("=");
Expand Down

0 comments on commit ee1e1ec

Please sign in to comment.