Skip to content

Commit

Permalink
Fixed bug with mpca_lang statement delete
Browse files Browse the repository at this point in the history
  • Loading branch information
orangeduck committed May 5, 2014
1 parent b12b12c commit 6af8360
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -ansi -pedantic -Wall -Wno-overlength-strings -Werror -g
CFLAGS = -ansi -pedantic -Wall -Wno-overlength-strings -Werror -O3 -g

TESTS = $(wildcard tests/*.c)
EXAMPLES = $(wildcard examples/*.c)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Micro Parser Combinators
========================

Version 0.8.3
Version 0.8.5


About
Expand Down
2 changes: 1 addition & 1 deletion examples/book.doge
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wow c so language such book
wow c so language such book
51 changes: 27 additions & 24 deletions mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,59 +482,63 @@ static int mpc_input_terminated(mpc_input_t *i) {

static char mpc_input_getc(mpc_input_t *i) {

char c;
char c = '\0';

switch (i->type) {

case MPC_INPUT_STRING: c = i->string[i->state.pos]; break;
case MPC_INPUT_FILE: c = fgetc(i->file); break;
case MPC_INPUT_STRING: return i->string[i->state.pos];
case MPC_INPUT_FILE: c = fgetc(i->file); return c;
case MPC_INPUT_PIPE:

if (!i->buffer) { c = getc(i->file); break; }
if (!i->buffer) { c = getc(i->file); return c; }

if (i->buffer && mpc_input_buffer_in_range(i)) {
c = mpc_input_buffer_get(i);
return c;
} else {
c = getc(i->file);
return c;
}

break;

default: return c;
}

return c;
}

static char mpc_input_peekc(mpc_input_t *i) {

char c;
char c = '\0';

switch (i->type) {
case MPC_INPUT_STRING: return i->string[i->state.pos];
case MPC_INPUT_FILE:

c = fgetc(i->file);
if (feof(i->file)) { return '\0'; }

c = fgetc(i->file);
fseek(i->file, -1, SEEK_CUR);
break;
return c;

case MPC_INPUT_PIPE:

if (feof(i->file)) { return '\0'; }

if (!i->buffer) { c = getc(i->file); ungetc(c, i->file); break; }
if (!i->buffer) {
c = getc(i->file);
if (feof(i->file)) { return '\0'; }
ungetc(c, i->file);
return c;
}

if (i->buffer && mpc_input_buffer_in_range(i)) {
return mpc_input_buffer_get(i);
} else {
c = getc(i->file); ungetc(c, i->file);
break;
c = getc(i->file);
if (feof(i->file)) { return '\0'; }
ungetc(c, i->file);
return c;
}


default: return c;
}

return c;

}

static int mpc_input_failure(mpc_input_t *i, char c) {
Expand Down Expand Up @@ -2016,17 +2020,15 @@ mpc_parser_t *mpc_re(const char *re) {
Base = mpc_new("base");
Range = mpc_new("range");

mpc_define(Regex, mpc_and(2,
mpcf_re_or,
mpc_define(Regex, mpc_and(2, mpcf_re_or,
Term,
mpc_maybe(mpc_and(2, mpcf_snd_free, mpc_char('|'), Regex, free)),
(mpc_dtor_t)mpc_delete
));

mpc_define(Term, mpc_many(mpcf_re_and, Factor));

mpc_define(Factor, mpc_and(2,
mpcf_re_repeat,
mpc_define(Factor, mpc_and(2, mpcf_re_repeat,
Base,
mpc_or(5,
mpc_char('*'), mpc_char('+'), mpc_char('?'),
Expand Down Expand Up @@ -2833,6 +2835,7 @@ static mpc_val_t *mpcaf_grammar_regex(mpc_val_t *x, void *s) {
return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "regex"));
}

/* Should this just use `isdigit` instead */
static int is_number(const char* s) {
int i;
for (i = 0; i < strlen(s); i++) { if (!strchr("0123456789", s[i])) { return 0; } }
Expand Down Expand Up @@ -3068,7 +3071,7 @@ static mpc_err_t *mpca_lang_st(mpc_input_t *i, mpca_grammar_st_t *st) {

mpc_define(Stmt, mpc_and(5, mpca_stmt_afold,
mpc_tok(mpc_ident()), mpc_maybe(mpc_tok(mpc_string_lit())), mpc_sym(":"), Grammar, mpc_sym(";"),
free, free, mpc_soft_delete
free, free, free, mpc_soft_delete
));

mpc_define(Grammar, mpc_and(2, mpcaf_grammar_or,
Expand Down

0 comments on commit 6af8360

Please sign in to comment.