Skip to content

Commit d828215

Browse files
committed
UPDATE:
1. fixed a major bug, due to which comma `,` becomes optional between separation of variables in parameters, func_calls and var_decls. Due to this bug `f(x, 2)` and `f(x 2)` were same, and comma becomes useless
1 parent 217161d commit d828215

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/parser/parser.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,24 @@ namespace horizon
9494
return nullptr;
9595
if (this->get_token().M_type == token_type::TOKEN_COMMA)
9696
this->post_advance();
97+
else if (this->get_token().M_type != token_type::TOKEN_RIGHT_PAREN)
98+
{
99+
this->handle_eof();
100+
horizon_errors::errors::parser_draw_error(horizon_errors::error_code::HORIZON_SYNTAX_ERROR, this->M_file, this->get_token(), {"unexpected token", this->get_token().M_lexeme.wrap("'"), "expected ')'"});
101+
return nullptr;
102+
}
97103
}
98104
else if (this->get_token().M_type == token_type::TOKEN_COMMA)
99105
{
100106
this->post_advance();
101107
temp_pair2.raw_second() = nullptr;
102108
}
109+
else if (this->get_token().M_type != token_type::TOKEN_RIGHT_PAREN)
110+
{
111+
this->handle_eof();
112+
horizon_errors::errors::parser_draw_error(horizon_errors::error_code::HORIZON_SYNTAX_ERROR, this->M_file, this->get_token(), {"unexpected token", this->get_token().M_lexeme.wrap("'"), "expected ')'"});
113+
return nullptr;
114+
}
103115
temp_vec.add(std::move(temp_pair2));
104116
}
105117
temp_vec.shrink_to_fit();
@@ -540,12 +552,24 @@ namespace horizon
540552
return nullptr;
541553
if (this->get_token().M_type == token_type::TOKEN_COMMA)
542554
this->post_advance();
555+
else if (this->get_token().M_type != token_type::TOKEN_SEMICOLON)
556+
{
557+
this->handle_eof();
558+
horizon_errors::errors::parser_draw_error(horizon_errors::error_code::HORIZON_SYNTAX_ERROR, this->M_file, this->get_token(), {"unexpected token", this->get_token().M_lexeme.wrap("'"), "expected ';'"});
559+
return nullptr;
560+
}
543561
}
544562
else if (this->get_token().M_type == token_type::TOKEN_COMMA)
545563
{
546564
this->post_advance();
547565
pair.raw_second() = nullptr;
548566
}
567+
else if (this->get_token().M_type != token_type::TOKEN_SEMICOLON)
568+
{
569+
this->handle_eof();
570+
horizon_errors::errors::parser_draw_error(horizon_errors::error_code::HORIZON_SYNTAX_ERROR, this->M_file, this->get_token(), {"unexpected token", this->get_token().M_lexeme.wrap("'"), "expected ';'"});
571+
return nullptr;
572+
}
549573
vec.add(std::move(pair));
550574
}
551575
vec.shrink_to_fit();
@@ -853,6 +877,14 @@ namespace horizon
853877
vec.add(std::move(temp));
854878
if (this->get_token().M_type == token_type::TOKEN_COMMA)
855879
this->post_advance();
880+
else if (this->get_token().M_type == token_type::TOKEN_RIGHT_PAREN)
881+
break;
882+
else
883+
{
884+
this->handle_eof();
885+
horizon_errors::errors::parser_draw_error(horizon_errors::error_code::HORIZON_SYNTAX_ERROR, this->M_file, this->get_token(), {"unexpected token", this->get_token().M_lexeme.wrap("'"), "expected ')'"});
886+
return nullptr;
887+
}
856888
}
857889
if (this->get_token().M_type == token_type::TOKEN_RIGHT_PAREN)
858890
this->post_advance();

0 commit comments

Comments
 (0)