diff --git a/src/parsers/many.c b/src/parsers/many.c index 071e3fcd2d30ed35f4622962751ebc63bea3d37c..77b9dd8be220d92eac36b18ddbcd2fe263945448 100644 --- a/src/parsers/many.c +++ b/src/parsers/many.c @@ -92,22 +92,17 @@ static void desugar_many(HAllocator *mm__, HCFStack *stk__, void *env) { // TODO: refactor this. HRepeat *repeat = (HRepeat*)env; if (!repeat->min_p) { - assert(!"Unreachable"); + // count is an exact count. + assert(repeat->sep == NULL); HCFS_BEGIN_CHOICE() { HCFS_BEGIN_SEQ() { - for (size_t i = 0; i < repeat->count; i++) { - if (i != 0 && repeat->sep != NULL) - HCFS_DESUGAR(repeat->sep); // Should be ignored. + for (size_t i = 0; i < repeat->count; i++) HCFS_DESUGAR(repeat->p); - } } HCFS_END_SEQ(); } HCFS_END_CHOICE(); return; } - if(repeat->count > 1) { - assert_message(0, "'h_repeat_n' is not context-free, can't be desugared"); - return; - } + assert(repeat->count <= 1); /* many(A) => Ma -> A Mar diff --git a/src/t_parser.c b/src/t_parser.c index 18e117487e4e3f49b39736934e41d1cbcaf4cbf7..7e4ff8293990adbb642a5b7b54f8b743466a2654 100644 --- a/src/t_parser.c +++ b/src/t_parser.c @@ -934,6 +934,7 @@ void register_parser_tests(void) { g_test_add_data_func("/core/parser/llk/choice", GINT_TO_POINTER(PB_LLk), test_choice); g_test_add_data_func("/core/parser/llk/many", GINT_TO_POINTER(PB_LLk), test_many); g_test_add_data_func("/core/parser/llk/many1", GINT_TO_POINTER(PB_LLk), test_many1); + g_test_add_data_func("/core/parser/llk/repeat_n", GINT_TO_POINTER(PB_LLk), test_repeat_n); g_test_add_data_func("/core/parser/llk/optional", GINT_TO_POINTER(PB_LLk), test_optional); g_test_add_data_func("/core/parser/llk/sepBy", GINT_TO_POINTER(PB_LLk), test_sepBy); g_test_add_data_func("/core/parser/llk/sepBy1", GINT_TO_POINTER(PB_LLk), test_sepBy1); @@ -1020,6 +1021,7 @@ void register_parser_tests(void) { g_test_add_data_func("/core/parser/lalr/choice", GINT_TO_POINTER(PB_LALR), test_choice); g_test_add_data_func("/core/parser/lalr/many", GINT_TO_POINTER(PB_LALR), test_many); g_test_add_data_func("/core/parser/lalr/many1", GINT_TO_POINTER(PB_LALR), test_many1); + g_test_add_data_func("/core/parser/lalr/repeat_n", GINT_TO_POINTER(PB_LALR), test_repeat_n); g_test_add_data_func("/core/parser/lalr/optional", GINT_TO_POINTER(PB_LALR), test_optional); g_test_add_data_func("/core/parser/lalr/sepBy", GINT_TO_POINTER(PB_LALR), test_sepBy); g_test_add_data_func("/core/parser/lalr/sepBy1", GINT_TO_POINTER(PB_LALR), test_sepBy1); @@ -1066,6 +1068,7 @@ void register_parser_tests(void) { g_test_add_data_func("/core/parser/glr/choice", GINT_TO_POINTER(PB_GLR), test_choice); g_test_add_data_func("/core/parser/glr/many", GINT_TO_POINTER(PB_GLR), test_many); g_test_add_data_func("/core/parser/glr/many1", GINT_TO_POINTER(PB_GLR), test_many1); + g_test_add_data_func("/core/parser/glr/repeat_n", GINT_TO_POINTER(PB_GLR), test_repeat_n); g_test_add_data_func("/core/parser/glr/optional", GINT_TO_POINTER(PB_GLR), test_optional); g_test_add_data_func("/core/parser/glr/sepBy", GINT_TO_POINTER(PB_GLR), test_sepBy); g_test_add_data_func("/core/parser/glr/sepBy1", GINT_TO_POINTER(PB_GLR), test_sepBy1);