diff options
| author | Mattias EngdegÄrd | 2019-02-24 22:12:52 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-03-02 15:35:28 +0100 |
| commit | da758046da74e33273265cd2e72a8aa1a0c9c7e3 (patch) | |
| tree | 4337523f0b56c12d69f27a91ee0a1b61376c0e7e /doc | |
| parent | dbffbe08815644fd30404891ef81496277ed27da (diff) | |
| download | emacs-da758046da74e33273265cd2e72a8aa1a0c9c7e3.tar.gz emacs-da758046da74e33273265cd2e72a8aa1a0c9c7e3.zip | |
rx: fix `or' ordering by adding argument to regexp-opt
The rx `or' form may reorder its arguments in an unpredictable way,
contrary to user expectation, since it sometimes uses `regexp-opt'.
Add a NOREORDER option to `regexp-opt' for preventing it from
producing a reordered regexp (Bug#34641).
* doc/lispref/searching.texi (Regular Expression Functions):
* etc/NEWS (Lisp Changes in Emacs 27.1):
Describe the new regexp-opt NOREORDER argument.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt): Add NOREORDER.
Make no attempt at regexp improvement if the set of strings contains
a prefix of another string.
(regexp-opt--contains-prefix): New.
* lisp/emacs-lisp/rx.el (rx-or): Call regexp-opt with NOREORDER.
* test/lisp/emacs-lisp/rx-tests.el: Test rx `or' form match order.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/searching.texi | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index cfbd2449b13..fb7f48474d5 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi | |||
| @@ -950,7 +950,7 @@ whitespace: | |||
| 950 | @end defun | 950 | @end defun |
| 951 | 951 | ||
| 952 | @cindex optimize regexp | 952 | @cindex optimize regexp |
| 953 | @defun regexp-opt strings &optional paren | 953 | @defun regexp-opt strings &optional paren noreorder |
| 954 | This function returns an efficient regular expression that will match | 954 | This function returns an efficient regular expression that will match |
| 955 | any of the strings in the list @var{strings}. This is useful when you | 955 | any of the strings in the list @var{strings}. This is useful when you |
| 956 | need to make matching or searching as fast as possible---for example, | 956 | need to make matching or searching as fast as possible---for example, |
| @@ -985,8 +985,15 @@ if it is necessary to ensure that a postfix operator appended to | |||
| 985 | it will apply to the whole expression. | 985 | it will apply to the whole expression. |
| 986 | @end table | 986 | @end table |
| 987 | 987 | ||
| 988 | The resulting regexp of @code{regexp-opt} is equivalent to but usually | 988 | The optional argument @var{noreorder}, if @code{nil} or omitted, |
| 989 | more efficient than that of a simplified version: | 989 | allows the returned regexp to match the strings in any order. If |
| 990 | non-@code{nil}, the match is guaranteed to be performed in the order | ||
| 991 | given, as if the strings were made into a regexp by joining them with | ||
| 992 | the @samp{\|} operator. | ||
| 993 | |||
| 994 | Up to reordering, the resulting regexp of @code{regexp-opt} is | ||
| 995 | equivalent to but usually more efficient than that of a simplified | ||
| 996 | version: | ||
| 990 | 997 | ||
| 991 | @example | 998 | @example |
| 992 | (defun simplified-regexp-opt (strings &optional paren) | 999 | (defun simplified-regexp-opt (strings &optional paren) |