aboutsummaryrefslogtreecommitdiff
path: root/compiler.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-16 22:36:38 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-16 22:36:38 -0700
commit82952fa5e955885baa1632b0b0ba2ab040a30f14 (patch)
treeaa02b3dbac36e7a6fb3050f9ae55dbc7e8a637da /compiler.c
parent9ee7102f51c60469659de752f119b1ecbd3c0ba7 (diff)
Removed the requirement for semicolons, changed '=' -> ':' for
definitions, added better error reporting for failed BPEG grammars
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler.c b/compiler.c
index f5bcd90..c3c6fba 100644
--- a/compiler.c
+++ b/compiler.c
@@ -86,9 +86,8 @@ static vm_op_t *chain_together(vm_op_t *first, vm_op_t *second)
*/
vm_op_t *bpeg_simplepattern(file_t *f, const char *str)
{
- if (!*str) return NULL;
str = after_spaces(str);
- check(*str, "Expected a pattern");
+ if (!*str) return NULL;
vm_op_t *op = calloc(sizeof(vm_op_t), 1);
op->start = str;
op->len = -1;
@@ -320,6 +319,11 @@ vm_op_t *bpeg_simplepattern(file_t *f, const char *str)
} else {
op->args.s = strndup(&c, 1);
}
+ if (*after_spaces(str) == ':') {
+ free((char*)op->args.s);
+ free(op);
+ return NULL;
+ }
op->op = VM_REF;
break;
}
@@ -333,6 +337,10 @@ vm_op_t *bpeg_simplepattern(file_t *f, const char *str)
--str;
const char *refname = str;
str = after_name(str);
+ if (*after_spaces(str) == ':') {
+ free(op);
+ return NULL;
+ }
op->op = VM_REF;
op->args.s = strndup(refname, (size_t)(str - refname));
break;