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.
This commit is contained in:
parent
4893a15631
commit
87475f4af2
2 changed files with 13 additions and 7 deletions
|
@ -1152,7 +1152,12 @@ For extending the `rx' notation in FORM, use `rx-define' or `rx-let-eval'."
|
||||||
|
|
||||||
(defun rx--to-expr (form)
|
(defun rx--to-expr (form)
|
||||||
"Translate the rx-expression FORM to a Lisp expression yielding a regexp."
|
"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)))
|
(elems (car (rx--translate form)))
|
||||||
(args nil))
|
(args nil))
|
||||||
;; Merge adjacent strings.
|
;; Merge adjacent strings.
|
||||||
|
@ -1282,12 +1287,7 @@ Additional constructs can be defined using `rx-define' and `rx-let',
|
||||||
which see.
|
which see.
|
||||||
|
|
||||||
\(fn REGEXPS...)"
|
\(fn REGEXPS...)"
|
||||||
;; Retrieve local definitions from the macroexpansion environment.
|
(rx--to-expr (cons 'seq regexps)))
|
||||||
;; (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))))
|
|
||||||
|
|
||||||
(defun rx--make-binding (name tail)
|
(defun rx--make-binding (name tail)
|
||||||
"Make a definitions entry out of TAIL.
|
"Make a definitions entry out of TAIL.
|
||||||
|
|
|
@ -207,6 +207,12 @@
|
||||||
(list 'ok z))
|
(list 'ok z))
|
||||||
'(ok "F"))))
|
'(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 ()
|
(ert-deftest rx-kleene ()
|
||||||
"Test greedy and non-greedy repetition operators."
|
"Test greedy and non-greedy repetition operators."
|
||||||
(should (equal (rx (* "a") (+ "b") (\? "c") (?\s "d")
|
(should (equal (rx (* "a") (+ "b") (\? "c") (?\s "d")
|
||||||
|
|
Loading…
Add table
Reference in a new issue