GNU bug report logs - #30568
27.0.50; `rx' doesn't create optimal regex for (group (or ...))

Previous Next

Package: emacs;

Reported by: p.stephani2 <at> gmail.com

Date: Wed, 21 Feb 2018 14:33:01 UTC

Severity: wishlist

Found in version 27.0.50

Full log


View this message in rfc822 format

From: Mattias EngdegÄrd <mattiase <at> acm.org>
To: 30568 <at> debbugs.gnu.org
Cc: Philipp <p.stephani2 <at> gmail.com>
Subject: bug#30568: 27.0.50; `rx' doesn't create optimal regex for (group (or ...))
Date: Fri, 13 Dec 2019 20:18:58 +0100
> (rx (group (or "aaa" "bbb")))
> ==> \(\(?:aaa\|bbb\)\)
>
> This should generate \(aaa\|bbb\) instead.  Of course, these regexes are
> equivalent, but the second one is easier to read (and maybe faster).

This remains unchanged, I'm afraid, despite rx being completely rewritten. Not that it matters much: brackets do not generate any regexp bytecode, thus matching performance isn't affected once the regexp has been compiled. When the brackets are required, there is no waste:

(rx (+ (or "aaa" "bbb"))) 
=> "\\(?:aaa\\|bbb\\)+"

Still, it's a bit untidy, and I like that you reported it. We could add a special value for the PAREN argument to regexp-opt to prevent bracketing altogether, I suppose. It isn't immediately on my to-do list, however.





This bug report was last modified 5 years and 185 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.