diff options
author | Carlos Maniero <carlos@maniero.me> | 2023-05-02 23:45:51 -0300 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-05-03 22:45:23 +0200 |
commit | e623c701d2ef41cf4993590e2932c7538c83fc54 (patch) | |
tree | e096ead143fe76d73df5789a3aee5b2b6358c602 /test | |
parent | 990f4d3e4c662c401a08e3704a39878fd6c1c1b6 (diff) |
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 <carlos@maniero.me>
Diffstat (limited to 'test')
-rw-r--r-- | test/parser_test.c | 3 |
1 files changed, 2 insertions, 1 deletions
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]; |