summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-05-27 15:51:50 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-05-27 17:01:51 -0400
commitdfe7ff3c3fbc2f9ed66171358fafa9abb9f2b23d (patch)
tree0358a78bbe1a3988c57ffc0fe598308a982bb613
parent136b604027389fd013c029f1d1ef33ac599bc922 (diff)
downloadbfs-dfe7ff3c3fbc2f9ed66171358fafa9abb9f2b23d.tar.xz
xregex: Support non-capturing groups with -regextype emacs
Link: https://savannah.gnu.org/bugs/index.php?65770 Link: https://github.com/kkos/oniguruma/issues/296
-rw-r--r--src/xregex.c8
-rw-r--r--tests/gnu/regextype_emacs.sh2
2 files changed, 8 insertions, 2 deletions
diff --git a/src/xregex.c b/src/xregex.c
index 484f099..414c366 100644
--- a/src/xregex.c
+++ b/src/xregex.c
@@ -37,6 +37,8 @@ struct bfs_regex {
static int bfs_onig_status;
static OnigEncoding bfs_onig_enc;
+static OnigSyntaxType bfs_onig_syntax_emacs;
+
/** pthread_once() callback. */
static void bfs_onig_once(void) {
// Fall back to ASCII by default
@@ -103,6 +105,10 @@ static void bfs_onig_once(void) {
if (bfs_onig_status != ONIG_NORMAL) {
bfs_onig_enc = NULL;
}
+
+ // https://github.com/kkos/oniguruma/issues/296
+ onig_copy_syntax(&bfs_onig_syntax_emacs, ONIG_SYNTAX_EMACS);
+ bfs_onig_syntax_emacs.op2 |= ONIG_SYN_OP2_QMARK_GROUP_EFFECT;
}
/** Initialize Oniguruma. */
@@ -144,7 +150,7 @@ int bfs_regcomp(struct bfs_regex **preg, const char *pattern, enum bfs_regex_typ
syntax = ONIG_SYNTAX_POSIX_EXTENDED;
break;
case BFS_REGEX_EMACS:
- syntax = ONIG_SYNTAX_EMACS;
+ syntax = &bfs_onig_syntax_emacs;
break;
case BFS_REGEX_GREP:
syntax = ONIG_SYNTAX_GREP;
diff --git a/tests/gnu/regextype_emacs.sh b/tests/gnu/regextype_emacs.sh
index 3cc388c..164d17a 100644
--- a/tests/gnu/regextype_emacs.sh
+++ b/tests/gnu/regextype_emacs.sh
@@ -1,3 +1,3 @@
invoke_bfs -regextype emacs -quit || skip
-bfs_diff basic -regextype emacs -regex '.*/\(f+o?o?\|bar\)'
+bfs_diff basic -regextype emacs -regex '.*/\(?:f+o?o?\|bar\)'