From: "Johan Bockgård" <bojohan@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: Question on pcase
Date: Wed, 28 Oct 2015 00:50:44 +0100 [thread overview]
Message-ID: <87r3kfg9bf.fsf@gnu.org> (raw)
In-Reply-To: <87si5165ze.fsf@web.de> (Michael Heerdegen's message of "Fri, 23 Oct 2015 15:59:17 +0200")
Michael Heerdegen <michael_heerdegen@web.de> writes:
> The only thing that makes sense to me would be to make `edebug' let you
> step into a pattern. AFAICT that would be a very hard work.
Edebug already understands most of pcase's patterns, but it doesn't step
"into" the SYMBOL bindings.
Try this:
pcase.el: Support edebug stepping of SYMBOL patterns
* lisp/emacs-lisp/pcase.el (pcase-SYMBOL) New edebug spec.
(pcase-PAT): Use it.
(pcase--edebug-match-symbol): New function.
(pcase-QPAT): Improve handling of cons patterns.
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index 8bcb447..3ea519c 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -70,31 +70,20 @@ (defconst pcase--dontcare-upats '(t _ pcase--dontcare))
(defvar pcase--dontwarn-upats '(pcase--dontcare))
-(def-edebug-spec
- pcase-PAT
- (&or symbolp
- ("or" &rest pcase-PAT)
- ("and" &rest pcase-PAT)
- ("guard" form)
- ("let" pcase-PAT form)
- ("pred" pcase-FUN)
- ("app" pcase-FUN pcase-PAT)
- pcase-MACRO
- sexp))
-
-(def-edebug-spec
- pcase-FUN
- (&or lambda-expr
- ;; Punt on macros/special forms.
- (functionp &rest form)
- sexp))
-
-(def-edebug-spec pcase-MACRO pcase--edebug-match-macro)
-
;; Only called from edebug.
(declare-function get-edebug-spec "edebug" (symbol))
(declare-function edebug-match "edebug" (cursor specs))
+(declare-function edebug-no-match "edebug" (cursor &rest args))
+(declare-function edebug-top-element-required "edebug" (cursor &rest error))
+(def-edebug-spec pcase-SYMBOL pcase--edebug-match-symbol)
+(defun pcase--edebug-match-symbol (cursor)
+ (let ((sexp (edebug-top-element-required cursor "Expected" '(symbolp))))
+ (if (or (not (symbolp sexp)) (keywordp sexp))
+ (edebug-no-match cursor "Expected" '(symbolp))
+ (list `(and ,sexp (let _ ,(car (edebug-match cursor '(form)))))))))
+
+(def-edebug-spec pcase-MACRO pcase--edebug-match-macro)
(defun pcase--edebug-match-macro (cursor)
(let (specs)
(mapatoms
@@ -105,6 +94,26 @@ (defun pcase--edebug-match-macro (cursor)
specs)))))
(edebug-match cursor (cons '&or specs))))
+(def-edebug-spec
+ pcase-FUN
+ (&or lambda-expr
+ ;; Punt on macros/special forms.
+ (functionp &rest form)
+ sexp))
+
+(def-edebug-spec
+ pcase-PAT
+ (&or "_"
+ pcase-SYMBOL
+ ("or" &rest pcase-PAT)
+ ("and" &rest pcase-PAT)
+ ("guard" form)
+ ("let" pcase-PAT form)
+ ("pred" pcase-FUN)
+ ("app" pcase-FUN pcase-PAT)
+ pcase-MACRO
+ sexp))
+
;;;###autoload
(defmacro pcase (exp &rest cases)
"Perform ML-style pattern matching on EXP.
@@ -865,8 +874,10 @@ (defun pcase--u1 (matches code vars rest)
(def-edebug-spec
pcase-QPAT
+ ;; Cf. edebug spec for `backquote-form' in edebug.el.
(&or ("," pcase-PAT)
- (pcase-QPAT . pcase-QPAT)
+ (pcase-QPAT [&rest [¬ ","] pcase-QPAT]
+ . [&or nil pcase-QPAT])
(vector &rest pcase-QPAT)
sexp))
next prev parent reply other threads:[~2015-10-27 23:50 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 14:46 Question on pcase Oleh Krehel
2015-10-22 21:19 ` Michael Heerdegen
2015-10-23 6:30 ` Eli Zaretskii
2015-10-23 11:58 ` Oleh Krehel
2015-10-23 12:23 ` Michael Heerdegen
2015-10-23 12:42 ` Oleh Krehel
2015-10-23 13:07 ` Michael Heerdegen
2015-10-23 13:26 ` Oleh Krehel
2015-10-23 13:59 ` Michael Heerdegen
2015-10-27 23:50 ` Johan Bockgård [this message]
2015-10-30 1:33 ` Michael Heerdegen
2015-10-23 14:23 ` Michael Heerdegen
2015-10-23 12:17 ` Michael Heerdegen
2015-10-23 12:22 ` Oleh Krehel
2015-10-23 13:26 ` Eli Zaretskii
2015-10-23 14:14 ` Michael Heerdegen
2015-10-23 14:41 ` Eli Zaretskii
2015-10-23 18:38 ` Michael Heerdegen
2015-10-23 18:43 ` Eli Zaretskii
2015-10-23 19:59 ` Przemysław Wojnowski
2015-10-23 21:01 ` Michael Heerdegen
2015-10-23 20:23 ` Przemysław Wojnowski
2015-10-23 20:39 ` Michael Heerdegen
2015-10-24 11:37 ` Przemysław Wojnowski
2015-10-24 9:01 ` Alan Mackenzie
2015-10-24 12:58 ` Stephen Berman
2015-10-24 17:47 ` Alan Mackenzie
2015-10-24 19:10 ` Stephen Berman
2015-10-24 19:28 ` Alan Mackenzie
2015-10-25 0:00 ` pcase docstring tweaks (was: Question on pcase) Michael Heerdegen
2015-10-27 14:54 ` pcase docstring tweaks Michael Heerdegen
2015-10-27 18:57 ` Stefan Monnier
2015-10-27 20:14 ` Michael Heerdegen
2015-10-28 3:15 ` Richard Stallman
2015-10-28 17:08 ` Michael Heerdegen
2015-10-24 17:00 ` Question on pcase Drew Adams
2015-10-24 17:22 ` Alan Mackenzie
2015-10-24 17:36 ` Drew Adams
2015-10-24 20:03 ` Johan Bockgård
2015-10-24 23:11 ` Michael Heerdegen
2015-10-26 15:55 ` Oleh Krehel
2015-10-26 16:07 ` Michael Heerdegen
2015-10-27 8:42 ` Oleh Krehel
2015-10-26 16:20 ` Michael Heerdegen
2015-10-27 8:42 ` Oleh Krehel
2015-10-27 14:27 ` Michael Heerdegen
2015-10-27 14:47 ` Michael Heerdegen
2015-10-28 18:05 ` Michael Heerdegen
2015-10-29 9:44 ` Oleh Krehel
2015-10-30 1:11 ` Michael Heerdegen
2015-10-26 16:35 ` Andreas Schwab
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=87r3kfg9bf.fsf@gnu.org \
--to=bojohan@gnu.org \
--cc=emacs-devel@gnu.org \
/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.