Fixed bug with mpca_lang statement delete
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
CC = gcc
|
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)
|
TESTS = $(wildcard tests/*.c)
|
||||||
EXAMPLES = $(wildcard examples/*.c)
|
EXAMPLES = $(wildcard examples/*.c)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
Micro Parser Combinators
|
Micro Parser Combinators
|
||||||
========================
|
========================
|
||||||
|
|
||||||
Version 0.8.3
|
Version 0.8.5
|
||||||
|
|
||||||
|
|
||||||
About
|
About
|
||||||
|
@@ -1 +1 @@
|
|||||||
wow c so language such book
|
wow c so language such book
|
51
mpc.c
51
mpc.c
@@ -482,59 +482,63 @@ static int mpc_input_terminated(mpc_input_t *i) {
|
|||||||
|
|
||||||
static char mpc_input_getc(mpc_input_t *i) {
|
static char mpc_input_getc(mpc_input_t *i) {
|
||||||
|
|
||||||
char c;
|
char c = '\0';
|
||||||
|
|
||||||
switch (i->type) {
|
switch (i->type) {
|
||||||
|
|
||||||
case MPC_INPUT_STRING: c = i->string[i->state.pos]; break;
|
case MPC_INPUT_STRING: return i->string[i->state.pos];
|
||||||
case MPC_INPUT_FILE: c = fgetc(i->file); break;
|
case MPC_INPUT_FILE: c = fgetc(i->file); return c;
|
||||||
case MPC_INPUT_PIPE:
|
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)) {
|
if (i->buffer && mpc_input_buffer_in_range(i)) {
|
||||||
c = mpc_input_buffer_get(i);
|
c = mpc_input_buffer_get(i);
|
||||||
|
return c;
|
||||||
} else {
|
} else {
|
||||||
c = getc(i->file);
|
c = getc(i->file);
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
default: return c;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char mpc_input_peekc(mpc_input_t *i) {
|
static char mpc_input_peekc(mpc_input_t *i) {
|
||||||
|
|
||||||
char c;
|
char c = '\0';
|
||||||
|
|
||||||
switch (i->type) {
|
switch (i->type) {
|
||||||
case MPC_INPUT_STRING: return i->string[i->state.pos];
|
case MPC_INPUT_STRING: return i->string[i->state.pos];
|
||||||
case MPC_INPUT_FILE:
|
case MPC_INPUT_FILE:
|
||||||
|
|
||||||
|
c = fgetc(i->file);
|
||||||
if (feof(i->file)) { return '\0'; }
|
if (feof(i->file)) { return '\0'; }
|
||||||
|
|
||||||
c = fgetc(i->file);
|
|
||||||
fseek(i->file, -1, SEEK_CUR);
|
fseek(i->file, -1, SEEK_CUR);
|
||||||
break;
|
return c;
|
||||||
|
|
||||||
case MPC_INPUT_PIPE:
|
case MPC_INPUT_PIPE:
|
||||||
|
|
||||||
if (feof(i->file)) { return '\0'; }
|
if (!i->buffer) {
|
||||||
|
c = getc(i->file);
|
||||||
if (!i->buffer) { c = getc(i->file); ungetc(c, i->file); break; }
|
if (feof(i->file)) { return '\0'; }
|
||||||
|
ungetc(c, i->file);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
if (i->buffer && mpc_input_buffer_in_range(i)) {
|
if (i->buffer && mpc_input_buffer_in_range(i)) {
|
||||||
return mpc_input_buffer_get(i);
|
return mpc_input_buffer_get(i);
|
||||||
} else {
|
} else {
|
||||||
c = getc(i->file); ungetc(c, i->file);
|
c = getc(i->file);
|
||||||
break;
|
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) {
|
static int mpc_input_failure(mpc_input_t *i, char c) {
|
||||||
@@ -2016,8 +2020,7 @@ mpc_parser_t *mpc_re(const char *re) {
|
|||||||
Base = mpc_new("base");
|
Base = mpc_new("base");
|
||||||
Range = mpc_new("range");
|
Range = mpc_new("range");
|
||||||
|
|
||||||
mpc_define(Regex, mpc_and(2,
|
mpc_define(Regex, mpc_and(2, mpcf_re_or,
|
||||||
mpcf_re_or,
|
|
||||||
Term,
|
Term,
|
||||||
mpc_maybe(mpc_and(2, mpcf_snd_free, mpc_char('|'), Regex, free)),
|
mpc_maybe(mpc_and(2, mpcf_snd_free, mpc_char('|'), Regex, free)),
|
||||||
(mpc_dtor_t)mpc_delete
|
(mpc_dtor_t)mpc_delete
|
||||||
@@ -2025,8 +2028,7 @@ mpc_parser_t *mpc_re(const char *re) {
|
|||||||
|
|
||||||
mpc_define(Term, mpc_many(mpcf_re_and, Factor));
|
mpc_define(Term, mpc_many(mpcf_re_and, Factor));
|
||||||
|
|
||||||
mpc_define(Factor, mpc_and(2,
|
mpc_define(Factor, mpc_and(2, mpcf_re_repeat,
|
||||||
mpcf_re_repeat,
|
|
||||||
Base,
|
Base,
|
||||||
mpc_or(5,
|
mpc_or(5,
|
||||||
mpc_char('*'), mpc_char('+'), mpc_char('?'),
|
mpc_char('*'), mpc_char('+'), mpc_char('?'),
|
||||||
@@ -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"));
|
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) {
|
static int is_number(const char* s) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < strlen(s); i++) { if (!strchr("0123456789", s[i])) { return 0; } }
|
for (i = 0; i < strlen(s); i++) { if (!strchr("0123456789", s[i])) { return 0; } }
|
||||||
@@ -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_define(Stmt, mpc_and(5, mpca_stmt_afold,
|
||||||
mpc_tok(mpc_ident()), mpc_maybe(mpc_tok(mpc_string_lit())), mpc_sym(":"), Grammar, mpc_sym(";"),
|
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,
|
mpc_define(Grammar, mpc_and(2, mpcaf_grammar_or,
|
||||||
|
Reference in New Issue
Block a user