From 7903686fe70fe2726fbcee86bfeb07cd96abd3ec Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Wed, 5 Jan 2022 21:50:50 +0100 Subject: [PATCH] Parser: Fix not setting error when -> is missing in dictionaries --- src/parser.c | 2 +- src/parser_test.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/parser.c b/src/parser.c index 5a46b25..9f95199 100644 --- a/src/parser.c +++ b/src/parser.c @@ -713,7 +713,7 @@ parse_dict( } if (p->token.type != APFL_TOK_MAPSTO) { - unread_token(p); + p->error = ERR_UNEXPECTED_TOKEN(p->token); goto error; } diff --git a/src/parser_test.c b/src/parser_test.c index bd2fd9e..bfc0f4f 100644 --- a/src/parser_test.c +++ b/src/parser_test.c @@ -1212,6 +1212,18 @@ TEST(err_statements_before_params, t) { destroy_parser_test(pt); } +TEST(err_dict_mapsto_missing, t) { + struct parser_test *pt = new_parser_test(t, "[foo -> bar, baz wtf -> xyu]"); + expect_error_of_type(pt, APFL_ERR_UNEXPECTED_TOKEN); + destroy_parser_test(pt); +} + +TEST(err_dict_mapsto_too_early, t) { + struct parser_test *pt = new_parser_test(t, "[foo -> bar -> baz]"); + expect_error_of_type(pt, APFL_ERR_UNEXPECTED_TOKEN); + destroy_parser_test(pt); +} + TESTS_BEGIN ADDTEST(empty), ADDTEST(hello_world), @@ -1242,4 +1254,6 @@ TESTS_BEGIN ADDTEST(err_mapsto_in_list), ADDTEST(err_expr_in_param), ADDTEST(err_statements_before_params), + ADDTEST(err_dict_mapsto_missing), + ADDTEST(err_dict_mapsto_too_early), TESTS_END