From e623c701d2ef41cf4993590e2932c7538c83fc54 Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Tue, 2 May 2023 23:45:51 -0300 Subject: parser: Use lookahead instead of consuming tokens Previously, during block declaration, the parser consumed the token which caused some parsers (such as return and variable declaration) to not be self-contained and to depend on the callee to start the parser. In this commit, I've refactored the parser to only look for future tokens using lookahead, and delegate the consumption to child parser functions. This results in a more modular and self-contained parser that improves the overall maintainability and readability of the code. Signed-off-by: Carlos Maniero --- test/parser_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/parser_test.c b/test/parser_test.c index 52437ce..3f814c6 100644 --- a/test/parser_test.c +++ b/test/parser_test.c @@ -67,7 +67,8 @@ test_parse_function(const MunitParameter params[], void *user_data_or_fixture) make_lexer_from_static_src(&lexer, "main(): i32 { \nreturn 42;\n }"); parser_init(&parser, &lexer, scope); ast_node_t *ast_function = parser_parse_function_declaration(&parser); - assert_true(ast_function != NULL); + + assert_not_null(ast_function); char actual[5]; -- cgit v1.2.3