diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2019-12-03 15:17:37 +0100 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2019-12-03 15:17:37 +0100 |
commit | a6b598518c4bf6dfc587cfb2b61fa5fb04b99494 (patch) | |
tree | 53a5dd14398ff04282ff98f7e97f4560b3f84b58 | |
parent | a05bafffdcb88df74408a8402cafc9829407c1e5 (diff) | |
download | emacs-a6b598518c4bf6dfc587cfb2b61fa5fb04b99494.tar.gz |
Avoid duplicated character classes in rx
For example, (any digit digit) should produce "[[:digit:]]",
not "[[:digit:][:digit:]]".
* lisp/emacs-lisp/rx.el (rx--translate-any): Deduplicate character classes.
* test/lisp/emacs-lisp/rx-tests.el (rx-any): Add test case.
-rw-r--r-- | lisp/emacs-lisp/rx.el | 4 | ||||
-rw-r--r-- | test/lisp/emacs-lisp/rx-tests.el | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 52a35ffa2a7..6fde27831a0 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el @@ -376,7 +376,9 @@ If NEGATED, negate the sense." (push (cons arg arg) conses)) ((and (symbolp arg) (let ((class (cdr (assq arg rx--char-classes)))) - (and class (push class classes))))) + (and class + (or (memq class classes) + (push class classes)))))) (t (error "Invalid rx `any' argument: %s" arg)))) (let ((items ;; Translate strings and conses into nonoverlapping intervals, diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index 4ecc805aead..26e39f8c8ed 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el @@ -128,7 +128,9 @@ (should (equal (rx (any) (not (any))) "\\`a\\`[^z-a]")) (should (equal (rx (any "") (not (any ""))) - "\\`a\\`[^z-a]"))) + "\\`a\\`[^z-a]")) + (should (equal (rx (any space ?a digit space)) + "[a[:space:][:digit:]]"))) (ert-deftest rx-pcase () (should (equal (pcase "a 1 2 3 1 1 b" |