Subject: 28.2; re-builder rx fails to match

From: Carl Allendorph <[email-masked]>
Date: Mon, 5 Jun 2023 09:20:18 -0700

I'm having trouble using the `re-builder` tool in emacs. I find
that if I use `rx` mode - the built regexp does not behave as
expected. I'm not an elisp expert - so it is very possible I'm
doing something wrong.

Steps:

1.  Create a buffer and put "ad ac" on line 1.
2.  Run `M-x re-builder`
3.  Press `C-c TAB` and enter `rx` to enter rx mode.
4.  Enter the following: `(rx (and (or "a" "b") "c"))`
5.  No Matches are discovered - I expect `ac` to match
6.  Switch to back to `string` mode with `C-c TAB` and enter `string`
7.  The shown regex string is `"\(?:\[ab]c\)"`

I think the problem is the `\[` character escape is invalid. In string
mode, if I remove the `\` character and make the regex string "\(?:[ab]c\)"
- then it
matches on `ac` like I expect.

I believe the problem is in `reb-cook-regexp` - specifically in
the call to `rx-to-string`:

(rx-to-string (rx (and (or "a" "b") "c")))
"\\(?:\\[ab]c\\)"

I've checked this in Emacs 26.3 on an Ubuntu 20.04 machine as well and get
the same behavior.

Can anyone confirm this behavior ?

In GNU Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00
Version 12.0.1 (Build 21A559))
 of 2023-02-22 built on armbob.lan
Windowing system distributor 'Apple', version 10.3.2113
System Description:  macOS 12.4

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules --with-x-toolkit=no'

Configured features:
ACL GMP GNUTLS JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER THREADS
TOOLKIT_SCROLL_BARS ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Text

Minor modes in effect:
  delete-selection-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils misearch multi-isearch
help-fns radix-tree cl-print debug backtrace help-mode find-func delsel
re-builder rx time-date package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
mailcap url-handlers url-parse auth-source cl-seq eieio eieio-core
cl-macs eieio-loaddefs password-cache json subr-x map url-vars seq
byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib iso-transl
tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize
mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 71017 6463)
 (symbols 48 8112 1)
 (strings 32 24554 990)
 (string-bytes 1 780996)
 (vectors 16 16939)
 (vector-slots 8 223944 10903)
 (floats 8 36 168)
 (intervals 56 652 133)
 (buffers 992 18))