]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix pcase rx form snag with '?' and '??' (bug#44532)
authorMattias EngdegÄrd <mattiase@acm.org>
Mon, 9 Nov 2020 16:11:05 +0000 (17:11 +0100)
committerEli Zaretskii <eliz@gnu.org>
Mon, 9 Nov 2020 16:59:24 +0000 (18:59 +0200)
This is a regression from Emacs 26.
Reported by Phillip Stephani.

* lisp/emacs-lisp/rx.el (rx--pcase-transform): Process ? and ?? correctly.
* test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add test case.

(cherry picked from commit 575b0681d926463960fc00d1e33decaa71d5c956)

lisp/emacs-lisp/rx.el
test/lisp/emacs-lisp/rx-tests.el

index 6564563e7ec1b5fff71b7d35dceea7b6e1f4c05a..88c843f3ce6ffa3ceed6e7ff02162893b9a4dee7 100644 (file)
@@ -1413,7 +1413,7 @@ into a plain rx-expression, collecting names into `rx--pcase-vars'."
                 (mapconcat #'symbol-name rx--pcase-vars " ")))
        `(backref ,index)))
     ((and `(,head . ,rest)
-          (guard (and (symbolp head)
+          (guard (and (or (symbolp head) (memq head '(?\s ??)))
                       (not (memq head '(literal regexp regex eval))))))
      (cons head (mapcar #'rx--pcase-transform rest)))
     (_ rx)))
index 0fece4004bd98c137b1186a2eebf1323ab9cc80b..05779b4e0a65f5257b7ee662e6e6aaa61210a217 100644 (file)
   (let ((k "blue"))
     (should (equal (pcase "<blue>"
                      ((rx "<" (literal k) ">") 'ok))
-                   'ok))))
+                   'ok)))
+  (should (equal (pcase "abc"
+                   ((rx (? (let x alpha)) (?? (let y alnum)) ?c)
+                    (list x y)))
+                 '("a" "b"))))
 
 (ert-deftest rx-kleene ()
   "Test greedy and non-greedy repetition operators."