From 77dbf3a5011566b4a6274b3cdfa075dd723642d3 Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Tue, 2 May 2023 23:45:49 -0300 Subject: Parser: Make the parser function return the ast_node In many situations, the parser is responsible for reserving memory for nodes, particularly during function body parsing. This commit introduces a new standard where parser functions not only allocate memory for ast_nodes, but also return them. In case of a parser error, a NULL pointer is returned. This standard will be extended to other parsers in future commits, ensuring consistency throughout the codebase. Signed-off-by: Carlos Maniero --- src/pipac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pipac.c') diff --git a/src/pipac.c b/src/pipac.c index 2041218..e3caec1 100644 --- a/src/pipac.c +++ b/src/pipac.c @@ -67,9 +67,9 @@ main(int argc, char **argv) parser_t parser; parser_init(&parser, &lexer, scope); - ast_node_t *func = ast_node_new(); + ast_node_t *func = parser_parse_function_declaration(&parser); - if (!parser_parse_function_declaration(&parser, func)) { + if (func == NULL) { parser_print_errors(&parser); return EXIT_FAILURE; } -- cgit v1.2.3