diff options
author | Carlos Maniero <carlos@maniero.me> | 2023-05-02 23:45:52 -0300 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-05-03 22:52:41 +0200 |
commit | b18a53b912ae66ad2bb23985640c9fac56ced358 (patch) | |
tree | eadc80d198b9ddab5f1fe77377e1249a3ec3259f /test/parser_test.c | |
parent | e623c701d2ef41cf4993590e2932c7538c83fc54 (diff) |
parser: Split block into small functions
Since it is possible to look a future token without consuming it, it was
possible to split the block parser into small chunks of code.
There is the performance drawback, because now the parser makes multiple
lookups to the same token. However IMO that it is not a big concern
given the small computation required to get a token. Also it can be
easily addressed by computing all token in advance.
Memory Leak:
During the refactor I found some extra memory leaks related to not
released scopes. So then, more than just printing a message I introduced
an assert on scope.c to make sure developers will get this feedback asap
because our testing framework suppress messages from stderr when the
test passes.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
Diffstat (limited to 'test/parser_test.c')
-rw-r--r-- | test/parser_test.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/test/parser_test.c b/test/parser_test.c index 3f814c6..ce77828 100644 --- a/test/parser_test.c +++ b/test/parser_test.c @@ -210,7 +210,7 @@ test_parse_basic_syntax_errors(const MunitParameter params[], void *user_data_or assert_parser_error("main() i32 { return 42; }", "expected ':' but got 'TOKEN_NAME'"); assert_parser_error("main(): { return 42; }", "expected 'TOKEN_NAME' but got '{'"); assert_parser_error("main(): i32 return 42; }", "expected '{' but got 'return'"); - assert_parser_error("main(): i32 { 42; }", "expected 'TOKEN_NAME' but got 'TOKEN_NUMBER'"); + assert_parser_error("main(): i32 { 42; }", "unexpected token 'TOKEN_NUMBER' value='42'"); assert_parser_error("main(): i32 { return; }", "unexpected '; (;)' token"); assert_parser_error("main(): i32 { return 42;", "expected '}' but got end of file"); assert_parser_error("main(): beff { return 42; }", "type 'beff' is not defined"); @@ -218,7 +218,7 @@ test_parse_basic_syntax_errors(const MunitParameter params[], void *user_data_or assert_parser_error("main(): i32 { b = 1; return b; }", "trying to assign 'b' before defining it."); // FIXME: once function calls are implemented, this error should inform that // neither a variable or function call was found. - assert_parser_error("main(): i32 { oxi 42; }", "expected 'TOKEN_NAME' but got 'TOKEN_NUMBER'"); + assert_parser_error("main(): i32 { oxi 42; }", "unexpected token 'TOKEN_NAME' value='oxi'"); return MUNIT_OK; } |