/* reject repetitions after empty expression in BRE */
if (!ere)
return REG_BADRPT;
+ case '|':
+ /* extension: treat \| as alternation in BRE */
+ if (!ere) {
+ node = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1);
+ s--;
+ goto end;
+ }
+ /* fallthrough */
default:
if (!ere && (unsigned)*s-'1' < 9) {
/* back reference */
s += len;
break;
}
+end:
if (!node)
return REG_ESPACE;
ctx->n = node;
if ((ere && *s == '|') ||
(ere && *s == ')' && depth) ||
(!ere && *s == '\\' && s[1] == ')') ||
+ /* extension: treat \| as alternation in BRE */
+ (!ere && *s == '\\' && s[1] == '|') ||
!*s) {
/* extension: empty branch is unspecified (), (|a), (a|)
here they are not rejected but match on empty string */
int c = *s;
nunion = tre_ast_new_union(ctx->mem, nunion, nbranch);
nbranch = 0;
- if (c != '|') {
+
+ if (c == '\\' && s[1] == '|') {
+ s+=2;
+ } else if (c == '|') {
+ s++;
+ } else {
if (c == '\\') {
if (!depth) return REG_EPAREN;
s+=2;
nunion = tre_stack_pop_voidptr(stack);
goto parse_iter;
}
- s++;
}
}
}