From 3643fbe6bb1a4fa88db62b24c7a67c3399d64086 Mon Sep 17 00:00:00 2001 From: Daniel Holden Date: Fri, 28 Aug 2015 19:20:39 +0100 Subject: [PATCH] Fixed bug in behaviour of counting parser. Removed changelog (git is the changelog). --- CHANGELOG.txt | 17 ----------------- README.md | 2 +- mpc.c | 18 ++++++++---------- tests/core.c | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 43 insertions(+), 32 deletions(-) delete mode 100644 CHANGELOG.txt diff --git a/CHANGELOG.txt b/CHANGELOG.txt deleted file mode 100644 index 9c7f2dc..0000000 --- a/CHANGELOG.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Oct. 17, 2014; Daniel Holden -- Reverted state to use long type - -# Oct. 16, 2014; Daniel Holden -- Removed comments describing changes -- Fixed warnings reported by gcc in test suite under the new compilation flags - -# Oct. 14, 2014; Dalton Woodard -- Fixed all compilation warnings in `mpc.h` and `mpc.c`; both now compile successfully on OS X under clang-600.0.51 -and gcc 4.9.1 with the following flags: -``` --std=c11 -O3 -g -Werror -Wall -Wextra -Wformat=2 -Wshadow -Wno-format-nonliteral -Wcast-align -Wwrite-strings --Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wswitch-default -``` -- Changed compilation standard from ansi to c11. -- Further small changes in source (documented in-line). - diff --git a/README.md b/README.md index d094d39..c2d6192 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Micro Parser Combinators ======================== -Version 0.8.5 +Version 0.8.6 About diff --git a/mpc.c b/mpc.c index 2869ee4..26985f5 100644 --- a/mpc.c +++ b/mpc.c @@ -1112,19 +1112,17 @@ int mpc_parse_input(mpc_input_t *i, mpc_parser_t *init, mpc_result_t *final) { case MPC_TYPE_COUNT: if (st == 0) { mpc_input_mark(i); MPC_CONTINUE(st+1, p->data.repeat.x); } if (st > 0) { - if (mpc_stack_peekr(stk, &r)) { - MPC_CONTINUE(st+1, p->data.repeat.x); + if (!mpc_stack_peekr(stk, &r)) { + mpc_stack_popr(stk, &r); + mpc_stack_popr_out_single(stk, st-1, p->data.repeat.dx); + mpc_input_rewind(i); + MPC_FAILURE(mpc_err_count(r.error, p->data.repeat.n)); } else { - if (st != (p->data.repeat.n+1)) { - mpc_stack_popr(stk, &r); - mpc_stack_popr_out_single(stk, st-1, p->data.repeat.dx); - mpc_input_rewind(i); - MPC_FAILURE(mpc_err_count(r.error, p->data.repeat.n)); + if (st < p->data.repeat.n) { + MPC_CONTINUE(st+1, p->data.repeat.x); } else { - mpc_stack_popr(stk, &r); - mpc_stack_err(stk, r.error); mpc_input_unmark(i); - MPC_SUCCESS(mpc_stack_merger_out(stk, st-1, p->data.repeat.f)); + MPC_SUCCESS(mpc_stack_merger_out(stk, st, p->data.repeat.f)); } } } diff --git a/tests/core.c b/tests/core.c index 516e2ae..de4a3e6 100644 --- a/tests/core.c +++ b/tests/core.c @@ -85,8 +85,38 @@ void test_strip(void) { } -void suite_core(void) { - pt_add_test(test_ident, "Test Ident", "Suite Core"); - pt_add_test(test_maths, "Test Maths", "Suite Core"); - pt_add_test(test_strip, "Test Strip", "Suite Core"); +void test_repeat(void) { + + int success; + mpc_result_t r; + mpc_parser_t *p = mpc_count(3, mpcf_strfold, mpc_digit(), free); + + success = mpc_parse("test", "046", p, &r); + PT_ASSERT(success); + PT_ASSERT_STR_EQ(r.output, "046"); + free(r.output); + + success = mpc_parse("test", "046aa", p, &r); + PT_ASSERT(success); + PT_ASSERT_STR_EQ(r.output, "046"); + free(r.output); + + success = mpc_parse("test", "04632", p, &r); + PT_ASSERT(success); + PT_ASSERT_STR_EQ(r.output, "046"); + free(r.output); + + success = mpc_parse("test", "04", p, &r); + PT_ASSERT(!success); + mpc_err_delete(r.error); + + mpc_delete(p); + +} + +void suite_core(void) { + pt_add_test(test_ident, "Test Ident", "Suite Core"); + pt_add_test(test_maths, "Test Maths", "Suite Core"); + pt_add_test(test_strip, "Test Strip", "Suite Core"); + pt_add_test(test_repeat, "Test Repeat", "Suite Core"); }