bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#30568: 27.0.50; `rx' doesn't create optimal regex for (group (or ...


From: Mattias Engdegård
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.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]