extracted the parsing of the function parameters
into it's own function (will be useful for the parsing of the parameters in the function calls)
This commit is contained in:
@@ -248,6 +248,27 @@ namespace parser {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<ast::identifier*> parser::parse_function_parameters() {
|
||||||
|
std::vector<ast::identifier*> ret;
|
||||||
|
while (next.type != token::type::RPAREN
|
||||||
|
&& expect_next(token::type::IDENTIFIER)) {
|
||||||
|
ret.push_back(parse_identifier());
|
||||||
|
if (next.type == token::type::RPAREN)
|
||||||
|
break;
|
||||||
|
if (!expect_next(token::type::COMMA))
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (current.type == token::type::COMMA
|
||||||
|
&& next.type == token::type::RPAREN) {
|
||||||
|
next_error(token::type::IDENTIFIER);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (!expect_next(token::type::RPAREN))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ast::function_literal* parser::parse_function() {
|
ast::function_literal* parser::parse_function() {
|
||||||
TRACE_FUNCTION;
|
TRACE_FUNCTION;
|
||||||
ast::function_literal* ret = new ast::function_literal(current);
|
ast::function_literal* ret = new ast::function_literal(current);
|
||||||
@@ -256,27 +277,7 @@ namespace parser {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (next.type != token::type::RPAREN
|
ret->parameters = parse_function_parameters();
|
||||||
&& expect_next(token::type::IDENTIFIER)) {
|
|
||||||
ret->parameters.push_back(parse_identifier());
|
|
||||||
if (next.type == token::type::RPAREN)
|
|
||||||
break;
|
|
||||||
if (!expect_next(token::type::COMMA)) {
|
|
||||||
delete ret;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (current.type == token::type::COMMA
|
|
||||||
&& next.type == token::type::RPAREN) {
|
|
||||||
next_error(token::type::IDENTIFIER);
|
|
||||||
delete ret;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expect_next(token::type::RPAREN)) {
|
|
||||||
delete ret;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expect_next(token::type::LBRACE)) {
|
if (!expect_next(token::type::LBRACE)) {
|
||||||
delete ret;
|
delete ret;
|
||||||
|
@@ -60,6 +60,7 @@ namespace parser {
|
|||||||
ast::identifier* parse_identifier();
|
ast::identifier* parse_identifier();
|
||||||
ast::integer_literal* parse_integer();
|
ast::integer_literal* parse_integer();
|
||||||
ast::boolean_literal* parse_boolean();
|
ast::boolean_literal* parse_boolean();
|
||||||
|
std::vector<ast::identifier*> parse_function_parameters();
|
||||||
ast::function_literal* parse_function();
|
ast::function_literal* parse_function();
|
||||||
ast::prefix_expr* parse_prefix_expr();
|
ast::prefix_expr* parse_prefix_expr();
|
||||||
ast::expression* parse_grouped_expr();
|
ast::expression* parse_grouped_expr();
|
||||||
|
Reference in New Issue
Block a user