Fix last commit
It fixed the crashes, but it broke the test suite. This commit makes
sure that the crashes stay fixed, but it also fixes the test suite.
diff --git a/include/bc.h b/include/bc.h
index 311cc78..d7fff12 100644
--- a/include/bc.h
+++ b/include/bc.h
@@ -101,6 +101,9 @@
#define BC_PARSE_DELIMITER(t) \
((t) == BC_LEX_SCOLON || (t) == BC_LEX_NLINE || (t) == BC_LEX_EOF)
+#define BC_PARSE_BLOCK_STMT(f) \
+ ((f) & (BC_PARSE_FLAG_ELSE | BC_PARSE_FLAG_LOOP_INNER))
+
#define BC_PARSE_OP(p, l) (((p) & ~(BC_LEX_CHAR_MSB(1))) | (BC_LEX_CHAR_MSB(l)))
#define BC_PARSE_OP_LEFT(op) ((op) & BC_LEX_CHAR_MSB(1))
diff --git a/src/bc/parse.c b/src/bc/parse.c
index 9e13ab7..5829048 100644
--- a/src/bc/parse.c
+++ b/src/bc/parse.c
@@ -56,10 +56,11 @@
size_t i;
uint16_t *fptr = NULL, flags = BC_PARSE_FLAG_ELSE;
- for (i = 0; i < p->flags.len && (flags & BC_PARSE_FLAG_ELSE); ++i) {
+ for (i = 0; i < p->flags.len && BC_PARSE_BLOCK_STMT(flags); ++i) {
fptr = bc_vec_item_rev(&p->flags, i);
flags = *fptr;
- if (flags & BC_PARSE_FLAG_BRACE) return false;
+ if ((flags & BC_PARSE_FLAG_BRACE) && p->l.last != BC_LEX_RBRACE)
+ return false;
}
good = ((flags & BC_PARSE_FLAG_IF) != 0 && !(flags & BC_PARSE_FLAG_BRACE));
@@ -515,6 +516,8 @@
if (p->l.t == BC_LEX_RBRACE) {
s = bc_lex_next(&p->l);
if (s) return s;
+ if (!bc_parse_isDelimiter(p))
+ return bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
}
else return bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
}
@@ -580,9 +583,6 @@
} while (p->flags.len > 1 && !new_else && !BC_PARSE_IF_END(p) &&
!(has_brace = (BC_PARSE_BRACE(p) != 0)));
- if (brace && !s && !BC_PARSE_DELIMITER(p->l.t))
- s = bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
-
return s;
}