all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: 59814@debbugs.gnu.org
Cc: Daniel Pittman <daniel@rimspace.net>
Subject: bug#59814: 28.2; `rx-let` bindings are not visible to `pcase` `rx` forms
Date: Sun, 4 Dec 2022 15:37:06 +0100	[thread overview]
Message-ID: <6CD6FD14-87A2-4221-87E8-5BF879C99C2C@acm.org> (raw)
In-Reply-To: <CABNGp=SbdnSc0f3b2fN9hrpE8h7KFLN+WqNO8my0q0nLvhf+Nw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 41 bytes --]

That's terrible. Would this patch help?


[-- Attachment #2: 0001-Fix-pcase-rx-patterns-using-rx-let-bindings-bug-5981.patch --]
[-- Type: application/octet-stream, Size: 2627 bytes --]

From 30894f0ed19572b6b55dfb791a8fd8a84bfd660a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 4 Dec 2022 15:20:49 +0100
Subject: [PATCH] Fix pcase rx patterns using rx-let bindings (bug#59814)

Reported by Daniel Pittman.

* lisp/emacs-lisp/rx.el (rx): Move binding of rx--local-definitions...
(rx--to-expr): ...here.
* test/lisp/emacs-lisp/rx-tests.el (rx-let-pcase): New test.
---
 lisp/emacs-lisp/rx.el            | 14 +++++++-------
 test/lisp/emacs-lisp/rx-tests.el |  6 ++++++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index ec51146484..f2a0dc5483 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -1152,7 +1152,12 @@ rx-to-string
 
 (defun rx--to-expr (form)
   "Translate the rx-expression FORM to a Lisp expression yielding a regexp."
-  (let* ((rx--delayed-evaluation t)
+  (let* ((rx--local-definitions
+          ;; Retrieve local definitions from the macroexpansion environment.
+          ;; (It's unclear whether the previous value of `rx--local-definitions'
+          ;; should be included, and if so, in which order.)
+          (cdr (assq :rx-locals macroexpand-all-environment)))
+         (rx--delayed-evaluation t)
          (elems (car (rx--translate form)))
          (args nil))
     ;; Merge adjacent strings.
@@ -1282,12 +1287,7 @@ rx
 which see.
 
 \(fn REGEXPS...)"
-  ;; Retrieve local definitions from the macroexpansion environment.
-  ;; (It's unclear whether the previous value of `rx--local-definitions'
-  ;; should be included, and if so, in which order.)
-  (let ((rx--local-definitions
-         (cdr (assq :rx-locals macroexpand-all-environment))))
-    (rx--to-expr (cons 'seq regexps))))
+  (rx--to-expr (cons 'seq regexps)))
 
 (defun rx--make-binding (name tail)
   "Make a definitions entry out of TAIL.
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 125ddee859..01772e54d8 100644
--- a/test/lisp/emacs-lisp/rx-tests.el
+++ b/test/lisp/emacs-lisp/rx-tests.el
@@ -207,6 +207,12 @@ rx-pcase
                    (list 'ok z))
                  '(ok "F"))))
 
+(ert-deftest rx-let-pcase ()
+  "Test `rx-let' around `pcase' with `rx' patterns (bug#59814)."
+  (should (equal (rx-let ((tata "ab"))
+                   (pcase "abc" ((rx tata) 'toto)))
+                 'toto)))
+
 (ert-deftest rx-kleene ()
   "Test greedy and non-greedy repetition operators."
   (should (equal (rx (* "a") (+ "b") (\? "c") (?\s "d")
-- 
2.32.0 (Apple Git-132)


  reply	other threads:[~2022-12-04 14:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-04 11:03 bug#59814: 28.2; `rx-let` bindings are not visible to `pcase` `rx` forms Daniel Pittman
2022-12-04 14:37 ` Mattias Engdegård [this message]
2022-12-11 16:14 ` bug#59814: 28.2; `rx-let` bindings are not visible to `pcase` `rx` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6CD6FD14-87A2-4221-87E8-5BF879C99C2C@acm.org \
    --to=mattiase@acm.org \
    --cc=59814@debbugs.gnu.org \
    --cc=daniel@rimspace.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.