Fixed bug in behaviour of counting parser. Removed changelog (git is the changelog).

This commit is contained in:
Daniel Holden
2015-08-28 19:20:39 +01:00
parent 81abc6f115
commit 3643fbe6bb
4 changed files with 43 additions and 32 deletions

View File

@@ -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).

View File

@@ -1,7 +1,7 @@
Micro Parser Combinators
========================
Version 0.8.5
Version 0.8.6
About

12
mpc.c
View File

@@ -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);
} else {
if (st != (p->data.repeat.n+1)) {
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 {
mpc_stack_popr(stk, &r);
mpc_stack_err(stk, r.error);
if (st < p->data.repeat.n) {
MPC_CONTINUE(st+1, p->data.repeat.x);
} else {
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));
}
}
}

View File

@@ -85,8 +85,38 @@ void test_strip(void) {
}
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");
}