aboutsummaryrefslogtreecommitdiff
path: root/compiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/compiler.c b/compiler.c
index 60da7d8..49c4996 100644
--- a/compiler.c
+++ b/compiler.c
@@ -252,16 +252,24 @@ vm_op_t *bpeg_simplepattern(file_t *f, const char *str)
check(matchchar(&str, ')'), "Expected closing ')' instead of \"%s\"", str);
break;
}
+ // Square brackets
+ case '[': {
+ vm_op_t *pat = bpeg_simplepattern(f, str);
+ check(pat, "Expected pattern inside square brackets");
+ pat = expand_choices(f, pat);
+ str = pat->end;
+ str = after_spaces(str);
+ check(matchchar(&str, ']'), "Expected closing ']' instead of \"%s\"", str);
+ set_range(op, 0, 1, pat, NULL);
+ break;
+ }
// Capture
case '@': {
op->op = VM_CAPTURE;
- str = after_spaces(str);
- if (matchchar(&str, '[')) {
- char *closing = strchr(str, ']');
- check(closing, "Expected closing ']'");
- op->args.capture.name = strndup(str, (size_t)(closing-str));
- str = closing;
- check(matchchar(&str, ']'), "Expected closing ']'");
+ const char *a = *str == '!' ? &str[1] : after_name(str);
+ if (a > str && *after_spaces(a) == '=') {
+ op->args.capture.name = strndup(str, (size_t)(a-str));
+ str = a + 1;
}
vm_op_t *pat = bpeg_simplepattern(f, str);
check(pat, "Expected pattern after @");